[CalendarServer-changes] [15703] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Fri Jun 24 10:03:43 PDT 2016


Revision: 15703
          http://trac.calendarserver.org//changeset/15703
Author:   cdaboo at apple.com
Date:     2016-06-24 10:03:43 -0700 (Fri, 24 Jun 2016)
Log Message:
-----------
Add -i option to dashtime for location to store saved images to. Add options to skip ahead 1 and 5 minutes in dashview replay mode.

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tools/dashtime.py
    CalendarServer/trunk/calendarserver/tools/dashview.py
    CalendarServer/trunk/doc/Admin/Dashboard.md

Modified: CalendarServer/trunk/calendarserver/tools/dashtime.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/dashtime.py	2016-06-24 02:17:34 UTC (rev 15702)
+++ CalendarServer/trunk/calendarserver/tools/dashtime.py	2016-06-24 17:03:43 UTC (rev 15703)
@@ -27,6 +27,7 @@
 import matplotlib.pyplot as plt
 import operator
 import os
+import sys
 
 
 verbose = False
@@ -431,19 +432,21 @@
             verbose = True
 
         # Get the log file
-        self.logname = args.l
+        self.logname = os.path.expanduser(args.l)
         try:
-            if args.l.endswith(".bz2"):
-                self.logfile = BZ2File(os.path.expanduser(args.l))
+            if self.logname.endswith(".bz2"):
+                self.logfile = BZ2File(self.logname)
             else:
-                self.logfile = open(os.path.expanduser(args.l))
+                self.logfile = open(self.logname)
         except:
             print("Failed to open logfile {}".format(args.l))
+            sys.exit(1)
 
         self.pod = getattr(args, "p", None)
         self.single_server = getattr(args, "s", None)
 
         self.save = args.save
+        self.savedir = getattr(args, "i", None)
         self.noshow = args.noshow
 
         self.mode = args.mode
@@ -505,7 +508,8 @@
                     line = decompress(line.decode("base64"))
                 jline = json.loads(line)
 
-                self.x.append(ctr)
+                timestamp = jline["timestamp"]
+                self.x.append(int(timestamp[14:16]) * 60 + int(timestamp[17:19]))
                 ctr += 1
 
                 # Initialize the plot arrays when we know how many hosts there are
@@ -565,7 +569,8 @@
                     line = decompress(line.decode("base64"))
                 jline = json.loads(line)
 
-                self.x.append(ctr)
+                timestamp = jline["timestamp"]
+                self.x.append(int(timestamp[14:16]) * 60 + int(timestamp[17:19]))
                 ctr += 1
 
                 # Initialize the plot arrays when we know how many hosts there are
@@ -651,7 +656,14 @@
                 plt.subplot(len(self.y), 1, plotnum + 1)
                 plotSeries(self.titles[measurement], self.x, self.y[measurement], 0, self.ymaxes[measurement], plotnum == plotmax - 1)
         if self.save:
-            plt.savefig(".".join((os.path.expanduser(self.logname), self.mode, "png",)), orientation="landscape", format="png")
+            if self.savedir:
+                dirpath = self.savedir
+                if not os.path.exists(dirpath):
+                    os.makedirs(dirpath)
+            else:
+                dirpath = os.path.dirname(self.logname)
+            fname = ".".join((os.path.basename(self.logname), self.mode, "png"),)
+            plt.savefig(os.path.join(dirpath, fname), orientation="landscape", format="png")
         if not self.noshow:
             plt.show()
 
@@ -790,6 +802,7 @@
 """,
     )
     parser.add_argument("-l", default=SUPPRESS, required=True, help="Log file to process")
+    parser.add_argument("-i", default=SUPPRESS, help="Directory to store image (default: log file directory)")
     parser.add_argument("-p", default=SUPPRESS, help="Name of pod to analyze")
     parser.add_argument("-s", default=SUPPRESS, help="Name of server to analyze")
     parser.add_argument("--save", action="store_true", help="Save plot PNG image")
@@ -820,22 +833,26 @@
 
     plt.plot(x, y)
 
-    if last_subplot:
-        plt.xlabel("Time")
-    else:
-        frame = plt.gca()
-        frame.axes.xaxis.set_ticklabels([])
-    plt.ylabel(title, fontsize="small", horizontalalignment="right", rotation="horizontal")
+
     if ymin is not None:
         plt.ylim(ymin=ymin)
     if ymax is not None:
         plt.ylim(ymax=ymax)
-    plt.xlim(min(x), max(x))
-    plt.xticks(range(min(x), max(x) + 1, 60))
-    plt.grid(True, "major", "x", alpha=0.5, linewidth=0.5)
+    plt.xlim(0, 3600)
 
+    frame = plt.gca()
+    if last_subplot:
+        plt.xlabel("Time (minutes)")
+    plt.ylabel(title, fontsize="small", horizontalalignment="right", rotation="horizontal")
 
+    # Setup axes - want 0 - 60 minute scale for x-axis
+    plt.tick_params(labelsize="small")
+    plt.xticks(range(0, 3601, 300), range(0, 61, 5) if last_subplot else [])
+    frame.set_xticks(range(0, 3601, 60), minor=True)
+    plt.grid(True, "minor", "x", alpha=0.5, linewidth=0.5)
 
+
+
 def plotScatter(title, x, y, xlim=None, ylim=None, last_subplot=True):
     """
     Plot the chosen dataset key for each scanned data file.

