[CalendarServer-changes] [8842] CalendarServer/trunk/contrib/tools/request_monitor.py

source_changes at macosforge.org source_changes at macosforge.org
Mon Mar 12 13:06:50 PDT 2012


Revision: 8842
          http://trac.macosforge.org/projects/calendarserver/changeset/8842
Author:   cdaboo at apple.com
Date:     2012-03-12 13:06:49 -0700 (Mon, 12 Mar 2012)
Log Message:
-----------
Support aggregation of multiple access logs.

Modified Paths:
--------------
    CalendarServer/trunk/contrib/tools/request_monitor.py

Modified: CalendarServer/trunk/contrib/tools/request_monitor.py
===================================================================
--- CalendarServer/trunk/contrib/tools/request_monitor.py	2012-03-12 19:43:50 UTC (rev 8841)
+++ CalendarServer/trunk/contrib/tools/request_monitor.py	2012-03-12 20:06:49 UTC (rev 8842)
@@ -65,7 +65,7 @@
 sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) 
 
 
-filename = "/var/log/caldavd/access.log"
+filenames = ["/var/log/caldavd/access.log",]
 debug = False
 
 def listenq():
@@ -105,24 +105,28 @@
 
 
 
-def tail(filename, n):
-    child = Popen(
-        args=[
-            "/usr/bin/tail", "-%d" % (n,), filename,
-        ],
-        stdout=PIPE, stderr=STDOUT,
-    )
-    output, _ignore_error = child.communicate()
-    return output.split("\n")
+def tail(filenames, n):
+    results = []
+    for filename in filenames:
+        child = Popen(
+            args=[
+                "/usr/bin/tail", "-%d" % (n,), filename,
+            ],
+            stdout=PIPE, stderr=STDOUT,
+        )
+        output, _ignore_error = child.communicate()
+        results.extend(output.splitlines())
+    return results
 
-def range(filename, start, end):
+def range(filenames, start, end):
     results = []
-    with open(filename) as f:
-        for count, line in enumerate(f):
-            if count >= start:
-                results.append(line)
-            if count > end:
-                break
+    for filename in filenames:
+        with open(filename) as f:
+            for count, line in enumerate(f):
+                if count >= start:
+                    results.append(line)
+                if count > end:
+                    break
     return results
 
 def cpuPerDaemon():
@@ -161,7 +165,7 @@
     elif OS == "Linux":
         child = Popen(
             args=[
-                IOSTAT, "-c",
+                IOSTAT, "-c", "1", "2"
             ],
             stdout=PIPE, stderr=STDOUT,
         )
@@ -312,22 +316,24 @@
         numTop = int(value)
 
 if len(args):
-    filename = os.path.expanduser(args[0])
+    filenames = [os.path.expanduser(arg) for arg in args]
 
-if not os.path.isfile(filename):
-    print "Path %s does not exist" % (filename,)
-    print
-    usage()
-    sys.exit(1)
+for filename in filenames:
+    if not os.path.isfile(filename):
+        print "Path %s does not exist" % (filename,)
+        print
+        usage()
+        sys.exit(1)
 
-if not os.access(filename, os.R_OK):
-    print "Path %s does not exist" % (filename,)
-    print
-    usage()
-    sys.exit(1)
+for filename in filenames:
+    if not os.access(filename, os.R_OK):
+        print "Path %s does not exist" % (filename,)
+        print
+        usage()
+        sys.exit(1)
 
 if debug:
-    print "Starting: access log file: %s" % (filename,)
+    print "Starting: access log files: %s" % (", ".join(filenames),)
     print
 
 while True:
@@ -358,7 +364,7 @@
     parseErrors = 0
 
     try:
-        lines = tail(filename, numLines) if lineRange is None else range(filename, *lineRange)
+        lines = tail(filenames, numLines) if lineRange is None else range(filenames, *lineRange)
         for line in lines:
             if not line or line.startswith("Log"):
                 continue
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120312/0c98eb43/attachment.html>


More information about the calendarserver-changes mailing list