[tor-commits] [metrics-web/master] Warn if torperf data has become stale.

karsten at torproject.org karsten at torproject.org
Tue Feb 7 12:08:22 UTC 2012


commit 0002fa2b7e7c180dd4fa3c3ffa949964333e93b0
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date:   Tue Feb 7 13:05:07 2012 +0100

    Warn if torperf data has become stale.
    
    In theory, this check belongs in metrics-db, not metrics-web.  But it's
    already implemented here, and raising a log level is easier than copying
    and maintaining the code.  As soon as metrics-db uses metrics-lib this is
    all going to be so much easier...
---
 .../torproject/ernie/cron/TorperfProcessor.java    |   27 ++++++++++++++------
 1 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/src/org/torproject/ernie/cron/TorperfProcessor.java b/src/org/torproject/ernie/cron/TorperfProcessor.java
index 7caccf6..dcd0657 100644
--- a/src/org/torproject/ernie/cron/TorperfProcessor.java
+++ b/src/org/torproject/ernie/cron/TorperfProcessor.java
@@ -22,6 +22,9 @@ public class TorperfProcessor {
     SortedMap<String, String> rawObs = new TreeMap<String, String>();
     SortedMap<String, String> stats = new TreeMap<String, String>();
     int addedRawObs = 0;
+    SimpleDateFormat formatter =
+        new SimpleDateFormat("yyyy-MM-dd,HH:mm:ss");
+    formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
     try {
       if (rawFile.exists()) {
         logger.fine("Reading file " + rawFile.getAbsolutePath() + "...");
@@ -80,9 +83,6 @@ public class TorperfProcessor {
                 size.length() - "xb.data".length()));
             BufferedReader br = new BufferedReader(new FileReader(pop));
             String line = null;
-            SimpleDateFormat formatter =
-                new SimpleDateFormat("yyyy-MM-dd,HH:mm:ss");
-            formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
             while ((line = br.readLine()) != null) {
               String[] parts = line.split(" ");
               // remove defective lines as they occurred on gabelmoo
@@ -230,22 +230,33 @@ public class TorperfProcessor {
         + "Last known obserations by source and file size are:");
     String lastSource = null;
     String lastLine = null;
+    Level logLevel = Level.INFO;
+    String cutoff = formatter.format(System.currentTimeMillis()
+        - 12L * 60L * 60L * 1000L).replaceAll(",", " ");
     for (String s : rawObs.keySet()) {
       String[] parts = s.split(",");
       if (lastSource == null) {
         lastSource = parts[0];
       } else if (!parts[0].equals(lastSource)) {
-        dumpStats.append("\n" + lastSource + " " + lastLine.split(",")[1]
-            + " " + lastLine.split(",")[2]);
+        String lastKnownObservation = lastLine.split(",")[1] + " "
+            + lastLine.split(",")[2];
+        dumpStats.append("\n" + lastSource + " " + lastKnownObservation);
         lastSource = parts[0];
+        if (cutoff.compareTo(lastKnownObservation) > 0) {
+          logLevel = Level.WARNING;
+        }
       }
       lastLine = s;
     }
     if (lastSource != null) {
-      dumpStats.append("\n" + lastSource + " " + lastLine.split(",")[1]
-          + " " + lastLine.split(",")[2]);
+      String lastKnownObservation = lastLine.split(",")[1] + " "
+          + lastLine.split(",")[2];
+      dumpStats.append("\n" + lastSource + " " + lastKnownObservation);
+      if (cutoff.compareTo(lastKnownObservation) > 0) {
+        logLevel = Level.WARNING;
+      }
     }
-    logger.info(dumpStats.toString());
+    logger.log(logLevel, dumpStats.toString());
 
     /* Write results to database. */
     if (connectionURL != null) {



More information about the tor-commits mailing list