[devserver] Added an apache_log_metrics.py script

This script uploads metrics to Monarch based on apache's request log.

BUG=chromium:621745
TEST=None

Change-Id: I47bf61913da25d44e3fe23fc9502e9c9caebf8a4
Reviewed-on: https://chromium-review.googlesource.com/356299
Commit-Ready: Paul Hobbs <phobbs@google.com>
Tested-by: Paul Hobbs <phobbs@google.com>
Reviewed-by: Don Garrett <dgarrett@chromium.org>
diff --git a/apache_log_metrics_unittest.py b/apache_log_metrics_unittest.py
new file mode 100755
index 0000000..8e3f3df
--- /dev/null
+++ b/apache_log_metrics_unittest.py
@@ -0,0 +1,40 @@
+#!/usr/bin/python2
+
+# Copyright 2016 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Unit tests for apache_log_metrics.py"""
+
+from __future__ import print_function
+
+import unittest
+
+import apache_log_metrics
+
+
+STATIC_REQUEST_LINE = (
+    '172.24.26.30 - - [30/Jun/2016:15:34:40 -0700] '
+    '"GET /static/veyron_minnie-release/R52-8350.46.0/'
+    'autotest_server_package.tar.bz2'
+    ' HTTP/1.1" 200 13805917 "-" "Wget/1.15    (linux-gnu)'
+)
+
+
+class TestParsers(unittest.TestCase):
+  """Tests the parsing functions in apache_log_metrics."""
+
+  def testParseStaticResponse(self):
+    match = apache_log_metrics.STATIC_GET_MATCHER.match(
+        STATIC_REQUEST_LINE)
+    self.assertTrue(match)
+
+    ip = match.group('ip_addr')
+    self.assertEqual(ip, '172.24.26.30')
+    self.assertFalse(apache_log_metrics.InLab(ip))
+
+    self.assertEqual(match.group('size'), '13805917')
+
+
+if __name__ == '__main__':
+  unittest.main()