Changeset 17


Ignore:
Timestamp:
03/23/05 12:49:16 (19 years ago)
Author:
bastiaans
Message:

daemon/togad.py:

  • RRD's will now be timestamped, like this: disk_free$1111574193.rrd
  • If last timestamp'ed RRD has expired ARCHIVE_HOURS a new one will be created
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/daemon/togad.py

    r16 r17  
    99import os
    1010import os.path
     11import time
     12import re
    1113
    1214# Specify debugging level here;
     
    3436ARCHIVE_HOURS_PER_RRD = 24
    3537
    36 
    37 #
    38 # Configuration ends
    39 #
     38######################
     39#                    #
     40# Configuration ends #
     41#                    #
     42######################
     43
     44# What XML data types not to store
     45#
     46UNSUPPORTED_ARCHIVE_TYPES = [ 'string' ]
    4047
    4148"""
     
    102109
    103110                for metric in self.metrics:
    104                         if metric['type'] not in [ 'string' ]:
     111                        if metric['type'] not in UNSUPPORTED_ARCHIVE_TYPES:
    105112
    106113                                self.rrd.createCheck( hostname, metric )       
    107114                                self.rrd.update( hostname, metric )
    108115                                debug_msg( 9, 'stored metric %s for %s: %s' %( hostname, metric['name'], metric['val'] ) )
    109                                 #sys.exit(1)
     116                                sys.exit(1)
    110117       
    111118
     
    262269                self.gmetad_conf = GangliaConfigParser( GMETAD_CONF )
    263270
     271        def makeTimeSerial( self ):
     272
     273                # YYYYMMDDhhmmss: 20050321143411
     274                #mytime = time.strftime( "%Y%m%d%H%M%S" )
     275
     276                # Seconds since epoch
     277                mytime = int( time.time() )
     278
     279                return mytime
     280
     281        def makeRrdPath( self, host, metric, timeserial='notime' ):
     282
     283                rrd_dir = '%s/%s/%s' %( check_dir(ARCHIVE_PATH), self.cluster, host )
     284                rrd_file = '%s/%s$%s.rrd' %( rrd_dir, metric['name'], timeserial )
     285
     286                return rrd_dir, rrd_file
     287
     288        def getLastRrdTimeSerial( self, host, metric ):
     289
     290                rrd_dir, rrd_file = self.makeRrdPath( host, metric )
     291
     292                if os.path.exists( rrd_dir ):
     293                        for root, dirs, files in os.walk( rrd_dir ):
     294
     295                                newest_timeserial = 0
     296
     297                                for file in files:
     298
     299                                        myre = re.match( '(\S+)\$(\d+).rrd', file )
     300
     301                                        if not myre:
     302                                                continue
     303
     304                                        mymetric = myre.group(1)
     305
     306                                        if mymetric == metric['name']:
     307
     308                                                timeserial = myre.group(2)
     309                                                if timeserial > newest_timeserial:
     310                                                        newest_timeserial = timeserial
     311
     312                if newest_timeserial:
     313                        return timeserial
     314                else:
     315                        return 0
     316
     317        def checkNewRrdPeriod( self, host, metric ):
     318
     319                cur_timeserial = int( self.makeTimeSerial() )
     320                last_timeserial = int( self.getLastRrdTimeSerial( host, metric ) )
     321
     322                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
     329                else:
     330                        return 0, last_timeserial
     331
    264332        def createCheck( self, host, metric ):
    265333                "Check if an .rrd allready exists for this metric, create if not"
    266334
    267                 rrd_dir = '%s/%s/%s' %( check_dir(ARCHIVE_PATH), self.cluster, host )
    268                 rrd_file = '%s/%s.rrd' %( rrd_dir, metric['name'] )
     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
     342                rrd_dir, rrd_file = self.makeRrdPath( host, metric, timeserial )
    269343
    270344                if not os.path.exists( rrd_dir ):
Note: See TracChangeset for help on using the changeset viewer.