コード例 #1
0
    def get_state(self, duration):
        '''Run any necessary calculations on the data collected from the logs
        and return a list of metric objects.'''
        metrics = []
        if duration > 0:
            metrics += [
                MetricObject(counter, self.counts[counter] / duration)
                for counter in self.counts
            ]
        for time_name in self.times:
            values = self.times[time_name]['values']
            unit = self.times[time_name]['unit']
            metrics.append(
                MetricObject(time_name + '.mean',
                             stats_helper.find_mean(values), unit))
            metrics.append(
                MetricObject(time_name + '.median',
                             stats_helper.find_median(values), unit))
            metrics += [
                MetricObject(
                    '%s.%sth_percentile' % (time_name, percentile),
                    stats_helper.find_percentile(values, int(percentile)),
                    unit) for percentile in self.percentiles
            ]

        return metrics
コード例 #2
0
    def get_state(self, duration):
        yield MetricObject("completed", self.count, "Jobs completeted")
        yield MetricObject("total_exec_time", self.exec_time,
                           "Total job execution time in seconds")

        for query, exec_time in self.query_exec_time.iteritems():
            yield MetricObject("%s_total_exec_time" % query, exec_time,
                               "Total query execution time in milliseconds")
コード例 #3
0
    def get_state(self, duration):
        '''Run any necessary calculations on the data collected from the logs
        and return a list of metric objects.'''
        self.duration = duration / 10

        # Return a list of metrics objects
        return [
            MetricObject("notice", (self.notice / self.duration),
                         "Logs per 10 sec"),
            MetricObject("warn", (self.warn / self.duration),
                         "Logs per 10 sec"),
            MetricObject("error", (self.error / self.duration),
                         "Logs per 10 sec"),
            MetricObject("crit", (self.crit / self.duration),
                         "Logs per 10 sec"),
            MetricObject("other", (self.other / self.duration),
                         "Logs per 10 sec"),
        ]
コード例 #4
0
    def get_state(self, duration):
        '''Run any necessary calculations on the data collected from the logs
        and return a list of metric objects.'''
        self.duration = duration

        metrics = [
            MetricObject(level, (getattr(self, level) / self.duration))
            for level in self.levels
        ]
        return metrics
コード例 #5
0
    def get_state(self, duration):
        """
        Runs any calculations on collected data and returns metric objects.

        :param duration:
        :type duration:
        :returns: List of metric objects.
        :rtype: list
        """
        metrics = []

        if duration:
            for count_key in self.kv_counts:
                metrics.append(
                    MetricObject(count_key,
                                 self.kv_counts[count_key] / duration))

        for time_key in self.kv_times:
            values = self.kv_times[time_key]['values']
            unit = self.kv_times[time_key]['unit']

            metrics.append(
                MetricObject('.'.join([time_key, 'mean']),
                             stats_helper.find_mean(values), unit))

            metrics.append(
                MetricObject('.'.join([time_key, 'median']),
                             stats_helper.find_median(values), unit))

            metrics += [
                MetricObject(
                    '.'.join([time_key,
                              "%sth_percentile" % percentile]),
                    stats_helper.find_percentile(values, int(percentile)),
                    unit) for percentile in self.percentiles
            ]

        return metrics
コード例 #6
0
    def get_state(self, duration):
        '''Run any necessary calculations on the data collected from the logs
        and return a list of metric objects.'''
        self.duration = duration
        totalTxns = self.numSent + self.numBounced + self.numDeferred
        pctDeferred = 0.0
        pctSent = 0.0
        pctBounced = 0.0
        avgDelay = 0
        mailTxnsSec = 0
        mailSentSec = 0

        #mind divide by zero situations
        if (totalTxns > 0):
            pctDeferred = (self.numDeferred / totalTxns) * 100
            pctSent = (self.numSent / totalTxns) * 100
            pctBounced = (self.numBounced / totalTxns) * 100

        if (self.numSent > 0):
            avgDelay = self.totalDelay / self.numSent

        if (self.duration > 0):
            mailTxnsSec = totalTxns / self.duration
            mailSentSec = self.numSent / self.duration

        # Return a list of metrics objects
        return [
            MetricObject("numSent", self.numSent, "Total Sent"),
            MetricObject("pctSent", pctSent, "Percentage Sent"),
            MetricObject("numDeferred", self.numDeferred, "Total Deferred"),
            MetricObject("pctDeferred", pctDeferred, "Percentage Deferred"),
            MetricObject("numBounced", self.numBounced, "Total Bounced"),
            MetricObject("pctBounced", pctBounced, "Percentage Bounced"),
            MetricObject("mailTxnsSec", mailTxnsSec, "Transactions per sec"),
            MetricObject("mailSentSec", mailSentSec, "Sends per sec"),
            MetricObject("avgDelay", avgDelay, "Average Sending Delay"),
        ]
