Alexis Lê-Quôc avatar Alexis Lê-Quôc committed 04cd378

Starting to play with it.

Comments (0)

Files changed (3)

 	install -d ${DESTDIR}/var/lib/ganglia-logtailer
 	install -d ${DESTDIR}/var/log/ganglia-logtailer
 
-	install -d ${DESTDIR}/usr/sbin
-	install -m 0755 ${SCRIPTS} ${DESTDIR}/usr/sbin
+	install -d ${DESTDIR}/bin
+	install -m 0755 ${SCRIPTS} ${DESTDIR}/bin
 
-	install -d ${DESTDIR}/usr/share/ganglia-logtailer
-	install -m 0644 ${MODULES} ${DESTDIR}/usr/share/ganglia-logtailer
+	install -d ${DESTDIR}/share/ganglia-logtailer
+	install -m 0644 ${MODULES} ${DESTDIR}/share/ganglia-logtailer
 
 clean:
 	-rm -f ganglia-logtailer.tar.gz
 
 source-rpm: dist
 	rpmbuild -ts ganglia-logtailer.tar.gz
-	
+
 rpm: dist 
 	rpmbuild -tb ganglia-logtailer.tar.gz
 

src/ApacheLogtailer.py

         # host.com 127.0.0.1 127.0.0.1 - 2008-05-08T07:34:44 - 200 200 371 103918 - "-" "GET /path HTTP/1.0" "-" 23794
         # match keys: server_name, local_ip, remote_ip, date, conn_status, init_retcode, final_retcode, size,
         #               req_time, cookie, referrer, request, user_agent, pid
-        self.reg = re.compile('^(?P<server_name>[^ ]+) (?P<local_ip>[^ ]+) (?P<remote_ip>[^ ]+) (?P<user>[^ ]+) (?P<date>[^ ]+) (?P<conn_status>[^ ]+) (?P<init_retcode>[^ ]+) (?P<final_retcode>[^ ]+) (?P<size>[^ ]+) (?P<req_time>[^ ]+) (?P<cookie>[^ ]+) "(?P<referrer>[^"]+)" "(?P<request>[^"]+)" "(?P<user_agent>[^"]+)" (?P<pid>[^ ]+)')
+        self.reg = re.compile('^(?P<local_ip>[^ ]+) (?P<remote_ip>[^ ]+) (?P<user>[^ ]+) (?P<date>[^ ]+) (?P<conn_status>[^ ]+) (?P<init_retcode>[^ ]+) (?P<final_retcode>[^ ]+) (?P<size>[^ ]+) (?P<req_time>[^ ]+) (?P<cookie>[^ ]+) "(?P<referrer>[^"]+)" "(?P<request>[^"]+)" "(?P<user_agent>[^"]+)" (?P<pid>[^ ]+)')
 
         # assume we're in daemon mode unless set_check_duration gets called
         self.dur_override = False

src/ganglia-logtailer

 from ganglia_logtailer_helper import LogtailerParsingException, LogtailerStateException, LockingError
 
 ## globals
-gmetric = '/usr/bin/gmetric'
-#gmetric = '/bin/echo'
+# gmetric = '/usr/bin/gmetric'
+gmetric = '/bin/echo'
 logtail = '/usr/sbin/logtail'
 logtail_statedir = '/var/lib/ganglia-logtailer/'
 
     os.mkdir(logDir)
 logger = logging.getLogger('ganglia_logtailer')
 # open the log file for append, rotate at 1GB, keep 10 of them
-#hdlr = logger.RotatingFileHandler('%s/ganglia_logtailer.log' % logDir, 'a', 1000000000, 10)
-hdlr = logging.handlers.RotatingFileHandler('%s/ganglia_logtailer.log' % logDir, 'a', 10 * 1024 * 1024, 10)
+#hdlr = logging.handlers.RotatingFileHandler('%s/ganglia_logtailer.log' % logDir, 'a', 10 * 1024 * 1024, 10)
+hdlr = logging.StreamHandler()
 formatter = logging.Formatter('%(asctime)s %(levelname)-8s %(message)s')
 hdlr.setFormatter(formatter)
 logger.addHandler(hdlr)
-logger.setLevel(logging.INFO)
-#logger.setLevel(logging.DEBUG)
+logger.setLevel(logging.DEBUG)
 
 
 ## This provides a lineno() function to make it easy to grab the line
     """Returns the current line number in our program."""
     return inspect.currentframe().f_back.f_lineno
 
-def submit_stats( parser, metric_prefix, gmetric_options, duration=None  ):
+def submit_stats( parser, metric_prefix, gmetric_options, duration=None ):
     if( duration != None ):
         # this only happens in cron mode
         parser.set_check_duration(duration)
 
 # function gmetric_manager
 # takes a parser object - class instance
-def gmetric_manager( parser ):
+def gmetric_manager( parser, metric_prefix, gmetric_options ):
     '''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'''
         logger.debug("manager: starting")
         start = time.time()
         # submit the stats
-        submit_stats(parser,metric_prefix,gmetric_options)
+        submit_stats(parser, metric_prefix, gmetric_options)
         finish = time.time()
         runtime = finish - start
         sleep_time = period - runtime
             period *= 2
             # tell the logtailer class that we're slowing period
             parser.period = period
-        logger.debug( "manager: sleeping for %s" % sleep_time)
+        logger.debug("manager: sleeping for %s" % sleep_time)
         time.sleep(sleep_time)
 
 
                        help='The state dir is used in cron mode, and is where to store the logtail state file.  Default location %s' % logtail_statedir)
 
     options, arguments = cmdline.parse_args()
-#    print ('classname = %s, log_file = %s, mode = %s, state_file = %s' % (options.classname, options.log_file, options.mode, options.state_dir) )
+    print ('classname = %s, log_file = %s, mode = %s, state_file = %s' % (options.classname, options.log_file, options.mode, options.state_dir) )
 
     class_name = options.classname
     log_file = options.log_file
 
     # import and instantiate the class from the module passed in.  Files and Class names must be the same.
     try:
-        sys.path.append("/usr/local/share/ganglia-logtailer")
         module = __import__(class_name)
         parser = getattr(module, class_name)()
     except Exception, e:
     # 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=gmetric_manager, args=[parser, metric_prefix, gmetric_options])
         # the process should die when the main thread dies
         submitter.setDaemon( True )
         submitter.start()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.