Commits

Anonymous committed cfefd22

Commit a change by cduffy that makes GmetricManager an object. Fixes
issues with metric_prefix when running in daemon mode

  • Participants
  • Parent commits 145672b

Comments (0)

Files changed (1)

File src/ganglia-logtailer

 
 # function gmetric_manager
 # takes a parser object - class instance
-def gmetric_manager( parser ):
+class GMetricManager(object):
     '''This process should be used to start the thread that calls
     gmetric every so often.  It should get the period and data from the
     parser object'''
-    period = parser.period
+    def __init__(self, metric_prefix, gmetric_options):
+        self.__metric_prefix = metric_prefix
+        self.__gmetric_options = gmetric_options
+    def __call__(self, parser):
+        period = parser.period
 
-    # wait one period the first time (so we have something to report)
-    time.sleep(period)
+        # wait one period the first time (so we have something to report)
+        time.sleep(period)
 
-    while True:
-        logger.debug("manager: starting")
-        start = time.time()
-        # submit the stats
-        submit_stats(parser,metric_prefix,gmetric_options)
-        finish = time.time()
-        runtime = finish - start
-        sleep_time = period - runtime
-        while( sleep_time <= 0 ):
-            logger.info( "manager: calculation time is longer than period.  doubling period to %s." % (period * 2) )
-            sleep_time += period
-            period *= 2
-            # tell the logtailer class that we're slowing period
-            parser.period = period
-        logger.debug( "manager: sleeping for %s" % sleep_time)
-        time.sleep(sleep_time)
-
-
+        while True:
+            logger.debug("manager: starting")
+            start = time.time()
+            # submit the stats
+            submit_stats(parser,self.__metric_prefix,self.__gmetric_options)
+            finish = time.time()
+            runtime = finish - start
+            sleep_time = period - runtime
+            while( sleep_time <= 0 ):
+                logger.info( "manager: calculation time is longer than period.  doubling period to %s." % (period * 2) )
+                sleep_time += period
+                period *= 2
+                # tell the logtailer class that we're slowing period
+                parser.period = period
+            logger.debug( "manager: sleeping for %s" % sleep_time)
+            time.sleep(sleep_time)
 
 # function start_locking
 def start_locking(lockfile_name):
     # if we're a daemon, launch the other thread (cron mode runs after the parsing)
     if ( mode == 'daemon' ):
         #launch gmetric caller thread
-        submitter = threading.Thread(target=gmetric_manager, args=[parser])
+        submitter = threading.Thread(target=GMetricManager(metric_prefix, gmetric_options), args=[parser])
         # the process should die when the main thread dies
         submitter.setDaemon( True )
         submitter.start()