Changeset 50


Ignore:
Timestamp:
04/07/05 15:28:49 (19 years ago)
Author:
bastiaans
Message:

daemon/togad.py:

Well it seems to be working now.

  • Code cleanup
  • Split checkStoreMetric into 2 functions, mem and check
  • Will now remember last update only when all entries for a file have been processed (read: after each rrd.update
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/daemon/togad.py

    r49 r50  
    2323# 7  = daemon threading
    2424#
    25 DEBUG_LEVEL = 9
     25DEBUG_LEVEL = 7
    2626
    2727# Where is the gmetad.conf located
     
    378378                #
    379379                #STORE_INTERVAL = random.randint( 360, 640 )
    380                 STORE_INTERVAL = 16
     380                STORE_INTERVAL = random.randint( 90, 120 )
    381381
    382382                storethread = threading.Thread( None, self.storeThread, 'storemetricthread' )
     
    526526                self.gatherLastUpdates()
    527527
    528         def isBlocking( self ):
    529 
    530                 return self.block
    531 
    532528        def gatherLastUpdates( self ):
    533529                "Populate the lastStored list, containing timestamps of all last updates"
    534 
    535                 self.block = 1
    536530
    537531                cluster_dir = '%s/%s' %( check_dir(ARCHIVE_PATH), self.cluster )
     
    643637                                if metric['time'] <= self.lastStored[ host ][ metric['name'] ]:
    644638
    645                                         # Allready wrote a value with this timestamp, skip tnx
     639                                        # This is old
    646640                                        return 0
    647641
    648                 else:
     642                return 1
     643
     644        def memLastUpdate( self, host, metriclist ):
     645
     646                last_update_time = 0
     647
     648                for metric in metriclist:
     649
     650                        if metric['time'] > last_update_time:
     651
     652                                last_update_time = metric['time']
     653
     654                if not self.lastStored.has_key( host ):
    649655                        self.lastStored[ host ] = { }
    650656
    651                 self.lastStored[ host ][ metric['name'] ] = metric['time']
    652 
    653                 return 1
     657                if last_update_time > self.lastStored[ host ][ metric['name'] ]:
     658                        self.lastStored[ host ][ metric['name'] ] = last_update_time
    654659
    655660        def storeMetrics( self ):
     
    659664                        for metricname, mymetric in mymetrics.items():
    660665
    661                                 #mytime = self.makeTimeSerial()
    662                                 #serial = mymetric['time']
    663                                 #correct_serial = self.checkNewRrdPeriod( hostname, mytime )
    664 
     666                                # Atomic: Don't want other threads messing around now
     667                                #
    665668                                self.slot.acquire()
    666669
     
    670673                                self.myMetrics[ hostname ][ metricname ] = [ ]
    671674
    672                                 self.slot.release()
     675                                self.slot.release() # Atomic end
     676
     677                                update_rets = [ ]
    673678
    674679                                for period, pmetric in metric_serial_table.items():
     
    684689                                                debug_msg( 9, 'metric update failed' )
    685690
    686                                 sys.exit(1)
     691                                        update_rets.append( update_ret )
     692
     693                                if not (1) in update_rets:
     694
     695                                        self.memLastUpdate( hostname, mymetric )
    687696
    688697        def makeTimeSerial( self ):
     
    694703                return mytime
    695704
    696         def makeRrdPath( self, host, metricname=None, timeserial=None ):
     705        def makeRrdPath( self, host, metricname, timeserial ):
    697706                """
    698707                Make a RRD location/path and filename
     
    701710                """
    702711
    703                 if not timeserial:     
    704                         rrd_dir = '%s/%s/%s' %( check_dir(ARCHIVE_PATH), self.cluster, host )
    705                 else:
    706                         rrd_dir = '%s/%s/%s/%s' %( check_dir(ARCHIVE_PATH), self.cluster, host, timeserial )
    707                 if metricname:
    708                         rrd_file = '%s/%s.rrd' %( rrd_dir, metricname )
    709                 else:
    710                         rrd_file = None
     712                rrd_dir = '%s/%s/%s/%s' %( check_dir(ARCHIVE_PATH), self.cluster, host, timeserial )
     713                rrd_file = '%s/%s.rrd' %( rrd_dir, metricname )
    711714
    712715                return rrd_dir, rrd_file
     
    770773                                        # This one should get it's own new period
    771774                                        period = metric['time']
     775                                        self.timeserials[ host ].append( period )
    772776
    773777                                if not metric_serial_table.has_key( period ):
     
    780784
    781785                return metric_serial_table
    782 
    783         def checkNewRrdPeriod( self, host, current_timeserial ):
    784                 """
    785                 Check if current timeserial belongs to recent time period
    786                 or should become a new period (and file).
    787 
    788                 Returns the serial of the correct time period
    789                 """
    790 
    791                 last_timeserial = int( self.getLastRrdTimeSerial( host ) )
    792                 debug_msg( 9, 'last timeserial of %s is %s' %( host, last_timeserial ) )
    793 
    794                 if not last_timeserial:
    795                         serial = current_timeserial
    796                 else:
    797 
    798                         archive_secs = ARCHIVE_HOURS_PER_RRD * (60 * 60)
    799 
    800                         if (current_timeserial - last_timeserial) > archive_secs:
    801                                 serial = current_timeserial
    802                         else:
    803                                 serial = last_timeserial
    804 
    805                 return serial
    806 
    807         def getFirstTime( self, host, metricname ):
    808                 "Get the first time of a metric we know of"
    809 
    810                 first_time = 0
    811 
    812                 for metric in self.myMetrics[ host ][ metricname ]:
    813 
    814                         if not first_time or metric['time'] <= first_time:
    815 
    816                                 first_time = metric['time']
    817 
    818                 return first_time
    819786
    820787        def createCheck( self, host, metricname, timeserial ):
Note: See TracChangeset for help on using the changeset viewer.