Modified: CalendarServer/trunk/calendarserver/tools/dashview.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/dashview.py	2016-06-24 02:17:34 UTC (rev 15702)
+++ CalendarServer/trunk/calendarserver/tools/dashview.py	2016-06-24 17:03:43 UTC (rev 15703)
@@ -143,6 +143,9 @@
     updates.
     """
 
+    MODE_SERVER = 1
+    MODE_LOGREPLAY = 2
+
     screen = None
     registered_windows = OrderedDict()
     registered_window_sets = {
@@ -163,8 +166,10 @@
 
         if server:
             self.client = DashboardClient(self, server)
+            self.mode = self.MODE_SERVER
         else:
             self.client = DashboardLogfile(self, logfile)
+            self.mode = self.MODE_LOGREPLAY
         self.client_error = False
 
 
@@ -363,7 +368,13 @@
                 self.selected_server.x = len(self.serversForPod(self.pods()[self.selected_server.y])) - 1
             self.resetWindows()
 
+        elif c == "1" and self.mode == self.MODE_LOGREPLAY:
+            self.client.skipLines(60)
 
+        elif c == "5" and self.mode == self.MODE_LOGREPLAY:
+            self.client.skipLines(300)
+
+
     def dataForItem(self, item):
         return self.client.getOneItem(
             self.selectedPod(),
@@ -561,7 +572,15 @@
         return data
 
 
+    def skipLines(self, count):
+        try:
+            for _ignore in range(count):
+                self.logfile.readline()
+        except ValueError as e:
+            logging.debug("skipLines: failed: {}".format(e))
 
+
+
 class Aggregator(object):
 
     @staticmethod
@@ -943,11 +962,29 @@
         "",
         " q - Quit",
     )
+    helpItemsReplay = (
+        " a - All Panels",
+        " n - No Panels",
+        "",
+        "   - (space) Pause",
+        " 1 - ahead one minute",
+        " 5 - ahead five minutes",
+        " t - Toggle Update Speed",
+        " x - Toggle Aggregate Mode",
+        "",
+        " q - Quit",
+    )
 
     windowTitle = "Help"
     formatWidth = 28
     additionalRows = 3
 
+    def __init__(self, dashboard):
+        super(HelpWindow, self).__init__(dashboard)
+        if self.dashboard.mode == self.dashboard.MODE_LOGREPLAY:
+            self.helpItems = self.helpItemsReplay
+
+
     def makeWindow(self, top=0, left=0):
         term_w, _ignore_term_h = terminal_size()
         help_x_offset = term_w - self.formatWidth

Modified: CalendarServer/trunk/doc/Admin/Dashboard.md
===================================================================
--- CalendarServer/trunk/doc/Admin/Dashboard.md	2016-06-24 02:17:34 UTC (rev 15702)
+++ CalendarServer/trunk/doc/Admin/Dashboard.md	2016-06-24 17:03:43 UTC (rev 15703)
@@ -141,6 +141,8 @@
 * `a` display all panels
 * `n` display no panels
 * ` ` (space) toggle pause
+* `1` skip ahead 1 minute (only when replaying a log file)
+* `5` skip ahead 5 minutes (only when replaying a log file)
 * `t` toggle Update Speed between 0.1 secs and 1 sec.
 * `x` toggle Aggregate Mode
 * `q` Quit
@@ -157,8 +159,8 @@
 #### Help
 
 	dashtime.py --help
-	usage: dashtime.py [-h] -l L [-p P] [-s S] [--save] [--noshow] [--start START]
-	                   [--count COUNT]
+	usage: dashtime.py [-h] -l L [-i I] [-p P] [-s S] [--save] [--noshow]
+	                   [--start START] [--count COUNT]
 	                   [--mode {basic,basicjob,basicmethod,basicschedule,hostcompleted,hostcpu,hostrequests,scatter}]
 	                   [-v]
 	
@@ -167,6 +169,7 @@
 	optional arguments:
 	  -h, --help            show this help message and exit
 	  -l L                  Log file to process
+	  -i I                  Directory to store image (default: log file directory)
 	  -p P                  Name of pod to analyze
 	  -s S                  Name of server to analyze
 	  --save                Save plot PNG image (default: False)
@@ -204,6 +207,7 @@
 	scatter - scatter plot of request count and response time vs CPU.
 
 * The `-l` option must be present and point to a `dashcollect` log file.
+* The `-i` option defines the directory in which any images will be saved (if not present the directory of the log file is used).
 * The `-p` option defines the pod to view data for (if not present the first pod - alphabetically sorted - is used).
 * The `-s` option defines a specific server to view data for (there are currently no modes that use this).
 * The `--save` option, when present, will cause a PNG image of the plots to be saved to disk. The image file has the same name as the log file, but with the mode name and a `.png` suffix appended, and it will be created in the same directory as the log file.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20160624/eeebf18c/attachment-0001.html>


More information about the calendarserver-changes mailing list