コード例 #7
0
    def get_state(self, duration):
        '''Run any necessary calculations on the data collected from the logs
        and return a list of metric objects.'''
        self.duration = duration

        # Return a list of metrics objects
        return_array = [
            MetricObject("http_1xx", (self.http_1xx / self.duration), "Responses per sec"),
            MetricObject("http_2xx", (self.http_2xx / self.duration), "Responses per sec"),
            MetricObject("http_3xx", (self.http_3xx / self.duration), "Responses per sec"),
            MetricObject("http_4xx", (self.http_4xx / self.duration), "Responses per sec"),
            MetricObject("http_5xx", (self.http_5xx / self.duration), "Responses per sec"),
            MetricObject("size", (self.size_transferred / self.duration), "Size per sec")
        ]
        for squid_code in self.squid_codes:
            return_array.append(MetricObject("squid_" + squid_code, (self.squid_codes[squid_code]/self.duration), "Squid code per sec"))

        return return_array
コード例 #8
0
    def get_state(self, duration):
        '''Run any necessary calculations on the data collected from the logs
        and return a list of metric objects.'''

        # Return a list of metrics objects
        return [
            MetricObject("1xx.count", self.http_1x['requests'], metric_type='c'),
            MetricObject(
                "1xx.time",
                self.http_1x['time']/self.http_1x['requests'] if self.http_1x['requests']>0 else 0,
                metric_type='ms',
            ),
            MetricObject(
                "1xx.size",
                self.http_1x['bytes']/self.http_1x['requests'] if self.http_1x['requests']>0 else 0,
                metric_type='b',
            ),
            MetricObject("2xx.count", self.http_2x['requests'], metric_type='c'),
            MetricObject(
                "2xx.time",
                self.http_2x['time']/self.http_2x['requests'] if self.http_2x['requests']>0 else 0,
                metric_type='ms'
            ),
            MetricObject(
                "2xx.size",
                self.http_2x['bytes']/self.http_2x['requests'] if self.http_2x['requests']>0 else 0,
                metric_type='b'
            ),
            MetricObject("3xx.count", self.http_3x['requests'], metric_type='c'),
            MetricObject(
                "3xx.time",
                self.http_3x['time']/self.http_3x['requests'] if self.http_3x['requests']>0 else 0,
                metric_type='ms'
            ),
            MetricObject(
                "3xx.size",
                self.http_3x['bytes']/self.http_3x['requests'] if self.http_3x['requests']>0 else 0,
                metric_type='b'
            ),
            MetricObject("4xx.count", self.http_4x['requests'], metric_type='c'),
            MetricObject(
                "4xx.time",
                self.http_4x['time']/self.http_4x['requests'] if self.http_4x['requests']>0 else 0,
                metric_type='ms'
            ),
            MetricObject(
                "4xx.size",
                self.http_4x['bytes']/self.http_4x['requests'] if self.http_4x['requests']>0 else 0,
                metric_type='b'
            ),
            MetricObject("5xx.count", self.http_5x['requests'], metric_type='c'),
            MetricObject(
                "5xx.time",
                self.http_5x['time']/self.http_5x['requests'] if self.http_5x['requests']>0 else 0,
                metric_type='ms'
            ),
            MetricObject(
                "5xx.size",
                self.http_5x['bytes']/self.http_5x['requests'] if self.http_5x['requests']>0 else 0,
                metric_type='b'
            ),
        ]
コード例 #9
0
 def get_state(self, duration):
     for job, count in self.count.iteritems():
         yield MetricObject("%s.completed" % job, count, "Jobs processed")
     for job, exec_time in self.exec_time.iteritems():
         yield MetricObject("%s.total_exec_time" % job, exec_time,
                            "Total job execution time in seconds")