run a stats provider even if there's no gatherer, since the HTTP /statistics page...
authorBrian Warner <warner@allmydata.com>
Thu, 8 May 2008 18:37:30 +0000 (11:37 -0700)
committerBrian Warner <warner@allmydata.com>
Thu, 8 May 2008 18:37:30 +0000 (11:37 -0700)
src/allmydata/client.py
src/allmydata/stats.py

index cb96b4958ee28599194474d428420bc09483c212..95cd8ff77a9021abc6842b96043e6f0189ec76d5 100644 (file)
@@ -114,12 +114,9 @@ class Client(node.Node, testutil.PollMixin):
 
     def init_stats_provider(self):
         gatherer_furl = self.get_config('stats_gatherer.furl')
-        if gatherer_furl:
-            self.stats_provider = StatsProvider(self, gatherer_furl)
-            self.add_service(self.stats_provider)
-            self.stats_provider.register_producer(self)
-        else:
-            self.stats_provider = None
+        self.stats_provider = StatsProvider(self, gatherer_furl)
+        self.add_service(self.stats_provider)
+        self.stats_provider.register_producer(self)
 
     def get_stats(self):
         return { 'node.uptime': time.time() - self.started_timestamp }
index 5a50b5716bd77f456c17c6c6d3d5f4fd3e33513c..96621311734e0ba8d640501ce5ef9cc7f1d57d34 100644 (file)
@@ -131,25 +131,31 @@ class StatsProvider(foolscap.Referenceable, service.MultiService):
     def __init__(self, node, gatherer_furl):
         service.MultiService.__init__(self)
         self.node = node
-        self.gatherer_furl = gatherer_furl
+        self.gatherer_furl = gatherer_furl # might be None
 
         self.counters = {}
         self.stats_producers = []
 
-        self.load_monitor = LoadMonitor(self)
-        self.load_monitor.setServiceParent(self)
-        self.register_producer(self.load_monitor)
+        # only run the LoadMonitor (which submits a timer every second) if
+        # there is a gatherer who is going to be paying attention. Our stats
+        # are visible through HTTP even without a gatherer, so run the rest
+        # of the stats (including the once-per-minute CPUUsageMonitor)
+        if gatherer_furl:
+            self.load_monitor = LoadMonitor(self)
+            self.load_monitor.setServiceParent(self)
+            self.register_producer(self.load_monitor)
 
         self.cpu_monitor = CPUUsageMonitor()
         self.cpu_monitor.setServiceParent(self)
         self.register_producer(self.cpu_monitor)
 
     def startService(self):
-        if self.node:
+        if self.node and self.gatherer_furl:
             d = self.node.when_tub_ready()
             def connect(junk):
                 nickname = self.node.get_config('nickname')
-                self.node.tub.connectTo(self.gatherer_furl, self._connected, nickname)
+                self.node.tub.connectTo(self.gatherer_furl,
+                                        self._connected, nickname)
             d.addCallback(connect)
         service.MultiService.startService(self)