source: trunk/daemon/togad.py @ 48

Last change on this file since 48 was 48, checked in by bastiaans, 19 years ago

daemon/togad.py:

  • Bugfix
File size: 20.4 KB
Line 
1#!/usr/bin/env python
2
3from xml.sax import make_parser
4from xml.sax.handler import ContentHandler
5import socket
6import sys
7import string
8import os
9import os.path
10import time
11import re
12import threading
13import mutex
14import random
15from types import *
16
17# Specify debugging level here;
18#
19# 11 = XML: metrics
20# 10 = XML: host, cluster, grid, ganglia
21# 9  = RRD activity, gmetad config parsing
22# 8  = RRD file activity
23# 7  = daemon threading
24#
25DEBUG_LEVEL = 9
26
27# Where is the gmetad.conf located
28#
29GMETAD_CONF = '/etc/gmetad.conf'
30
31# Where to store the archived rrd's
32#
33ARCHIVE_PATH = '/data/toga/rrds'
34
35# List of data_source names to archive for
36#
37ARCHIVE_SOURCES = [ "LISA Cluster" ]
38
39# Amount of hours to store in one single archived .rrd
40#
41ARCHIVE_HOURS_PER_RRD = 12
42
43# Wether or not to run as a daemon in background
44#
45DAEMONIZE = 0
46
47######################
48#                    #
49# Configuration ends #
50#                    #
51######################
52
53# What XML data types not to store
54#
55UNSUPPORTED_ARCHIVE_TYPES = [ 'string' ]
56
57# Maximum time (in seconds) a parsethread may run
58#
59PARSE_TIMEOUT = 60
60
61# Maximum time (in seconds) a storethread may run
62#
63STORE_TIMEOUT = 360
64
65"""
66This is TOrque-GAnglia's data Daemon
67"""
68
69class RRDMutator:
70        "A class for handling .rrd mutations"
71
72        binary = '/usr/bin/rrdtool'
73
74        def __init__( self, binary=None ):
75
76                if binary:
77                        self.binary = binary
78
79        def create( self, filename, args ):
80                return self.perform( 'create', '"' + filename + '"', args )
81
82        def update( self, filename, args ):
83                return self.perform( 'update', '"' + filename + '"', args )
84
85        def grabLastUpdate( self, filename ):
86
87                last_update = 0
88
89                for line in os.popen( self.binary + ' info "' + filename + '"' ).readlines():
90
91                        if line.find( 'last_update') != -1:
92
93                                last_update = line.split( ' = ' )[1]
94
95                if last_update:
96                        return last_update
97                else:
98                        return 0
99
100        def perform( self, action, filename, args ):
101
102                arg_string = None
103
104                if type( args ) is not ListType:
105                        debug_msg( 8, 'Arguments needs to be of type List' )
106                        return 1
107
108                for arg in args:
109
110                        if not arg_string:
111
112                                arg_string = arg
113                        else:
114                                arg_string = arg_string + ' ' + arg
115
116                debug_msg( 8, 'rrdm.perform(): ' + self.binary + ' ' + action + ' ' + filename + ' ' + arg_string  )
117
118                for line in os.popen( self.binary + ' ' + action + ' ' + filename + ' ' + arg_string ).readlines():
119
120                        if line.find( 'ERROR' ) != -1:
121
122                                error_msg = string.join( line.split( ' ' )[1:] )
123                                debug_msg( 8, error_msg )
124                                return 1
125
126                return 0
127
128class GangliaXMLHandler( ContentHandler ):
129        "Parse Ganglia's XML"
130
131        def __init__( self, config ):
132                self.config = config
133                self.clusters = { }
134                debug_msg( 0, printTime() + ' Checking existing toga rrd archive..' )
135                self.gatherClusters()
136                debug_msg( 0, printTime() + ' Check done.' )
137
138        def gatherClusters( self ):
139
140                archive_dir = check_dir(ARCHIVE_PATH)
141
142                hosts = [ ]
143
144                if os.path.exists( archive_dir ):
145
146                        dirlist = os.listdir( archive_dir )
147
148                        for item in dirlist:
149
150                                clustername = item
151
152                                if not self.clusters.has_key( clustername ) and clustername in ARCHIVE_SOURCES:
153
154                                        self.clusters[ clustername ] = RRDHandler( self.config, clustername )
155
156        def startElement( self, name, attrs ):
157                "Store appropriate data from xml start tags"
158
159                if name == 'GANGLIA_XML':
160
161                        self.XMLSource = attrs.get( 'SOURCE', "" )
162                        self.gangliaVersion = attrs.get( 'VERSION', "" )
163
164                        debug_msg( 10, 'Found XML data: source %s version %s' %( self.XMLSource, self.gangliaVersion ) )
165
166                elif name == 'GRID':
167
168                        self.gridName = attrs.get( 'NAME', "" )
169                        self.time = attrs.get( 'LOCALTIME', "" )
170
171                        debug_msg( 10, '`-Grid found: %s' %( self.gridName ) )
172
173                elif name == 'CLUSTER':
174
175                        self.clusterName = attrs.get( 'NAME', "" )
176                        self.time = attrs.get( 'LOCALTIME', "" )
177
178                        if not self.clusters.has_key( self.clusterName ) and self.clusterName in ARCHIVE_SOURCES:
179
180                                self.clusters[ self.clusterName ] = RRDHandler( self.config, self.clusterName )
181
182                                debug_msg( 10, ' |-Cluster found: %s' %( self.clusterName ) )
183
184                elif name == 'HOST' and self.clusterName in ARCHIVE_SOURCES:     
185
186                        self.hostName = attrs.get( 'NAME', "" )
187                        self.hostIp = attrs.get( 'IP', "" )
188                        self.hostReported = attrs.get( 'REPORTED', "" )
189
190                        debug_msg( 10, ' | |-Host found: %s - ip %s reported %s' %( self.hostName, self.hostIp, self.hostReported ) )
191
192                elif name == 'METRIC' and self.clusterName in ARCHIVE_SOURCES:
193
194                        type = attrs.get( 'TYPE', "" )
195
196                        if type not in UNSUPPORTED_ARCHIVE_TYPES:
197
198                                myMetric = { }
199                                myMetric['name'] = attrs.get( 'NAME', "" )
200                                myMetric['val'] = attrs.get( 'VAL', "" )
201                                myMetric['time'] = self.hostReported
202
203                                self.clusters[ self.clusterName ].memMetric( self.hostName, myMetric )
204
205                                debug_msg( 11, ' | | |-metric: %s:%s' %( myMetric['name'], myMetric['val'] ) )
206
207        def storeMetrics( self ):
208
209                for clustername, rrdh in self.clusters.items():
210
211                        ret = rrdh.storeMetrics()
212
213                        if ret:
214                                debug_msg( 9, 'An error occured while storing metrics for cluster %s' %clustername )
215                                return 1
216
217                return 0
218
219class GangliaXMLGatherer:
220        "Setup a connection and file object to Ganglia's XML"
221
222        s = None
223
224        def __init__( self, host, port ):
225                "Store host and port for connection"
226
227                self.host = host
228                self.port = port
229                self.connect()
230
231        def connect( self ):
232                "Setup connection to XML source"
233
234                for res in socket.getaddrinfo( self.host, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM ):
235
236                        af, socktype, proto, canonname, sa = res
237
238                        try:
239
240                                self.s = socket.socket( af, socktype, proto )
241
242                        except socket.error, msg:
243
244                                self.s = None
245                                continue
246
247                        try:
248
249                                self.s.connect( sa )
250
251                        except socket.error, msg:
252
253                                self.s.close()
254                                self.s = None
255                                continue
256
257                        break
258
259                if self.s is None:
260
261                        debug_msg( 0, 'Could not open socket' )
262                        sys.exit( 1 )
263
264        def disconnect( self ):
265                "Close socket"
266
267                if self.s:
268                        self.s.close()
269                        self.s = None
270
271        def __del__( self ):
272                "Kill the socket before we leave"
273
274                self.disconnect()
275
276        def getFileObject( self ):
277                "Connect, and return a file object"
278
279                if self.s:
280                        # Apearantly, only data is received when a connection is made
281                        # therefor, disconnect and connect
282                        #
283                        self.disconnect()
284                        self.connect()
285
286                return self.s.makefile( 'r' )
287
288class GangliaXMLProcessor:
289
290        def __init__( self ):
291                "Setup initial XML connection and handlers"
292
293                self.config = GangliaConfigParser( GMETAD_CONF )
294
295                self.myXMLGatherer = GangliaXMLGatherer( 'localhost', 8651 ) 
296                self.myParser = make_parser()   
297                self.myHandler = GangliaXMLHandler( self.config )
298                self.myParser.setContentHandler( self.myHandler )
299
300        def daemon( self ):
301                "Run as daemon forever"
302
303                self.DAEMON = 1
304
305                # Fork the first child
306                #
307                pid = os.fork()
308
309                if pid > 0:
310
311                        sys.exit(0)  # end parent
312
313                # creates a session and sets the process group ID
314                #
315                os.setsid()
316
317                # Fork the second child
318                #
319                pid = os.fork()
320
321                if pid > 0:
322
323                        sys.exit(0)  # end parent
324
325                # Go to the root directory and set the umask
326                #
327                os.chdir('/')
328                os.umask(0)
329
330                sys.stdin.close()
331                sys.stdout.close()
332                #sys.stderr.close()
333
334                os.open('/dev/null', 0)
335                os.dup(0)
336                os.dup(0)
337
338                self.run()
339
340        def printTime( self ):
341                "Print current time in human readable format"
342
343                return time.strftime("%a %d %b %Y %H:%M:%S")
344
345        def run( self ):
346                "Main thread"
347
348                xmlthread = threading.Thread( None, self.processXML, 'xmlthread' )
349                storethread = threading.Thread( None, self.storeMetrics, 'storethread' )
350
351                while( 1 ):
352
353                        if not xmlthread.isAlive():
354                                # Gather XML at the same interval as gmetad
355
356                                # threaded call to: self.processXML()
357                                #
358                                xmlthread = threading.Thread( None, self.processXML, 'xmlthread' )
359                                xmlthread.start()
360
361                        if not storethread.isAlive():
362                                # Store metrics every .. sec
363
364                                # threaded call to: self.storeMetrics()
365                                #
366                                storethread = threading.Thread( None, self.storeMetrics, 'storethread' )
367                                storethread.start()
368               
369                        # Just sleep a sec here, to prevent daemon from going mad. We're all threads here anyway
370                        time.sleep( 1 ) 
371
372        def storeMetrics( self ):
373                "Store metrics retained in memory to disk"
374
375                debug_msg( 7, self.printTime() + ' - storethread(): started.' )
376
377                # Store metrics somewhere between every 60 and 180 seconds
378                #
379                #STORE_INTERVAL = random.randint( 360, 640 )
380                STORE_INTERVAL = 16
381
382                storethread = threading.Thread( None, self.storeThread, 'storemetricthread' )
383                storethread.start()
384
385                debug_msg( 7, self.printTime() + ' - storethread(): Sleeping.. (%ss)' %STORE_INTERVAL )
386                time.sleep( STORE_INTERVAL )
387                debug_msg( 7, self.printTime() + ' - storethread(): Done sleeping.' )
388
389                if storethread.isAlive():
390
391                        debug_msg( 7, self.printTime() + ' - storethread(): storemetricthread() still running, waiting to finish..' )
392                        storethread.join( STORE_TIMEOUT ) # Maximum time is for storing thread to finish
393                        debug_msg( 7, self.printTime() + ' - storethread(): Done waiting.' )
394
395                debug_msg( 7, self.printTime() + ' - storethread(): finished.' )
396
397                return 0
398
399        def storeThread( self ):
400
401                debug_msg( 7, self.printTime() + ' - storemetricthread(): started.' )
402                debug_msg( 7, self.printTime() + ' - storemetricthread(): Storing data..' )
403                ret = self.myHandler.storeMetrics()
404                debug_msg( 7, self.printTime() + ' - storemetricthread(): Done storing.' )
405                debug_msg( 7, self.printTime() + ' - storemetricthread(): finished.' )
406               
407                return ret
408
409        def processXML( self ):
410                "Process XML"
411
412                debug_msg( 7, self.printTime() + ' - xmlthread(): started.' )
413
414                parsethread = threading.Thread( None, self.parseThread, 'parsethread' )
415                parsethread.start()
416
417                debug_msg( 7, self.printTime() + ' - xmlthread(): Sleeping.. (%ss)' %self.config.getLowestInterval() )
418                time.sleep( float( self.config.getLowestInterval() ) ) 
419                debug_msg( 7, self.printTime() + ' - xmlthread(): Done sleeping.' )
420
421                if parsethread.isAlive():
422
423                        debug_msg( 7, self.printTime() + ' - xmlthread(): parsethread() still running, waiting to finish..' )
424                        parsethread.join( PARSE_TIMEOUT ) # Maximum time for XML thread to finish
425                        debug_msg( 7, self.printTime() + ' - xmlthread(): Done waiting.' )
426
427                debug_msg( 7, self.printTime() + ' - xmlthread(): finished.' )
428
429                return 0
430
431        def parseThread( self ):
432
433                debug_msg( 7, self.printTime() + ' - parsethread(): started.' )
434                debug_msg( 7, self.printTime() + ' - parsethread(): Parsing XML..' )
435                ret = self.myParser.parse( self.myXMLGatherer.getFileObject() )
436                debug_msg( 7, self.printTime() + ' - parsethread(): Done parsing.' )
437                debug_msg( 7, self.printTime() + ' - parsethread(): finished.' )
438
439                return ret
440
441class GangliaConfigParser:
442
443        sources = [ ]
444
445        def __init__( self, config ):
446
447                self.config = config
448                self.parseValues()
449
450        def parseValues( self ):
451                "Parse certain values from gmetad.conf"
452
453                readcfg = open( self.config, 'r' )
454
455                for line in readcfg.readlines():
456
457                        if line.count( '"' ) > 1:
458
459                                if line.find( 'data_source' ) != -1 and line[0] != '#':
460
461                                        source = { }
462                                        source['name'] = line.split( '"' )[1]
463                                        source_words = line.split( '"' )[2].split( ' ' )
464
465                                        for word in source_words:
466
467                                                valid_interval = 1
468
469                                                for letter in word:
470
471                                                        if letter not in string.digits:
472
473                                                                valid_interval = 0
474
475                                                if valid_interval and len(word) > 0:
476
477                                                        source['interval'] = word
478                                                        debug_msg( 9, 'polling interval for %s = %s' %(source['name'], source['interval'] ) )
479       
480                                        # No interval found, use Ganglia's default     
481                                        if not source.has_key( 'interval' ):
482                                                source['interval'] = 15
483                                                debug_msg( 9, 'polling interval for %s defaulted to 15' %(source['name']) )
484
485                                        self.sources.append( source )
486
487        def getInterval( self, source_name ):
488
489                for source in self.sources:
490
491                        if source['name'] == source_name:
492
493                                return source['interval']
494
495                return None
496
497        def getLowestInterval( self ):
498
499                lowest_interval = 0
500
501                for source in self.sources:
502
503                        if not lowest_interval or source['interval'] <= lowest_interval:
504
505                                lowest_interval = source['interval']
506
507                # Return 15 when nothing is found, so that the daemon won't go insane with 0 sec delays
508                if lowest_interval:
509                        return lowest_interval
510                else:
511                        return 15
512
513class RRDHandler:
514
515        myMetrics = { }
516        lastStored = { }
517        timeserials = { }
518        slot = None
519
520        def __init__( self, config, cluster ):
521                self.block = 0
522                self.cluster = cluster
523                self.config = config
524                self.slot = threading.Lock()
525                self.rrdm = RRDMutator()
526                self.gatherLastUpdates()
527
528        def isBlocking( self ):
529
530                return self.block
531
532        def gatherLastUpdates( self ):
533                "Populate the lastStored list, containing timestamps of all last updates"
534
535                self.block = 1
536
537                cluster_dir = '%s/%s' %( check_dir(ARCHIVE_PATH), self.cluster )
538
539                hosts = [ ]
540
541                if os.path.exists( cluster_dir ):
542
543                        dirlist = os.listdir( cluster_dir )
544
545                        for dir in dirlist:
546
547                                hosts.append( dir )
548
549                for host in hosts:
550
551                        host_dir = cluster_dir + '/' + host
552                        dirlist = os.listdir( host_dir )
553
554                        for dir in dirlist:
555
556                                if not self.timeserials.has_key( host ):
557
558                                        self.timeserials[ host ] = [ ]
559
560                                self.timeserials[ host ].append( dir )
561
562                        last_serial = self.getLastRrdTimeSerial( host )
563                        if last_serial:
564
565                                metric_dir = cluster_dir + '/' + host + '/' + last_serial
566                                if os.path.exists( metric_dir ):
567
568                                        dirlist = os.listdir( metric_dir )
569
570                                        for file in dirlist:
571
572                                                metricname = file.split( '.rrd' )[0]
573
574                                                if not self.lastStored.has_key( host ):
575
576                                                        self.lastStored[ host ] = { }
577
578                                                self.lastStored[ host ][ metricname ] = self.rrdm.grabLastUpdate( metric_dir + '/' + file )
579
580        def getClusterName( self ):
581                return self.cluster
582
583        def memMetric( self, host, metric ):
584
585                if self.myMetrics.has_key( host ):
586
587                        if self.myMetrics[ host ].has_key( metric['name'] ):
588
589                                for mymetric in self.myMetrics[ host ][ metric['name'] ]:
590
591                                        if mymetric['time'] == metric['time']:
592
593                                                # Allready have this metric, abort
594                                                return 1
595                        else:
596                                self.myMetrics[ host ][ metric['name'] ] = [ ]
597                else:
598                        self.myMetrics[ host ] = { }
599                        self.myMetrics[ host ][ metric['name'] ] = [ ]
600
601                # Ah, psst, push it
602                #
603                # <atomic>
604                self.slot.acquire()
605
606                self.myMetrics[ host ][ metric['name'] ].append( metric )
607
608                self.slot.release()
609                # </atomic>
610
611        def makeUpdateList( self, host, metriclist ):
612
613                update_list = [ ]
614                metric = None
615
616                while len( metriclist ) > 0:
617
618                        # Kabouter pop
619                        #
620                        # <atomic>     
621                        #self.slot.acquire()
622
623                        # len might have changed since loop start
624                        #
625                        if len( metriclist ) > 0:
626                                metric = metriclist.pop( 0 )
627
628                        #self.slot.release()
629                        # </atomic>
630
631                        if metric:
632                                if self.checkStoreMetric( host, metric ):
633                                        update_list.append( '%s:%s' %( metric['time'], metric['val'] ) )
634
635                return update_list
636
637        def checkStoreMetric( self, host, metricname, metric ):
638
639                if self.lastStored.has_key( host ):
640
641                        if self.lastStored[ host ].has_key( metric['name'] ):
642
643                                if metric['time'] <= self.lastStored[ host ][ metric['name'] ]:
644
645                                        # Allready wrote a value with this timestamp, skip tnx
646                                        return 0
647
648                else:
649                        self.lastStored[ host ] = { }
650
651                self.lastStored[ host ][ metric['name'] ] = metric['time']
652
653                return 1
654
655        def storeMetrics( self ):
656
657                for hostname, mymetrics in self.myMetrics.items():     
658
659                        for metricname, mymetric in mymetrics.items():
660
661                                #mytime = self.makeTimeSerial()
662                                #serial = mymetric['time']
663                                #correct_serial = self.checkNewRrdPeriod( hostname, mytime )
664
665                                self.slot.acquire() 
666
667                                # Create a mapping table, each metric to the period where it should be stored
668                                #
669                                metric_serial_table = self.determineSerials( hostname, metricname, mymetric )
670                                self.myMetrics[ hostname ][ metricname ] = [ ]
671
672                                self.slot.release()
673
674                                for period, pmetric in metric_serial_table.items():
675
676                                        self.createCheck( hostname, metricname, period )       
677
678                                        update_ret = self.update( hostname, metricname, period, pmetric )
679
680                                        if update_ret == 0:
681
682                                                debug_msg( 9, 'stored metric %s for %s' %( hostname, metricname ) )
683                                        else:
684                                                debug_msg( 9, 'metric update failed' )
685
686                                sys.exit(1)
687
688        def makeTimeSerial( self ):
689                "Generate a time serial. Seconds since epoch"
690
691                # Seconds since epoch
692                mytime = int( time.time() )
693
694                return mytime
695
696        def makeRrdPath( self, host, metricname=None, timeserial=None ):
697                """
698                Make a RRD location/path and filename
699                If a metric or timeserial are supplied the complete locations
700                will be made, else just the host directory
701                """
702
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
711
712                return rrd_dir, rrd_file
713
714        def getLastRrdTimeSerial( self, host ):
715                """
716                Find the last timeserial (directory) for this host
717                This is determined once every host
718                """
719
720                newest_timeserial = 0
721
722                for dir in self.timeserials[ host ]:
723
724                        valid_dir = 1
725
726                        for letter in dir:
727                                if letter not in string.digits:
728                                        valid_dir = 0
729
730                        if valid_dir:
731                                timeserial = dir
732                                if timeserial > newest_timeserial:
733                                        newest_timeserial = timeserial
734
735                if newest_timeserial:
736                        return newest_timeserial
737                else:
738                        return 0
739
740        def determinePeriod( self, host, check_serial ):
741
742                period_serial = 0
743
744                for serial in self.timeserials[ host ]:
745
746                        if check_serial >= serial and period_serial < serial:
747
748                                period_serial = serial
749
750                return period_serial
751
752        def determineSerials( self, host, metricname, metriclist ):
753                """
754                Determine the correct serial and corresponding rrd to store
755                for a list of metrics
756                """
757
758                metric_serial_table = { }
759
760                for metric in metriclist:
761
762                        if metric['name'] == metricname:
763
764                                period = self.determinePeriod( host, metric['time'] )   
765
766                                archive_secs = ARCHIVE_HOURS_PER_RRD * (60 * 60)
767
768                                if (int( metric['time'] ) - period) > archive_secs:
769
770                                        # This one should get it's own new period
771                                        period = metric['time']
772
773                                if not metric_serial_table.has_key( period ):
774
775                                        metric_serial_table = [ ]
776
777                                metric_serial_table[ period ].append( metric )
778
779                print metric_serial_table
780
781                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
819
820        def createCheck( self, host, metricname, timeserial ):
821                "Check if an .rrd allready exists for this metric, create if not"
822
823                debug_msg( 9, 'rrdcreate: using timeserial %s for %s/%s' %( timeserial, host, metricname ) )
824               
825                rrd_dir, rrd_file = self.makeRrdPath( host, metricname, timeserial )
826
827                if not os.path.exists( rrd_dir ):
828                        os.makedirs( rrd_dir )
829                        debug_msg( 9, 'created dir %s' %( str(rrd_dir) ) )
830
831                if not os.path.exists( rrd_file ):
832
833                        interval = self.config.getInterval( self.cluster )
834                        heartbeat = 8 * int( interval )
835
836                        params = [ ]
837
838                        params.append( '--step' )
839                        params.append( str( interval ) )
840
841                        params.append( '--start' )
842                        params.append( str( int( timeserial ) - 1 ) )
843
844                        params.append( 'DS:sum:GAUGE:%d:U:U' %heartbeat )
845                        params.append( 'RRA:AVERAGE:0.5:1:%s' %(ARCHIVE_HOURS_PER_RRD * 240) )
846
847                        self.rrdm.create( str(rrd_file), params )
848
849                        debug_msg( 9, 'created rrd %s' %( str(rrd_file) ) )
850
851        def update( self, host, metricname, timeserial, metriclist ):
852
853                debug_msg( 9, 'rrdupdate: using timeserial %s for %s/%s' %( timeserial, host, metricname ) )
854
855                rrd_dir, rrd_file = self.makeRrdPath( host, metricname, timeserial )
856
857                update_list = self.makeUpdateList( host, metriclist )
858
859                if len( update_list ) > 0:
860                        ret = self.rrdm.update( str(rrd_file), update_list )
861
862                        if ret:
863                                return 1
864               
865                        debug_msg( 9, 'updated rrd %s with %s' %( str(rrd_file), string.join( update_list ) ) )
866
867                return 0
868
869def main():
870        "Program startup"
871
872        myProcessor = GangliaXMLProcessor()
873
874        if DAEMONIZE:
875                myProcessor.daemon()
876        else:
877                myProcessor.run()
878
879def check_dir( directory ):
880        "Check if directory is a proper directory. I.e.: Does _not_ end with a '/'"
881
882        if directory[-1] == '/':
883                directory = directory[:-1]
884
885        return directory
886
887def debug_msg( level, msg ):
888
889        if (DEBUG_LEVEL >= level):
890                sys.stderr.write( msg + '\n' )
891
892def printTime( ):
893        "Print current time in human readable format"
894
895        return time.strftime("%a %d %b %Y %H:%M:%S")
896
897# Let's go
898if __name__ == '__main__':
899        main()
Note: See TracBrowser for help on using the repository browser.