Ejemplo n.º 1
0
class ApacheJsonLogster(LogsterParser):
    def __init__(self, option_string=None):
        '''Initialize any data structures or variables needed for keeping track
        of the tasty bits we find in the log we are parsing.'''
        self.metrics = {
            # Make sure we always report the number of 500 errors found
            "http.response.status.5xx.500":
            MetricObject(name="http.response.status.5xx.500",
                         value=0,
                         type='gauge'),
            "http.response.status.5xx":
            MetricObject(name="http.response.status.5xx",
                         value=0,
                         type='gauge'),
            # Always report the total number of requests
            "http.request.total":
            MetricObject(name="http.request.total", value=0, type='counter')
        }

    def parse_line(self, line):
        '''This function should digest the contents of one line at a time,
        updating object's state variables.

        Takes a single argument, the line to be parsed.'''

        try:
            data = json.loads(line)
        except Exception, e:
            raise LogsterParsingException, "Failing to decode line %s" % e

        try:
            status = str(data['statusCode'])
        except KeyError:
            raise LogsterParsingException, "statusCode not found"
        status_type = "%sxx" % (status[0])

        name = "http.response.status.%s" % (status_type)
        if name in self.metrics:
            self.metrics[name].value += 1
        else:
            self.metrics[name] = MetricObject(name=name,
                                              value=1,
                                              type='counter')

        name = "http.response.status.%s.%s" % (status_type, status)
        if name in self.metrics:
            self.metrics[name].value += 1
        else:
            self.metrics[name] = MetricObject(name=name,
                                              value=1,
                                              type='counter')

        self.metrics["http.request.total"].value += 1
Ejemplo n.º 2
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 [
            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"),
        ]
Ejemplo n.º 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"),
        ]
Ejemplo n.º 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
Ejemplo n.º 5
0
 def __init__(self, option_string=None):
     '''Initialize any data structures or variables needed for keeping track
     of the tasty bits we find in the log we are parsing.'''
     self.metrics = {
         # Make sure we always report the number of 500 errors found
         "http.response.status.5xx.500":
         MetricObject(name="http.response.status.5xx.500",
                      value=0,
                      type='gauge'),
         "http.response.status.5xx":
         MetricObject(name="http.response.status.5xx",
                      value=0,
                      type='gauge'),
         # Always report the total number of requests
         "http.request.total":
         MetricObject(name="http.request.total", value=0, type='counter')
     }
Ejemplo n.º 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

        # 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
Ejemplo n.º 7
0
    def get_state(self, duration):
        self.duration = duration

        outlines = []

        for k in self.metrics.keys():
            outlines.append(
                MetricObject(k, (self.metrics[k] / self.duration), "per sec"))

        return outlines
Ejemplo n.º 8
0
 def __init__(self, option_string=None):
     '''Initialize any data structures or variables needed for keeping track
     of the tasty bits we find in the log we are parsing.'''
     self.criticality_names = {
         0: 'emerg',
         1: 'alert',
         2: 'crit',
         3: 'err',
         4: 'warning',
         5: 'notice',
         6: 'info',
         7: 'debug'
     }
     self.metrics = {}
     for name in self.criticality_names.values():
         name = "app.events.crit.%s" % (name)
         self.metrics[name] = MetricObject(name=name, value=0, type='gauge')
     # the total number of events we've seen
     name = 'app.events.total'
     self.metrics[name] = MetricObject(name=name, value=0, type='counter')
     # Store all emerg, alert, crit and err messages in one metric
     # so that we don't have to add rules for each one of them
     name = 'app.events.crit.allErrors'
     self.metrics[name] = MetricObject(name=name, value=0, type='gauge')
Ejemplo n.º 9
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"),
        ]      
Ejemplo n.º 10
0
 def __init__(self, option_string=None):
     '''Initialize any data structures or variables needed for keeping track
     of the tasty bits we find in the log we are parsing.'''
     self.phpErrorLinesMetric = MetricObject(name='http.php.errorLines',
                                             value=0,
                                             type='gauge')