Example #1
0
    def run(self):

        log.info("Reporting to %s every %ss" % (self.api_host, self.interval))
        log.debug("Watchmonitor enabled: %s" % bool(self.watchmonitor))

        MonitorstatsdStatus().persist()

        while not self.finished.isSet(
        ):  # Use camel case isSet for 2.4 support.
            self.finished.wait(self.interval)
            self.metrics_aggregator.send_packet_count(
                'datamonitor.monitorstatsd.packet.count')
            self.flush()
            if self.watchmonitor:
                self.watchmonitor.reset()

        log.debug("Stopped reporter")
        MonitorstatsdStatus.remove_latest_status()
Example #2
0
    def flush(self):
        try:
            self.flush_count += 1
            self.log_count += 1
            packets_per_second = self.metrics_aggregator.packets_per_second(
                self.interval)
            packet_count = self.metrics_aggregator.total_count

            metrics = self.metrics_aggregator.flush()
            count = len(metrics)
            if self.flush_count % FLUSH_LOGGING_PERIOD == 0:
                self.log_count = 0
            if count:
                self.submit(metrics)

            events = self.metrics_aggregator.flush_events()
            event_count = len(events)
            if event_count:
                self.submit_events(events)

            service_checks = self.metrics_aggregator.flush_service_checks()
            service_check_count = len(service_checks)
            if service_check_count:
                self.submit_service_checks(service_checks)

            should_log = self.flush_count <= FLUSH_LOGGING_INITIAL or self.log_count <= FLUSH_LOGGING_COUNT
            log_func = log.info
            if not should_log:
                log_func = log.debug
            log_func(
                "Flush #%s: flushed %s metric%s, %s event%s, and %s service check run%s"
                % (self.flush_count, count, plural(count), event_count,
                   plural(event_count), service_check_count,
                   plural(service_check_count)))
            if self.flush_count == FLUSH_LOGGING_INITIAL:
                log.info(
                    "First flushes done, %s flushes will be logged every %s flushes."
                    % (FLUSH_LOGGING_COUNT, FLUSH_LOGGING_PERIOD))

            # Persist a status message.
            packet_count = self.metrics_aggregator.total_count
            MonitorstatsdStatus(
                flush_count=self.flush_count,
                packet_count=packet_count,
                packets_per_second=packets_per_second,
                metric_count=count,
                event_count=event_count,
                service_check_count=service_check_count,
            ).persist()

        except Exception:
            if self.finished.isSet():
                log.debug(
                    "Couldn't flush metrics, but that's expected as we're stopping"
                )
            else:
                log.exception("Error flushing metrics")
Example #3
0
 def latest_status(self):
     try:
         loaded_template = template.Loader(".")
         monitorstatsd_status = MonitorstatsdStatus.load_latest_status()
         forwarder_status = ForwarderStatus.load_latest_status()
         collector_status = CollectorStatus.load_latest_status()
         generated_template = loaded_template.load("status.html").generate(
             port=22,
             platform=platform.platform(),
             agent_version=get_version(),
             python_version=platform.python_version(),
             python_architecture=Platform.python_architecture(),
             logger_info=logger_info(),
             monitorstatsd=monitorstatsd_status.to_dict(),
             forwarder=forwarder_status.to_dict(),
             collector=collector_status.to_dict(),
         )
         return generated_template
     except Exception:
         return ("Unable to fetch latest status")
Example #4
0
 def info(self):
     logging.getLogger().setLevel(logging.ERROR)
     return MonitorstatsdStatus.print_latest_status()
Example #5
0
 def _info_all(self):
     CollectorStatus.print_latest_status(verbose=True)
     MonitorstatsdStatus.print_latest_status(verbose=True)
     ForwarderStatus.print_latest_status(verbose=True)