Ejemplo n.º 1
0
    def _get_sdsd6_stats(self, cfg={}):
        port = cfg.get('sdstatsd6_stats_port', 5000)
        try:
            sdsd6_agg_stats = get_expvar_stats('aggregator', port=port)
            sdsd6_stats = get_expvar_stats('sdstatsd', port=port)
        except Exception as e:
            log.info("Unable to collect sdstatsd6 statistics: %s", e)
            return None

        if sdsd6_stats is not None and sdsd6_agg_stats is not None:
            packet_count = sdsd6_stats.get("ServiceCheckPackets", 0) + \
                sdsd6_stats.get("EventPackets", 0) + \
                sdsd6_stats.get("MetricPackets", 0)
            flush_counts = sdsd6_agg_stats.get("FlushCount", {})

            sdsd6_status = SdstatsdStatus(
                flush_count=sdsd6_agg_stats.get('NumberOfFlush', 0),
                packet_count=packet_count,
                packets_per_second="N/A",  # unavailable
                metric_count=flush_counts.get("Series",
                                              {}).get("LastFlush", 0),
                event_count=flush_counts.get("Events", {}).get("LastFlush", 0),
                service_check_count=flush_counts.get("ServiceChecks",
                                                     {}).get("LastFlush", 0))

            return sdsd6_status

        return None
Ejemplo n.º 2
0
    def info(self, cfg=None):
        logging.getLogger().setLevel(logging.ERROR)
        if cfg and not _is_affirmative(cfg.get('sdstatsd6_enable', False)):
            message = SdstatsdStatus._sdstatsd6_unavailable_message()
            exit_code = -1
        else:
            alt_title = "{} (v BETA)".format(self.SDSD6_BIN_NAME)
            sdsd6_status = Sdstatsd6._get_sdsd6_stats(cfg)
            if sdsd6_status:
                message = sdsd6_status.render(alt_title)
                exit_code = 0
            else:
                message = SdstatsdStatus._sdstatsd6_unavailable_message(alt_title)
                exit_code = -1

        sys.stdout.write(message)
        return exit_code
Ejemplo n.º 3
0
    def info(self, cfg=None):
        logging.getLogger().setLevel(logging.ERROR)
        if cfg and not _is_affirmative(cfg.get('sdstatsd6_enable', False)):
            message = SdstatsdStatus._sdstatsd6_unavailable_message()
            exit_code = -1
        else:
            alt_title = "{} (v BETA)".format(self.SDSD6_BIN_NAME)
            sdsd6_status = Sdstatsd6._get_sdsd6_stats(cfg)
            if sdsd6_status:
                message = sdsd6_status.render(alt_title)
                exit_code = 0
            else:
                message = SdstatsdStatus._sdstatsd6_unavailable_message(
                    alt_title)
                exit_code = -1

        sys.stdout.write(message)
        return exit_code
Ejemplo n.º 4
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
            SdstatsdStatus(
                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")
Ejemplo n.º 5
0
    def run(self):

        log.info("Reporting to %s every %ss" % (self.sd_url, self.interval))
        log.debug("Watchdog enabled: %s" % bool(self.watchdog))

        # Persist a start-up message.
        SdstatsdStatus().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('serverdensity.sdstatsd.packet.count')
            self.flush()
            if self.watchdog:
                self.watchdog.reset()

        # Clean up the status messages.
        log.debug("Stopped reporter")
        SdstatsdStatus.remove_latest_status()
Ejemplo n.º 6
0
    def run(self):

        log.info("Reporting to %s every %ss" % (self.sd_url, self.interval))
        log.debug("Watchdog enabled: %s" % bool(self.watchdog))

        # Persist a start-up message.
        SdstatsdStatus().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(
                'serverdensity.sdstatsd.packet.count')
            self.flush()
            if self.watchdog:
                self.watchdog.reset()

        # Clean up the status messages.
        log.debug("Stopped reporter")
        SdstatsdStatus.remove_latest_status()
Ejemplo n.º 7
0
 def info(self, cfg=None):
     logging.getLogger().setLevel(logging.ERROR)
     return SdstatsdStatus.print_latest_status()
Ejemplo n.º 8
0
 def info(self, cfg=None):
     logging.getLogger().setLevel(logging.ERROR)
     return SdstatsdStatus.print_latest_status()