diskwatcher.tac: include total-bytes-used
authorBrian Warner <warner@lothar.com>
Thu, 7 Aug 2008 20:12:14 +0000 (13:12 -0700)
committerBrian Warner <warner@lothar.com>
Thu, 7 Aug 2008 20:12:14 +0000 (13:12 -0700)
misc/munin/tahoe_diskusage
misc/munin/tahoe_doomsday
misc/spacetime/diskwatcher.tac

index a4ccf7b016c05f5339333358dc18a83bced6fc28..8f7fdfcbd122d41b002e3838a03df23f3ec367ea 100644 (file)
@@ -24,7 +24,7 @@ rate_4wk.draw LINE2"""
     sys.exit(0)
 
 url = os.environ["url"]
-timespans = simplejson.load(urllib.urlopen(url))
+timespans = simplejson.load(urllib.urlopen(url))["rates"]
 
 data = dict([(name, growth)
              for (name, timespan, growth, timeleft) in timespans])
index 08f642ca0a8e4abfd2d67f65edb08245d0fc411d..e200696391033689474c0876155a4205431398a3 100644 (file)
@@ -24,7 +24,7 @@ days_4wk.draw LINE2"""
     sys.exit(0)
 
 url = os.environ["url"]
-timespans = simplejson.load(urllib.urlopen(url))
+timespans = simplejson.load(urllib.urlopen(url))["rates"]
 
 data = dict([(name, timeleft)
              for (name, timespan, growth, timeleft) in timespans])
index 9780e2dd4d4d9ca771c18a32e68711cb9d5954e3..5fa72d897df1422cbee1198817a9468bc68983c7 100644 (file)
@@ -150,7 +150,7 @@ class DiskWatcher(service.MultiService, resource.Resource):
         Sample(store=self.store,
                url=unicode(url), when=when, used=used, avail=avail)
 
-    def calculate(self):
+    def calculate_growth_timeleft(self):
         timespans = []
         total_avail_space = self.find_total_avail_space()
         pairs = [ (timespan,name)
@@ -183,6 +183,23 @@ class DiskWatcher(service.MultiService, resource.Resource):
                 total_avail_space += latest[0].avail
         return total_avail_space
 
+    def find_total_used_space(self):
+        # this returns the sum of disk-used stats for all servers that 1) are
+        # listed in urls.txt and 2) have responded recently.
+        now = extime.Time()
+        recent = now - timedelta(seconds=2*self.POLL_INTERVAL)
+        total_used_space = 0
+        for url in self.get_urls():
+            url = unicode(url)
+            latest = list(self.store.query(Sample,
+                                           AND(Sample.url == url,
+                                               Sample.when > recent),
+                                           sort=Sample.when.descending,
+                                           limit=1))
+            if latest:
+                total_used_space += latest[0].used
+        return total_used_space
+
 
     def growth(self, timespan):
         """Calculate the bytes-per-second growth of the total disk-used stat,
@@ -268,12 +285,15 @@ class DiskWatcher(service.MultiService, resource.Resource):
         data = ""
         if t == "html":
             data = ""
-            for (name, timespan, growth, timeleft) in self.calculate():
+            for (name, timespan, growth, timeleft) in self.calculate_growth_timeleft():
                 data += "%f bytes per second, %s remaining (over %s)\n" % \
                         (growth, self.abbreviate_time(timeleft), name)
+            used = self.find_total_used_space()
+            data += "total used: %d bytes\n" % used
         elif t == "json":
-            current = self.calculate()
-            #data = str(current) + "\n" # isn't that convenient? almost.
+            current = {"rates": self.calculate_growth_timeleft(),
+                       "used": self.find_total_used_space(),
+                       }
             data = simplejson.dumps(current, indent=True)
         else:
             req.setResponseCode(http.BAD_REQUEST)