def to_dict(self): status_info = AgentStatus.to_dict(self) # Hostnames status_info['hostnames'] = {} # Checks.d Status status_info['checks'] = {} check_statuses = self.check_statuses + get_jmx_status() for cs in check_statuses: status_info['checks'][cs.name] = {'instances': {}} if cs.init_failed_error: status_info['checks'][cs.name]['init_failed'] = True status_info['checks'][ cs.name]['traceback'] = cs.init_failed_traceback else: status_info['checks'][cs.name] = {'instances': {}} status_info['checks'][cs.name]['init_failed'] = False for s in cs.instance_statuses: status_info['checks'][cs.name]['instances'][ s.instance_id] = { 'status': s.status, 'has_error': s.has_error(), 'has_warnings': s.has_warnings(), } if s.has_error(): status_info['checks'][cs.name]['instances'][ s.instance_id]['error'] = s.error if s.has_warnings(): status_info['checks'][cs.name]['instances'][ s.instance_id]['warnings'] = s.warnings status_info['checks'][ cs.name]['metric_count'] = cs.metric_count status_info['checks'][cs.name]['event_count'] = cs.event_count # Emitter status status_info['emitter'] = [] for es in self.emitter_statuses: check_status = { 'name': es.name, 'status': es.status, 'has_error': es.has_error() } if es.has_error(): check_status['error'] = es.error status_info['emitter'].append(check_status) paths = util.Paths() try: status_info['confd_path'] = paths.get_confd_path() except config.PathNotFound: status_info['confd_path'] = 'Not found' try: status_info['checksd_path'] = paths.get_checksd_path() except config.PathNotFound: status_info['checksd_path'] = 'Not found' return status_info
def body_lines(self): lines = ['Clocks', '======', ''] try: ntp_offset, ntp_styles = get_ntp_info() lines.append(' ' + style('NTP offset', *ntp_styles) + ': ' + style('%s s' % round(ntp_offset, 4), *ntp_styles)) except Exception as e: lines.append(' NTP offset: Unkwown (%s)' % str(e)) lines.append(' System UTC time: ' + datetime.datetime.utcnow().__str__()) lines.append('') # Paths to checks_d/conf.d lines += ['Paths', '=====', ''] paths = util.Paths() try: confd_path = paths.get_confd_path() except util.PathNotFound: confd_path = 'Not found' try: checksd_path = paths.get_checksd_path() except util.PathNotFound: checksd_path = 'Not found' lines.append(' conf.d: ' + confd_path) lines.append(' checks_d: ' + checksd_path) lines.append('') # Hostnames lines += ['Hostnames', '=========', ''] # Checks.d Status lines += ['Checks', '======', ''] check_statuses = self.check_statuses + get_jmx_status() if not check_statuses: lines.append(" No checks have run yet.") else: for cs in check_statuses: check_lines = [' ' + cs.name, ' ' + '-' * len(cs.name)] if cs.init_failed_error: check_lines.append( " - initialize check class [%s]: %s" % (style( STATUS_ERROR, 'red'), repr(cs.init_failed_error))) if self.verbose and cs.init_failed_traceback: check_lines.extend( ' ' + line for line in cs.init_failed_traceback.split('\n')) else: for s in cs.instance_statuses: c = 'green' if s.has_warnings(): c = 'yellow' if s.has_error(): c = 'red' line = " - instance #%s [%s]" % (s.instance_id, style(s.status, c)) if s.has_error(): line += u": %s" % s.error if s.metric_count is not None: line += " collected %s metrics" % s.metric_count check_lines.append(line) if s.has_warnings(): for warning in s.warnings: warn = warning.split('\n') if not len(warn): continue check_lines.append( u" %s: %s" % (style("Warning", 'yellow'), warn[0])) check_lines.extend(u" %s" % l for l in warn[1:]) if self.verbose and s.traceback is not None: check_lines.extend( ' ' + line for line in s.traceback.split('\n')) check_lines += [ " - Collected %s metrics & %s events" % (cs.metric_count, cs.event_count), ] if cs.library_versions is not None: check_lines += [" - Dependencies:"] for library, version in cs.library_versions.iteritems( ): check_lines += [ " - %s: %s" % (library, version) ] check_lines += [""] lines += check_lines # Emitter status lines += ["", "Emitters", "========", ""] if not self.emitter_statuses: lines.append(" No emitters have run yet.") else: for es in self.emitter_statuses: c = 'green' if es.has_error(): c = 'red' line = " - %s [%s]" % (es.name, style(es.status, c)) if es.status != STATUS_OK: line += ": %s" % es.error lines.append(line) return lines