Changeset 37


Ignore:
Timestamp:
04/04/05 19:11:11 (19 years ago)
Author:
bastiaans
Message:

daemon/togad.py:

  • RRDTool module will only take string variable's for parameters wrote a simple RRDMutator class to the rrdtool binary
  • Now we can parse lists for arguments to rrdupdate
  • Threading and in-memory rrd seems to work, more testing required
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/daemon/togad.py

    r36 r37  
    55import socket
    66import sys
    7 import rrdtool
    87import string
    98import os
     
    5857"""
    5958
     59class RRDMutator:
     60
     61        binary = '/usr/bin/rrdtool'
     62
     63        def __init__( self, binary=None ):
     64
     65                if binary:
     66                        self.binary = binary
     67
     68        def create( self, filename, args ):
     69                return self.perform( 'create' + ' "' + filename + '"', args )
     70
     71        def update( self, filename, args ):
     72                return self.perform( 'update' + ' "' + filename + '"', args )
     73
     74        def perform( self, action, args ):
     75
     76                arg_string = None
     77
     78                for arg in args:
     79
     80                        if not arg_string:
     81
     82                                arg_string = arg
     83                        else:
     84                                arg_string = arg_string + ' ' + arg
     85
     86                debug_msg( 7, 'rrdm.perform(): ' + self.binary + ' ' + action + ' ' + arg_string  )
     87
     88                for line in os.popen( self.binary + ' ' + action + ' ' + arg_string ).readlines():
     89
     90                        if line.find( 'ERROR' ) != -1:
     91
     92                                error_msg = string.join( line.split( ' ' )[1:] )
     93                                debu_msg( 7, error_msg )
     94                                return 1
     95
     96                return 0
     97
    6098class GangliaXMLHandler( ContentHandler ):
    6199        "Parse Ganglia's XML"
     
    320358                "Store metrics retained in memory to disk"
    321359
    322                 STORE_INTERVAL = 30
     360                STORE_INTERVAL = 5
    323361
    324362                debug_msg( 7, self.printTime() + ' - storethread() - Storing data..' )
     
    448486                self.config = config
    449487                self.slot = mutex.mutex()
     488                self.rrdm = RRDMutator()
    450489
    451490        def getClusterName( self ):
     
    476515        def makeUpdateString( self, host, metricname ):
    477516
    478                 update_string = ''
     517                update_string = None
     518
     519                print self.myMetrics[ host ][ metricname ]
    479520
    480521                for m in self.myMetrics[ host ][ metricname ]:
    481522
    482                         update_string = update_string + ' %s:%s' %( m['time'], m['val'] )
     523                        print m
     524
     525                        if not update_string:
     526                                update_string = '%s:%s' %( m['time'], m['val'] )
     527                        else:
     528                                update_string = update_string + ' %s:%s' %( m['time'], m['val'] )
    483529
    484530                return update_string
     531
     532        def makeUpdateList( self, host, metricname ):
     533
     534                update_list = [ ]
     535
     536                for metric in self.myMetrics[ host ][ metricname ]:
     537
     538                        update_list.append( '%s:%s' %( metric['time'], metric['val'] ) )
     539
     540                return update_list
    485541
    486542        def storeMetrics( self ):
     
    616672                        heartbeat = 8 * int(interval)
    617673
    618                         param_step1 = '--step'
    619                         param_step2 = str( interval )
    620 
    621                         param_start1 = '--start'
    622                         param_start2 = str( int( self.getFirstTime( host, metricname ) ) - 1 )
    623 
    624                         param_ds = 'DS:sum:GAUGE:%d:U:U' %heartbeat
    625                         param_rra = 'RRA:AVERAGE:0.5:1:%s' %(ARCHIVE_HOURS_PER_RRD * 240)
    626 
    627                         rrdtool.create( str(rrd_file), param_step1, param_step2, param_start1, param_start2, param_ds, param_rra )
     674                        params = [ ]
     675
     676                        params.append( '--step' )
     677                        params.append( str( interval ) )
     678
     679                        params.append( '--start' )
     680                        params.append( str( int( self.getFirstTime( host, metricname ) ) - 1 ) )
     681
     682                        params.append( 'DS:sum:GAUGE:%d:U:U' %heartbeat )
     683                        params.append( 'RRA:AVERAGE:0.5:1:%s' %(ARCHIVE_HOURS_PER_RRD * 240) )
     684
     685                        self.rrdm.create( str(rrd_file), params )
    628686
    629687                        debug_msg( 9, 'created rrd %s' %( str(rrd_file) ) )
     
    639697
    640698                #update_string = '%s:%s' %(timestamp, val)
    641                 update_string = self.makeUpdateString( host, metricname )
    642 
    643                 try:
    644 
    645                         rrdtool.update( str(rrd_file), str(update_string) )
    646 
    647                 except rrdtool.error, detail:
    648 
    649                         debug_msg( 0, 'EXCEPTION! While trying to update rrd:' )
    650                         debug_msg( 0, '\trrd %s with %s' %( str(rrd_file), update_string ) )
    651                         debug_msg( 0, str(detail) )
    652 
    653                         return 1
     699                update_list = self.makeUpdateList( host, metricname )
     700
     701                #try:
     702
     703                self.rrdm.update( str(rrd_file), update_list )
     704
     705                #except rrdtool.error, detail:
     706
     707                #       debug_msg( 0, 'EXCEPTION! While trying to update rrd:' )
     708                #       debug_msg( 0, '\trrd %s with %s' %( str(rrd_file), update_string ) )
     709                #       debug_msg( 0, str(detail) )
     710
     711                #       return 1
    654712               
    655                 debug_msg( 9, 'updated rrd %s with %s' %( str(rrd_file), update_string ) )
     713                debug_msg( 9, 'updated rrd %s with %s' %( str(rrd_file), string.join( update_list ) ) )
    656714
    657715                return 0
Note: See TracChangeset for help on using the changeset viewer.