Changeset 20 for trunk


Ignore:
Timestamp:
03/23/05 15:40:45 (19 years ago)
Author:
bastiaans
Message:

daemon/togad.py:

Directory listing each host for each metric took _ages_ to do a update run

  • Rewrote timestamping style to: <cluster>/<host>/<time>/<metric>

This requires only 1 dirlisting per host, which speeds up the app considerably:

  • A update run now takes 7 seconds, in stead of 2 minutes
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/daemon/togad.py

    r19 r20  
    105105                        # Determine time here, so all use same time in this run
    106106                        mytime = self.rrd.makeTimeSerial()
    107 
    108                         self.storeMetrics( self.hostName, mytime )
     107                        correct_serial = self.rrd.checkNewRrdPeriod( self.hostName, mytime )
     108
     109                        self.storeMetrics( self.hostName, correct_serial )
    109110
    110111                #if name == 'METRIC':
     
    282283                return mytime
    283284
    284         def makeRrdPath( self, host, metric, timeserial='notime' ):
    285 
    286                 rrd_dir = '%s/%s/%s' %( check_dir(ARCHIVE_PATH), self.cluster, host )
    287                 rrd_file = '%s/%s.%s.rrd' %( rrd_dir, metric['name'], timeserial )
     285        def makeRrdPath( self, host, metric=None, timeserial=None ):
     286
     287                if not timeserial:     
     288                        rrd_dir = '%s/%s/%s' %( check_dir(ARCHIVE_PATH), self.cluster, host )
     289                else:
     290                        rrd_dir = '%s/%s/%s/%s' %( check_dir(ARCHIVE_PATH), self.cluster, host, timeserial )
     291                if metric:
     292                        rrd_file = '%s/%s.rrd' %( rrd_dir, metric['name'] )
     293                else:
     294                        rrd_file = None
    288295
    289296                return rrd_dir, rrd_file
    290297
    291         def getLastRrdTimeSerial( self, host, metric ):
    292 
    293                 rrd_dir, rrd_file = self.makeRrdPath( host, metric )
     298        def getLastRrdTimeSerial( self, host ):
     299
     300                rrd_dir, rrd_file = self.makeRrdPath( host )
    294301
    295302                newest_timeserial = 0
     
    298305                        for root, dirs, files in os.walk( rrd_dir ):
    299306
    300                                 for file in files:
    301 
    302                                         myre = re.match( '(\S+?).(\d+).rrd', file )
    303 
    304                                         if not myre:
    305                                                 continue
    306 
    307                                         mymetric = myre.group(1)
    308 
    309                                         if mymetric == metric['name']:
    310 
    311                                                 timeserial = myre.group(2)
     307                                for dir in dirs:
     308
     309                                        valid_dir = 1
     310
     311                                        for letter in dir:
     312                                                if letter not in string.digits:
     313                                                        valid_dir = 0
     314
     315                                        if valid_dir:
     316                                                timeserial = dir
    312317                                                if timeserial > newest_timeserial:
    313318                                                        newest_timeserial = timeserial
     
    318323                        return 0
    319324
    320         def checkNewRrdPeriod( self, host, metric, current_timeserial ):
    321 
    322                 last_timeserial = int( self.getLastRrdTimeSerial( host, metric ) )
    323                 debug_msg( 8, 'last timeserial on %s of %s is %s' %( metric['name'], host, last_timeserial ) )
     325        def checkNewRrdPeriod( self, host, current_timeserial ):
     326
     327                last_timeserial = int( self.getLastRrdTimeSerial( host ) )
     328                debug_msg( 8, 'last timeserial of %s is %s' %( host, last_timeserial ) )
    324329
    325330                if not last_timeserial:
     
    336341                return serial
    337342
    338         def createCheck( self, host, metric, current_timeserial ):
     343        def createCheck( self, host, metric, timeserial ):
    339344                "Check if an .rrd allready exists for this metric, create if not"
    340345
    341                 timeserial = self.checkNewRrdPeriod( host, metric, current_timeserial )
    342346                debug_msg( 8, 'rrdcreate: using timeserial %s for %s/%s' %( timeserial, host, metric['name'] ) )
    343347
     
    366370                        debug_msg( 9, 'created rrd %s' %( str(rrd_file) ) )
    367371
    368         def update( self, host, metric, current_timeserial ):
    369 
    370                 timeserial = self.checkNewRrdPeriod( host, metric, current_timeserial )
     372        def update( self, host, metric, timeserial ):
     373
    371374                debug_msg( 8, 'rrdupdate: using timeserial %s for %s/%s' %( timeserial, host, metric['name'] ) )
    372375
Note: See TracChangeset for help on using the changeset viewer.