Esempio n. 1
0
class NginxErrorLogsCollector(AbstractCollector):

    short_name = 'nginx_elog'

    def __init__(self, filename=None, log_format=None, tail=None, **kwargs):
        super(NginxErrorLogsCollector, self).__init__(**kwargs)
        self.filename = filename
        self.parser = NginxErrorLogParser()
        self.tail = tail if tail is not None else FileTail(filename)

    def collect(self):
        count = 0
        for line in self.tail:
            count += 1
            try:
                error = self.parser.parse(line)
            except:
                context.log.debug('could not parse line %s' % line, exc_info=True)
                error = None

            if error:
                try:
                    self.statsd.incr(error)
                except Exception, e:
                    exception_name = e.__class__.__name__
                    context.log.error('failed to collect error log metrics due to %s' % exception_name)
                    context.log.debug('additional info:', exc_info=True)

        context.log.debug('%s processed %s lines from %s' % (self.object.id, count, self.filename))
Esempio n. 2
0
    def test_upstream_response_timed_out(self):
        line = '2015/07/14 08:42:57 [error] 28386#28386: *38698 upstream timed out ' + \
               '(110: Connection timed out) while reading response header from upstream, ' + \
               'client: 127.0.0.1, server: localhost, request: "GET /1.0/ HTTP/1.0", ' + \
               'upstream: "uwsgi://127.0.0.1:3131", host: "localhost:5000"'

        parser = NginxErrorLogParser()
        parsed = parser.parse(line)
        assert_that(parsed, equal_to('upstream.response.failed'))
Esempio n. 3
0
    def test_upstream_response_buffered(self):
        line = '2015/07/15 05:56:33 [warn] 28386#28386: *94149 an upstream response is buffered ' + \
               'to a temporary file /var/cache/nginx/proxy_temp/4/08/0000000084 while reading upstream, ' + \
               'client: 85.141.232.177, server: *.compute.amazonaws.com, request: ' + \
               '"POST /api/metrics/query/timeseries/ HTTP/1.1", upstream: ' + \
               '"http://127.0.0.1:3000/api/metrics/query/timeseries/", host: ' + \
               '"ec2-54-78-3-178.eu-west-1.compute.amazonaws.com:4000", referrer: ' + \
               '"http://ec2-54-78-3-178.eu-west-1.compute.amazonaws.com:4000/"'

        parser = NginxErrorLogParser()
        parsed = parser.parse(line)
        assert_that(parsed, equal_to('upstream.response.buffered'))
Esempio n. 4
0
 def test_none_found(self):
     line = '2015/07/15 05:56:30 [info] 28386#28386: *94160 client 10.196.158.41 closed keepalive connection'
     parser = NginxErrorLogParser()
     parsed = parser.parse(line)
     assert_that(parsed, equal_to(None))