1. Ben Hartshorne
  2. ganglia-logtailer


vvuksan  committed 9f12fbe

Add options to set metric prefix and pass options to gmetric

  • Participants
  • Parent commits 8fb12e0
  • Branches default

Comments (0)

Files changed (1)

File src/ganglia-logtailer

View file
 #!/usr/bin/python -tt
+# -*- coding: utf-8 -*-
 ###  logtailer
 ## globals
 gmetric = '/usr/bin/gmetric'
 #gmetric = '/bin/echo'
-#gmetric = '/bin/echo'
-conffile = '/etc/ganglia/gmond.conf'
 logtail = '/usr/sbin/logtail'
 logtail_statedir = '/var/lib/ganglia-logtailer/'
     """Returns the current line number in our program."""
     return inspect.currentframe().f_back.f_lineno
-def submit_stats( parser, duration=None ):
+def submit_stats( parser, metric_prefix, gmetric_options, duration=None  ):
     if( duration != None ):
         # this only happens in cron mode
         metrics = parser.get_state()
         for m in metrics:
-            logger.debug( "Submitting gmetric: %s -c %s --name %s --value %s --type %s --units %s" %
-                 (gmetric, conffile, m.name, m.value, m.type, m.units) )
-            os.system("%s -c %s --name %s --value %s --type %s --units %s" %
-                (gmetric, conffile, m.name, m.value, m.type, m.units) )
+            if ( metric_prefix != "" ):
+                m.name = metric_prefix + "_" + m.name
+            logger.debug( "Submitting gmetric: %s %s --name %s --value %s --type %s --units %s" %
+                 (gmetric, gmetric_options, m.name, m.value, m.type, m.units) )
+            os.system("%s %s --name %s --value %s --type %s --units %s" %
+                (gmetric, gmetric_options, m.name, m.value, m.type, m.units) )
     except LogtailerStateException, e:
         logger.warning( "State exception caught (line %s): %s" % (lineno(), e) )
         logger.debug("manager: starting")
         start = time.time()
         # submit the stats
-        submit_stats(parser)
+        submit_stats(parser,metric_prefix,gmetric_options)
         finish = time.time()
         runtime = finish - start
         sleep_time = period - runtime
     cmdline = optparse.OptionParser()
     cmdline.add_option('--classname', '-c', action='store', help='The name of the plugin to use to parse the log file')
     cmdline.add_option('--log_file', '-l', action='store', help='The path to the file to tail and parse')
+    cmdline.add_option('--metric_prefix', '-p', action='store', help='Add prefix to all published metrics. This is for people that may multiple instances of same service on same host. So if your metric is e.g. gc_time it becomes tomcat1_gc_time', default='' )
+    cmdline.add_option('--gmetric_options', '-g', action='store', help='Options to pass to gmetric such as -d 180 -c /etc/ganglia/gmond.conf (default). These are passed directly to gmetric',
+                       default='-d 180 -c /etc/ganglia/gmond.conf' )
     cmdline.add_option('--mode', '-m', action='store', type='choice',
                        choices=('daemon', 'cron'), default='cron',
                        help='MODE must be "cron" or "daemon".  Cron mode (default) is designed to be called every X minutes.  Daemon mode is a persistent process.')
     class_name = options.classname
     log_file = options.log_file
     mode = options.mode
+    metric_prefix = options.metric_prefix
+    gmetric_options = options.gmetric_options
     state_dir = options.state_dir
     dirsafe_logfile = log_file.replace('/','-')
     logtail_state_file = '%s/logtail-%s%s.state' % (state_dir, class_name, dirsafe_logfile)
             # something's borked.  cron's minimum is 60s
             logger.warning('duration (%s) less than 45s, despite being called from cron.  Shouldn\'t happen. (line: %s)' % (duration, lineno()))
         #print 'metric measure with duration: %s' % duration
-        submit_stats(parser, duration=duration)
+        submit_stats(parser, metric_prefix, gmetric_options, duration=duration)
         end_locking(lockfile, logtail_lock_file)
     # try and remove the lockfile one last time, but it's a valid state that it's already been removed.