Changeset 17
- Timestamp:
- 03/23/05 12:49:16 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/daemon/togad.py
r16 r17 9 9 import os 10 10 import os.path 11 import time 12 import re 11 13 12 14 # Specify debugging level here; … … 34 36 ARCHIVE_HOURS_PER_RRD = 24 35 37 36 37 # 38 # Configuration ends 39 # 38 ###################### 39 # # 40 # Configuration ends # 41 # # 42 ###################### 43 44 # What XML data types not to store 45 # 46 UNSUPPORTED_ARCHIVE_TYPES = [ 'string' ] 40 47 41 48 """ … … 102 109 103 110 for metric in self.metrics: 104 if metric['type'] not in [ 'string' ]:111 if metric['type'] not in UNSUPPORTED_ARCHIVE_TYPES: 105 112 106 113 self.rrd.createCheck( hostname, metric ) 107 114 self.rrd.update( hostname, metric ) 108 115 debug_msg( 9, 'stored metric %s for %s: %s' %( hostname, metric['name'], metric['val'] ) ) 109 #sys.exit(1)116 sys.exit(1) 110 117 111 118 … … 262 269 self.gmetad_conf = GangliaConfigParser( GMETAD_CONF ) 263 270 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 264 332 def createCheck( self, host, metric ): 265 333 "Check if an .rrd allready exists for this metric, create if not" 266 334 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 ) 269 343 270 344 if not os.path.exists( rrd_dir ):
Note: See TracChangeset
for help on using the changeset viewer.