Changeset 18


Ignore:
Timestamp:
03/23/05 14:27:48 (19 years ago)
Author:
bastiaans
Message:

daemon/togad.py:

  • Changed timestamp'ing style to: disk_free.1111580431.rrd
  • Rewrote some timestamp handling
  • RRD updating now updates the RRD with the correct timestamp
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/daemon/togad.py

    r17 r18  
    102102
    103103                if name == 'HOST' and self.clusterName in ARCHIVE_SOURCES:     
    104                         self.storeMetrics( self.hostName )
     104
     105                        # Determine time here, so all use same time in this run
     106                        mytime = self.rrd.makeTimeSerial()
     107
     108                        self.storeMetrics( self.hostName, mytime )
    105109
    106110                #if name == 'METRIC':
    107111
    108         def storeMetrics( self, hostname ):
     112        def storeMetrics( self, hostname, timeserial ):
    109113
    110114                for metric in self.metrics:
    111115                        if metric['type'] not in UNSUPPORTED_ARCHIVE_TYPES:
    112116
    113                                 self.rrd.createCheck( hostname, metric )       
    114                                 self.rrd.update( hostname, metric )
     117                                self.rrd.createCheck( hostname, metric, timeserial )   
     118                                self.rrd.update( hostname, metric, timeserial )
    115119                                debug_msg( 9, 'stored metric %s for %s: %s' %( hostname, metric['name'], metric['val'] ) )
    116120                                sys.exit(1)
     
    266270        def __init__( self, cluster ):
    267271                self.cluster = cluster
    268 
    269272                self.gmetad_conf = GangliaConfigParser( GMETAD_CONF )
    270273
     
    282285
    283286                rrd_dir = '%s/%s/%s' %( check_dir(ARCHIVE_PATH), self.cluster, host )
    284                 rrd_file = '%s/%s$%s.rrd' %( rrd_dir, metric['name'], timeserial )
     287                rrd_file = '%s/%s.%s.rrd' %( rrd_dir, metric['name'], timeserial )
    285288
    286289                return rrd_dir, rrd_file
     
    297300                                for file in files:
    298301
    299                                         myre = re.match( '(\S+)\$(\d+).rrd', file )
     302                                        myre = re.match( '(\S+?).(\d+).rrd', file )
    300303
    301304                                        if not myre:
     
    311314
    312315                if newest_timeserial:
    313                         return timeserial
     316                        return newest_timeserial
    314317                else:
    315318                        return 0
    316319
    317         def checkNewRrdPeriod( self, host, metric ):
    318 
    319                 cur_timeserial = int( self.makeTimeSerial() )
     320        def checkNewRrdPeriod( self, host, metric, current_timeserial ):
     321
    320322                last_timeserial = int( self.getLastRrdTimeSerial( host, metric ) )
     323                debug_msg( 8, 'last timeserial on %s of %s is %s' %( metric['name'], host, last_timeserial ) )
    321324
    322325                if not last_timeserial:
    323                         return 0, 0
    324 
    325                 archive_secs = ARCHIVE_HOURS_PER_RRD * (60 * 60)
    326 
    327                 if (cur_timeserial - last_timeserial) >= archive_secs:
    328                         return 1, last_timeserial
     326                        serial = current_timeserial
    329327                else:
    330                         return 0, last_timeserial
    331 
    332         def createCheck( self, host, metric ):
     328
     329                        archive_secs = ARCHIVE_HOURS_PER_RRD * (60 * 60)
     330
     331                        if (current_timeserial - last_timeserial) >= archive_secs:
     332                                serial = current_timeserial
     333                        else:
     334                                serial = last_timeserial
     335
     336                return serial
     337
     338        def createCheck( self, host, metric, current_timeserial ):
    333339                "Check if an .rrd allready exists for this metric, create if not"
    334340
    335                 need_new, last_timeserial = self.checkNewRrdPeriod( host, metric )
    336 
    337                 if need_new or not last_timeserial:
    338                         timeserial = self.makeTimeSerial()
    339                 else:
    340                         timeserial = last_timeserial
     341                timeserial = self.checkNewRrdPeriod( host, metric, current_timeserial )
     342                debug_msg( 8, 'rrdcreate: using timeserial %s for %s/%s' %( timeserial, host, metric['name'] ) )
    341343
    342344                rrd_dir, rrd_file = self.makeRrdPath( host, metric, timeserial )
     
    364366                        debug_msg( 9, 'created rrd %s' %( str(rrd_file) ) )
    365367
    366         def update( self, host, metric ):
    367 
    368                 rrd_dir = '%s/%s/%s' %( check_dir(ARCHIVE_PATH), self.cluster, host )
    369                 rrd_file = '%s/%s.rrd' %( rrd_dir, metric['name'] )
     368        def update( self, host, metric, current_timeserial ):
     369
     370                timeserial = self.checkNewRrdPeriod( host, metric, current_timeserial )
     371                debug_msg( 8, 'rrdupdate: using timeserial %s for %s/%s' %( timeserial, host, metric['name'] ) )
     372
     373                rrd_dir, rrd_file = self.makeRrdPath( host, metric, timeserial )
    370374
    371375                timestamp = metric['time']
Note: See TracChangeset for help on using the changeset viewer.