Commit e07b1f25 authored by Jérome Perrin's avatar Jérome Perrin

Support %{ms}T for duration in milliseconds

Since 2.4.13, httpd suports %{UNIT}T in LogFormat
parent 86913b29
...@@ -114,6 +114,7 @@ INPUT_ENCODING_ERROR_HANDLER = 'replace' ...@@ -114,6 +114,7 @@ INPUT_ENCODING_ERROR_HANDLER = 'replace'
MONTH_VALUE_DICT = dict((y, x) for (x, y) in enumerate(('Jan', 'Feb', 'Mar', MONTH_VALUE_DICT = dict((y, x) for (x, y) in enumerate(('Jan', 'Feb', 'Mar',
'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'), 1)) 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'), 1))
MS_PER_S = 10 ** 3
US_PER_S = 10 ** 6 US_PER_S = 10 ** 6
N_HOTTEST_PAGES_DEFAULT = 20 N_HOTTEST_PAGES_DEFAULT = 20
...@@ -806,6 +807,7 @@ class ERP5SiteStats(GenericSiteStats): ...@@ -806,6 +807,7 @@ class ERP5SiteStats(GenericSiteStats):
attribute[value_date].accumulateFrom(apdex) attribute[value_date].accumulateFrom(apdex)
DURATION_US_FORMAT = '%D' DURATION_US_FORMAT = '%D'
DURATION_MS_FORMAT = '%{ms}T'
DURATION_S_FORMAT = '%T' DURATION_S_FORMAT = '%T'
server_name_group_dict = { server_name_group_dict = {
...@@ -826,6 +828,7 @@ logformat_dict = { ...@@ -826,6 +828,7 @@ logformat_dict = {
'%{REMOTE_USER}i': r'(?P<remote_user>[^"]*)', # XXX: expected to be enclosed in " '%{REMOTE_USER}i': r'(?P<remote_user>[^"]*)', # XXX: expected to be enclosed in "
'%{User-Agent}i': r'(?P<agent>[^"]*)', # XXX: expected to be enclosed in " '%{User-Agent}i': r'(?P<agent>[^"]*)', # XXX: expected to be enclosed in "
DURATION_US_FORMAT: r'(?P<duration>[0-9]*)', DURATION_US_FORMAT: r'(?P<duration>[0-9]*)',
DURATION_MS_FORMAT: r'(?P<duration_ms>[0-9]*)',
DURATION_S_FORMAT: r'(?P<duration_s>[0-9]*)', DURATION_S_FORMAT: r'(?P<duration_s>[0-9]*)',
'%%': r'%', '%%': r'%',
'%v': r'(?P<servername>[^ ]*)', '%v': r'(?P<servername>[^ ]*)',
...@@ -1369,6 +1372,8 @@ def main(): ...@@ -1369,6 +1372,8 @@ def main():
'must be specified.') 'must be specified.')
if DURATION_US_FORMAT in args.logformat: if DURATION_US_FORMAT in args.logformat:
getDuration = lambda x: int(x.group('duration')) getDuration = lambda x: int(x.group('duration'))
elif DURATION_MS_FORMAT in args.logformat:
getDuration = lambda x: int(x.group('duration_ms')) * MS_PER_S
elif DURATION_S_FORMAT in args.logformat: elif DURATION_S_FORMAT in args.logformat:
getDuration = lambda x: int(x.group('duration_s')) * US_PER_S getDuration = lambda x: int(x.group('duration_s')) * US_PER_S
else: else:
......
...@@ -100,3 +100,42 @@ else: ...@@ -100,3 +100,42 @@ else:
class TestLzmaEncoding(ApacheDEXTestCase): class TestLzmaEncoding(ApacheDEXTestCase):
def test(self): def test(self):
self.skipTest("lzma not available") self.skipTest("lzma not available")
class TestTimeEnconding(ApacheDEXTestCase):
def test_seconds_timing(self):
with tempfile.NamedTemporaryFile() as fout:
sys.argv = ['apachedex', '--base=/', '-', '--logformat', '%h %l %u %t "%r" %>s %O "%{Referer}i" "%{User-Agent}i" %T', '-f', 'json', '-o', fout.name]
sys.stdin = StringIO(
'''127.0.0.1 - - [14/Jul/2017:09:41:41 +0200] "GET / HTTP/1.1" 200 7499 "https://example.org/" "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36" 1''')
apachedex.main()
fout.seek(0)
state = json.load(fout)
self.assertEqual(state[0][1]['apdex']['2017/07/14 09:41']['duration_max'], 1000000)
def test_milliseconds_timing(self):
with tempfile.NamedTemporaryFile() as fout:
sys.argv = ['apachedex', '--base=/', '-', '--logformat', '%h %l %u %t "%r" %>s %O "%{Referer}i" "%{User-Agent}i" %D', '-f', 'json', '-o', fout.name]
sys.stdin = StringIO(
'''127.0.0.1 - - [14/Jul/2017:09:41:41 +0200] "GET / HTTP/1.1" 200 7499 "https://example.org/" "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36" 1000000''')
apachedex.main()
fout.seek(0)
state = json.load(fout)
self.assertEqual(state[0][1]['apdex']['2017/07/14 09:41']['duration_max'], 1000000)
def test_microseconds_timing(self):
with tempfile.NamedTemporaryFile() as fout:
sys.argv = ['apachedex', '--base=/', '-', '--logformat', '%h %l %u %t "%r" %>s %O "%{Referer}i" "%{User-Agent}i" %{ms}T', '-f', 'json', '-o', fout.name]
sys.stdin = StringIO(
'''127.0.0.1 - - [14/Jul/2017:09:41:41 +0200] "GET / HTTP/1.1" 200 7499 "https://example.org/" "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36" 1000
''')
apachedex.main()
fout.seek(0)
state = json.load(fout)
self.assertEqual(state[0][1]['apdex']['2017/07/14 09:41']['duration_max'], 1000000)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment