[tor-commits] [metrics-db/master] Check whether Torperf files are becoming stale.

karsten at torproject.org karsten at torproject.org
Wed Mar 7 12:27:26 UTC 2012


commit 606cf9f55a96bbd8dcb2f2338d8f5c23aefd0e4c
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date:   Wed Mar 7 13:26:45 2012 +0100

    Check whether Torperf files are becoming stale.
---
 src/org/torproject/ernie/db/TorperfDownloader.java |   25 ++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/src/org/torproject/ernie/db/TorperfDownloader.java b/src/org/torproject/ernie/db/TorperfDownloader.java
index 9506eee..48a6ef8 100644
--- a/src/org/torproject/ernie/db/TorperfDownloader.java
+++ b/src/org/torproject/ernie/db/TorperfDownloader.java
@@ -97,6 +97,9 @@ public class TorperfDownloader {
       boolean copyLines = lastTimestampLine == null;
       while ((line = br.readLine()) != null) {
         if (copyLines && linesAfterLastTimestampLine == 0) {
+          if (isDataFile || line.contains(" LAUNCH")) {
+            lastTimestampLine = line;
+          }
           bw.write(line + "\n");
         } else if (copyLines && linesAfterLastTimestampLine > 0) {
           linesAfterLastTimestampLine--;
@@ -111,6 +114,28 @@ public class TorperfDownloader {
           + "'.", e);
       return;
     }
+    if (lastTimestampLine == null) {
+      logger.warning("'" + outputFile.getAbsolutePath() + "' doesn't "
+          + "contain any timestamp lines.  Unable to check whether that "
+          + "file is stale or not.");
+    } else {
+      long lastTimestampMillis = -1L;
+      if (isDataFile) {
+        lastTimestampMillis = Long.parseLong(lastTimestampLine.substring(
+            0, lastTimestampLine.indexOf(" "))) * 1000L;
+      } else {
+        lastTimestampMillis = Long.parseLong(lastTimestampLine.substring(
+            lastTimestampLine.indexOf(" LAUNCH=") + " LAUNCH=".length(),
+            lastTimestampLine.indexOf(".",
+            lastTimestampLine.indexOf(" LAUNCH=")))) * 1000L;
+      }
+      if (lastTimestampMillis < System.currentTimeMillis()
+          - 330L * 60L * 1000L) {
+        logger.warning("The last timestamp in '"
+            + outputFile.getAbsolutePath() + "' is more than 5:30 hours "
+            + "old: " + lastTimestampMillis);
+      }
+    }
   }
 }
 



More information about the tor-commits mailing list