- Timestamp:
- 04/04/05 19:11:11 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/daemon/togad.py
r36 r37 5 5 import socket 6 6 import sys 7 import rrdtool8 7 import string 9 8 import os … … 58 57 """ 59 58 59 class RRDMutator: 60 61 binary = '/usr/bin/rrdtool' 62 63 def __init__( self, binary=None ): 64 65 if binary: 66 self.binary = binary 67 68 def create( self, filename, args ): 69 return self.perform( 'create' + ' "' + filename + '"', args ) 70 71 def update( self, filename, args ): 72 return self.perform( 'update' + ' "' + filename + '"', args ) 73 74 def perform( self, action, args ): 75 76 arg_string = None 77 78 for arg in args: 79 80 if not arg_string: 81 82 arg_string = arg 83 else: 84 arg_string = arg_string + ' ' + arg 85 86 debug_msg( 7, 'rrdm.perform(): ' + self.binary + ' ' + action + ' ' + arg_string ) 87 88 for line in os.popen( self.binary + ' ' + action + ' ' + arg_string ).readlines(): 89 90 if line.find( 'ERROR' ) != -1: 91 92 error_msg = string.join( line.split( ' ' )[1:] ) 93 debu_msg( 7, error_msg ) 94 return 1 95 96 return 0 97 60 98 class GangliaXMLHandler( ContentHandler ): 61 99 "Parse Ganglia's XML" … … 320 358 "Store metrics retained in memory to disk" 321 359 322 STORE_INTERVAL = 30360 STORE_INTERVAL = 5 323 361 324 362 debug_msg( 7, self.printTime() + ' - storethread() - Storing data..' ) … … 448 486 self.config = config 449 487 self.slot = mutex.mutex() 488 self.rrdm = RRDMutator() 450 489 451 490 def getClusterName( self ): … … 476 515 def makeUpdateString( self, host, metricname ): 477 516 478 update_string = '' 517 update_string = None 518 519 print self.myMetrics[ host ][ metricname ] 479 520 480 521 for m in self.myMetrics[ host ][ metricname ]: 481 522 482 update_string = update_string + ' %s:%s' %( m['time'], m['val'] ) 523 print m 524 525 if not update_string: 526 update_string = '%s:%s' %( m['time'], m['val'] ) 527 else: 528 update_string = update_string + ' %s:%s' %( m['time'], m['val'] ) 483 529 484 530 return update_string 531 532 def makeUpdateList( self, host, metricname ): 533 534 update_list = [ ] 535 536 for metric in self.myMetrics[ host ][ metricname ]: 537 538 update_list.append( '%s:%s' %( metric['time'], metric['val'] ) ) 539 540 return update_list 485 541 486 542 def storeMetrics( self ): … … 616 672 heartbeat = 8 * int(interval) 617 673 618 param_step1 = '--step' 619 param_step2 = str( interval ) 620 621 param_start1 = '--start' 622 param_start2 = str( int( self.getFirstTime( host, metricname ) ) - 1 ) 623 624 param_ds = 'DS:sum:GAUGE:%d:U:U' %heartbeat 625 param_rra = 'RRA:AVERAGE:0.5:1:%s' %(ARCHIVE_HOURS_PER_RRD * 240) 626 627 rrdtool.create( str(rrd_file), param_step1, param_step2, param_start1, param_start2, param_ds, param_rra ) 674 params = [ ] 675 676 params.append( '--step' ) 677 params.append( str( interval ) ) 678 679 params.append( '--start' ) 680 params.append( str( int( self.getFirstTime( host, metricname ) ) - 1 ) ) 681 682 params.append( 'DS:sum:GAUGE:%d:U:U' %heartbeat ) 683 params.append( 'RRA:AVERAGE:0.5:1:%s' %(ARCHIVE_HOURS_PER_RRD * 240) ) 684 685 self.rrdm.create( str(rrd_file), params ) 628 686 629 687 debug_msg( 9, 'created rrd %s' %( str(rrd_file) ) ) … … 639 697 640 698 #update_string = '%s:%s' %(timestamp, val) 641 update_ string = self.makeUpdateString( host, metricname )642 643 try:644 645 rrdtool.update( str(rrd_file), str(update_string))646 647 except rrdtool.error, detail:648 649 debug_msg( 0, 'EXCEPTION! While trying to update rrd:' )650 debug_msg( 0, '\trrd %s with %s' %( str(rrd_file), update_string ) )651 debug_msg( 0, str(detail) )652 653 return 1699 update_list = self.makeUpdateList( host, metricname ) 700 701 #try: 702 703 self.rrdm.update( str(rrd_file), update_list ) 704 705 #except rrdtool.error, detail: 706 707 # debug_msg( 0, 'EXCEPTION! While trying to update rrd:' ) 708 # debug_msg( 0, '\trrd %s with %s' %( str(rrd_file), update_string ) ) 709 # debug_msg( 0, str(detail) ) 710 711 # return 1 654 712 655 debug_msg( 9, 'updated rrd %s with %s' %( str(rrd_file), update_string) )713 debug_msg( 9, 'updated rrd %s with %s' %( str(rrd_file), string.join( update_list ) ) ) 656 714 657 715 return 0
Note: See TracChangeset
for help on using the changeset viewer.