1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | from xml.sax import make_parser |
---|
4 | from xml.sax.handler import ContentHandler |
---|
5 | import socket |
---|
6 | import sys |
---|
7 | import rrdtool |
---|
8 | import string |
---|
9 | import os |
---|
10 | import os.path |
---|
11 | import time |
---|
12 | import re |
---|
13 | |
---|
14 | # Specify debugging level here; |
---|
15 | # |
---|
16 | # <=11 = metric XML |
---|
17 | # <=10 = host,cluster,grid,ganglia XML |
---|
18 | # <=9 = RRD activity,gmetad config parsing |
---|
19 | # <=8 = host processing |
---|
20 | # <=7 = daemon threading - NOTE: Daemon will 'halt on all errors' from this level |
---|
21 | # |
---|
22 | DEBUG_LEVEL = 10 |
---|
23 | |
---|
24 | # Where is the gmetad.conf located |
---|
25 | # |
---|
26 | GMETAD_CONF = '/etc/gmetad.conf' |
---|
27 | |
---|
28 | # Where to store the archived rrd's |
---|
29 | # |
---|
30 | ARCHIVE_PATH = '/data/toga/rrds' |
---|
31 | |
---|
32 | # List of data_source names to archive for |
---|
33 | # |
---|
34 | ARCHIVE_SOURCES = [ "LISA Cluster" ] |
---|
35 | |
---|
36 | # Amount of hours to store in one single archived .rrd |
---|
37 | # |
---|
38 | ARCHIVE_HOURS_PER_RRD = 12 |
---|
39 | |
---|
40 | # Wether or not to run as a daemon in background |
---|
41 | # |
---|
42 | DAEMONIZE = 0 |
---|
43 | |
---|
44 | ###################### |
---|
45 | # # |
---|
46 | # Configuration ends # |
---|
47 | # # |
---|
48 | ###################### |
---|
49 | |
---|
50 | # What XML data types not to store |
---|
51 | # |
---|
52 | UNSUPPORTED_ARCHIVE_TYPES = [ 'string' ] |
---|
53 | |
---|
54 | """ |
---|
55 | This is TOrque-GAnglia's data Daemon |
---|
56 | """ |
---|
57 | |
---|
58 | class GangliaXMLHandler( ContentHandler ): |
---|
59 | "Parse Ganglia's XML" |
---|
60 | |
---|
61 | def __init__( self, config ): |
---|
62 | self.config = config |
---|
63 | self.clusters = { } |
---|
64 | |
---|
65 | def startElement( self, name, attrs ): |
---|
66 | "Store appropriate data from xml start tags" |
---|
67 | |
---|
68 | if name == 'GANGLIA_XML': |
---|
69 | |
---|
70 | self.XMLSource = attrs.get( 'SOURCE', "" ) |
---|
71 | self.gangliaVersion = attrs.get( 'VERSION', "" ) |
---|
72 | |
---|
73 | debug_msg( 10, 'Found XML data: source %s version %s' %( self.XMLSource, self.gangliaVersion ) ) |
---|
74 | |
---|
75 | elif name == 'GRID': |
---|
76 | |
---|
77 | self.gridName = attrs.get( 'NAME', "" ) |
---|
78 | self.time = attrs.get( 'LOCALTIME', "" ) |
---|
79 | |
---|
80 | debug_msg( 10, '`-Grid found: %s' %( self.gridName ) ) |
---|
81 | |
---|
82 | elif name == 'CLUSTER': |
---|
83 | |
---|
84 | self.clusterName = attrs.get( 'NAME', "" ) |
---|
85 | self.time = attrs.get( 'LOCALTIME', "" ) |
---|
86 | |
---|
87 | if not self.clusters.has_key( self.clusterName ) and self.clusterName in ARCHIVE_SOURCES: |
---|
88 | |
---|
89 | self.clusters[ self.clusterName ] = RRDHandler( self.config, self.clusterName ) |
---|
90 | |
---|
91 | debug_msg( 10, ' |-Cluster found: %s' %( self.clusterName ) ) |
---|
92 | |
---|
93 | elif name == 'HOST' and self.clusterName in ARCHIVE_SOURCES: |
---|
94 | |
---|
95 | self.hostName = attrs.get( 'NAME', "" ) |
---|
96 | self.hostIp = attrs.get( 'IP', "" ) |
---|
97 | self.hostReported = attrs.get( 'REPORTED', "" ) |
---|
98 | |
---|
99 | debug_msg( 10, ' | |-Host found: %s - ip %s reported %s' %( self.hostName, self.hostIp, self.hostReported ) ) |
---|
100 | |
---|
101 | elif name == 'METRIC' and self.clusterName in ARCHIVE_SOURCES: |
---|
102 | |
---|
103 | type = attrs.get( 'TYPE', "" ) |
---|
104 | |
---|
105 | if type not in UNSUPPORTED_ARCHIVE_TYPES: |
---|
106 | |
---|
107 | myMetric = { } |
---|
108 | myMetric['name'] = attrs.get( 'NAME', "" ) |
---|
109 | myMetric['val'] = attrs.get( 'VAL', "" ) |
---|
110 | myMetric['time'] = self.hostReported |
---|
111 | |
---|
112 | self.clusters[ self.clusterName ].memMetric( self.hostName, myMetric ) |
---|
113 | |
---|
114 | debug_msg( 11, ' | | |-metric: %s:%s' %( myMetric['name'], myMetric['val'] ) ) |
---|
115 | |
---|
116 | def storeMetrics( self ): |
---|
117 | |
---|
118 | for clustername, rrdh in self.clusters.items(): |
---|
119 | |
---|
120 | print 'storing metrics of cluster ' + clustername |
---|
121 | rrdh.storeMetrics() |
---|
122 | |
---|
123 | class GangliaXMLGatherer: |
---|
124 | "Setup a connection and file object to Ganglia's XML" |
---|
125 | |
---|
126 | s = None |
---|
127 | |
---|
128 | def __init__( self, host, port ): |
---|
129 | "Store host and port for connection" |
---|
130 | |
---|
131 | self.host = host |
---|
132 | self.port = port |
---|
133 | self.connect() |
---|
134 | |
---|
135 | def connect( self ): |
---|
136 | "Setup connection to XML source" |
---|
137 | |
---|
138 | for res in socket.getaddrinfo( self.host, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM ): |
---|
139 | |
---|
140 | af, socktype, proto, canonname, sa = res |
---|
141 | |
---|
142 | try: |
---|
143 | |
---|
144 | self.s = socket.socket( af, socktype, proto ) |
---|
145 | |
---|
146 | except socket.error, msg: |
---|
147 | |
---|
148 | self.s = None |
---|
149 | continue |
---|
150 | |
---|
151 | try: |
---|
152 | |
---|
153 | self.s.connect( sa ) |
---|
154 | |
---|
155 | except socket.error, msg: |
---|
156 | |
---|
157 | self.s.close() |
---|
158 | self.s = None |
---|
159 | continue |
---|
160 | |
---|
161 | break |
---|
162 | |
---|
163 | if self.s is None: |
---|
164 | |
---|
165 | debug_msg( 0, 'Could not open socket' ) |
---|
166 | sys.exit( 1 ) |
---|
167 | |
---|
168 | def disconnect( self ): |
---|
169 | "Close socket" |
---|
170 | |
---|
171 | if self.s: |
---|
172 | self.s.close() |
---|
173 | self.s = None |
---|
174 | |
---|
175 | def __del__( self ): |
---|
176 | "Kill the socket before we leave" |
---|
177 | |
---|
178 | self.disconnect() |
---|
179 | |
---|
180 | def getFileObject( self ): |
---|
181 | "Connect, and return a file object" |
---|
182 | |
---|
183 | if not self.s: |
---|
184 | self.connect() |
---|
185 | |
---|
186 | return self.s.makefile( 'r' ) |
---|
187 | |
---|
188 | class GangliaXMLProcessor: |
---|
189 | |
---|
190 | def __init__( self ): |
---|
191 | "Setup initial XML connection and handlers" |
---|
192 | |
---|
193 | self.config = GangliaConfigParser( GMETAD_CONF ) |
---|
194 | |
---|
195 | self.myXMLGatherer = GangliaXMLGatherer( 'localhost', 8651 ) |
---|
196 | self.myParser = make_parser() |
---|
197 | self.myHandler = GangliaXMLHandler( self.config ) |
---|
198 | self.myParser.setContentHandler( self.myHandler ) |
---|
199 | |
---|
200 | def daemon( self ): |
---|
201 | "Run as daemon forever" |
---|
202 | |
---|
203 | self.DAEMON = 1 |
---|
204 | |
---|
205 | # Fork the first child |
---|
206 | # |
---|
207 | pid = os.fork() |
---|
208 | |
---|
209 | if pid > 0: |
---|
210 | |
---|
211 | sys.exit(0) # end parent |
---|
212 | |
---|
213 | # creates a session and sets the process group ID |
---|
214 | # |
---|
215 | os.setsid() |
---|
216 | |
---|
217 | # Fork the second child |
---|
218 | # |
---|
219 | pid = os.fork() |
---|
220 | |
---|
221 | if pid > 0: |
---|
222 | |
---|
223 | sys.exit(0) # end parent |
---|
224 | |
---|
225 | # Go to the root directory and set the umask |
---|
226 | # |
---|
227 | os.chdir('/') |
---|
228 | os.umask(0) |
---|
229 | |
---|
230 | sys.stdin.close() |
---|
231 | sys.stdout.close() |
---|
232 | sys.stderr.close() |
---|
233 | |
---|
234 | os.open('/dev/null', 0) |
---|
235 | os.dup(0) |
---|
236 | os.dup(0) |
---|
237 | |
---|
238 | self.run() |
---|
239 | |
---|
240 | def printTime( self ): |
---|
241 | "Print current time in human readable format" |
---|
242 | |
---|
243 | return time.strftime("%a %d %b %Y %H:%M:%S") |
---|
244 | |
---|
245 | def grabXML( self ): |
---|
246 | |
---|
247 | debug_msg( 7, self.printTime() + ' - mainthread() - xmlthread() started' ) |
---|
248 | pid = os.fork() |
---|
249 | |
---|
250 | if pid == 0: |
---|
251 | # Child - XML Thread |
---|
252 | # |
---|
253 | # Process XML and exit |
---|
254 | |
---|
255 | debug_msg( 7, self.printTime() + ' - xmlthread() - Start XML processing..' ) |
---|
256 | self.processXML() |
---|
257 | debug_msg( 7, self.printTime() + ' - xmlthread() - Done processing; exiting.' ) |
---|
258 | sys.exit( 0 ) |
---|
259 | |
---|
260 | elif pid > 0: |
---|
261 | # Parent - Time/sleep Thread |
---|
262 | # |
---|
263 | # Make sure XML is processed on time and at regular intervals |
---|
264 | |
---|
265 | debug_msg( 7, self.printTime() + ' - mainthread() - Sleep '+ str( self.config.getLowestInterval() ) +'s: zzzzz..' ) |
---|
266 | time.sleep( float( self.config.getLowestInterval() ) ) |
---|
267 | debug_msg( 7, self.printTime() + ' - mainthread() - Awoken: waiting for XML thread..' ) |
---|
268 | |
---|
269 | r = os.wait() |
---|
270 | ret = r[1] |
---|
271 | if ret != 0: |
---|
272 | debug_msg( 7, self.printTime() + ' - mainthread() - Done waiting: ERROR! xmlthread() exited with status %d' %(ret) ) |
---|
273 | if DEBUG_LEVEL>=7: sys.exit( 1 ) |
---|
274 | else: |
---|
275 | |
---|
276 | debug_msg( 7, self.printTime() + ' - mainthread() - Done waiting: xmlthread() finished succesfully' ) |
---|
277 | |
---|
278 | def run( self ): |
---|
279 | "Main thread" |
---|
280 | |
---|
281 | # Daemonized not working yet |
---|
282 | if DAEMONIZE: |
---|
283 | pid = os.fork() |
---|
284 | |
---|
285 | # Handle XML grabbing in Child |
---|
286 | if pid == 0: |
---|
287 | |
---|
288 | while( 1 ): |
---|
289 | self.grabXML() |
---|
290 | |
---|
291 | # Do scheduled RRD storing in Parent |
---|
292 | #elif pid > ): |
---|
293 | |
---|
294 | else: |
---|
295 | #self.grabXML() |
---|
296 | self.processXML() |
---|
297 | self.storeMetrics() |
---|
298 | |
---|
299 | def storeMetrics( self ): |
---|
300 | "Store metrics retained in memory to disk" |
---|
301 | |
---|
302 | self.myHandler.storeMetrics() |
---|
303 | |
---|
304 | def processXML( self ): |
---|
305 | "Process XML" |
---|
306 | |
---|
307 | self.myParser.parse( self.myXMLGatherer.getFileObject() ) |
---|
308 | |
---|
309 | class GangliaConfigParser: |
---|
310 | |
---|
311 | sources = [ ] |
---|
312 | |
---|
313 | def __init__( self, config ): |
---|
314 | |
---|
315 | self.config = config |
---|
316 | self.parseValues() |
---|
317 | |
---|
318 | def parseValues( self ): |
---|
319 | "Parse certain values from gmetad.conf" |
---|
320 | |
---|
321 | readcfg = open( self.config, 'r' ) |
---|
322 | |
---|
323 | for line in readcfg.readlines(): |
---|
324 | |
---|
325 | if line.count( '"' ) > 1: |
---|
326 | |
---|
327 | if line.find( 'data_source' ) != -1 and line[0] != '#': |
---|
328 | |
---|
329 | source = { } |
---|
330 | source['name'] = line.split( '"' )[1] |
---|
331 | source_words = line.split( '"' )[2].split( ' ' ) |
---|
332 | |
---|
333 | for word in source_words: |
---|
334 | |
---|
335 | valid_interval = 1 |
---|
336 | |
---|
337 | for letter in word: |
---|
338 | |
---|
339 | if letter not in string.digits: |
---|
340 | |
---|
341 | valid_interval = 0 |
---|
342 | |
---|
343 | if valid_interval and len(word) > 0: |
---|
344 | |
---|
345 | source['interval'] = word |
---|
346 | debug_msg( 9, 'polling interval for %s = %s' %(source['name'], source['interval'] ) ) |
---|
347 | |
---|
348 | # No interval found, use Ganglia's default |
---|
349 | if not source.has_key( 'interval' ): |
---|
350 | source['interval'] = 15 |
---|
351 | debug_msg( 9, 'polling interval for %s defaulted to 15' %(source['name']) ) |
---|
352 | |
---|
353 | self.sources.append( source ) |
---|
354 | |
---|
355 | def getInterval( self, source_name ): |
---|
356 | |
---|
357 | for source in self.sources: |
---|
358 | |
---|
359 | if source['name'] == source_name: |
---|
360 | |
---|
361 | return source['interval'] |
---|
362 | |
---|
363 | return None |
---|
364 | |
---|
365 | def getLowestInterval( self ): |
---|
366 | |
---|
367 | lowest_interval = 0 |
---|
368 | |
---|
369 | for source in self.sources: |
---|
370 | |
---|
371 | if not lowest_interval or source['interval'] <= lowest_interval: |
---|
372 | |
---|
373 | lowest_interval = source['interval'] |
---|
374 | |
---|
375 | # Return 15 when nothing is found, so that the daemon won't go insane with 0 sec delays |
---|
376 | if lowest_interval: |
---|
377 | return lowest_interval |
---|
378 | else: |
---|
379 | return 15 |
---|
380 | |
---|
381 | class RRDHandler: |
---|
382 | |
---|
383 | myMetrics = { } |
---|
384 | |
---|
385 | def __init__( self, config, cluster ): |
---|
386 | self.cluster = cluster |
---|
387 | self.config = config |
---|
388 | |
---|
389 | def getClusterName( self ): |
---|
390 | return self.cluster |
---|
391 | |
---|
392 | def memMetric( self, host, metric ): |
---|
393 | |
---|
394 | if self.myMetrics.has_key( host ): |
---|
395 | |
---|
396 | if self.myMetrics[ host ].has_key( metric['name'] ): |
---|
397 | |
---|
398 | for mymetric in self.myMetrics[ host ][ metric['name'] ]: |
---|
399 | |
---|
400 | if mymetric['time'] == metric['time']: |
---|
401 | |
---|
402 | # Allready have this metric, abort |
---|
403 | return 1 |
---|
404 | else: |
---|
405 | self.myMetrics[ host ][ metric['name'] ] = [ ] |
---|
406 | else: |
---|
407 | self.myMetrics[ host ] = { } |
---|
408 | self.myMetrics[ host ][ metric['name'] ] = [ ] |
---|
409 | |
---|
410 | |
---|
411 | self.myMetrics[ host ][ metric['name'] ].append( metric ) |
---|
412 | |
---|
413 | def makeUpdateString( self, host, metricname ): |
---|
414 | |
---|
415 | update_string = '' |
---|
416 | |
---|
417 | for m in self.myMetrics[ host ][ metricname ]: |
---|
418 | |
---|
419 | update_string = update_string + ' %s:%s' %( m['time'], m['val'] ) |
---|
420 | |
---|
421 | return update_string |
---|
422 | |
---|
423 | def storeMetrics( self ): |
---|
424 | |
---|
425 | for hostname, mymetrics in self.myMetrics.items(): |
---|
426 | |
---|
427 | for metricname, mymetric in mymetrics.items(): |
---|
428 | |
---|
429 | mytime = self.makeTimeSerial() |
---|
430 | self.createCheck( hostname, metricname, mytime ) |
---|
431 | update_okay = self.update( hostname, metricname, mytime ) |
---|
432 | |
---|
433 | if not update_okay: |
---|
434 | |
---|
435 | del self.myMetrics[ hostname ][ metricname ] |
---|
436 | debug_msg( 9, 'stored metric %s for %s' %( hostname, metricname ) ) |
---|
437 | else: |
---|
438 | debug_msg( 9, 'metric update failed' ) |
---|
439 | |
---|
440 | sys.exit(1) |
---|
441 | |
---|
442 | def makeTimeSerial( self ): |
---|
443 | "Generate a time serial. Seconds since epoch" |
---|
444 | |
---|
445 | # Seconds since epoch |
---|
446 | mytime = int( time.time() ) |
---|
447 | |
---|
448 | return mytime |
---|
449 | |
---|
450 | def makeRrdPath( self, host, metricname=None, timeserial=None ): |
---|
451 | """ |
---|
452 | Make a RRD location/path and filename |
---|
453 | If a metric or timeserial are supplied the complete locations |
---|
454 | will be made, else just the host directory |
---|
455 | """ |
---|
456 | |
---|
457 | if not timeserial: |
---|
458 | rrd_dir = '%s/%s/%s' %( check_dir(ARCHIVE_PATH), self.cluster, host ) |
---|
459 | else: |
---|
460 | rrd_dir = '%s/%s/%s/%s' %( check_dir(ARCHIVE_PATH), self.cluster, host, timeserial ) |
---|
461 | if metricname: |
---|
462 | rrd_file = '%s/%s.rrd' %( rrd_dir, metricname ) |
---|
463 | else: |
---|
464 | rrd_file = None |
---|
465 | |
---|
466 | return rrd_dir, rrd_file |
---|
467 | |
---|
468 | def getLastRrdTimeSerial( self, host ): |
---|
469 | """ |
---|
470 | Find the last timeserial (directory) for this host |
---|
471 | This is determined once every host |
---|
472 | """ |
---|
473 | |
---|
474 | rrd_dir, rrd_file = self.makeRrdPath( host ) |
---|
475 | |
---|
476 | newest_timeserial = 0 |
---|
477 | |
---|
478 | if os.path.exists( rrd_dir ): |
---|
479 | |
---|
480 | for root, dirs, files in os.walk( rrd_dir ): |
---|
481 | |
---|
482 | for dir in dirs: |
---|
483 | |
---|
484 | valid_dir = 1 |
---|
485 | |
---|
486 | for letter in dir: |
---|
487 | if letter not in string.digits: |
---|
488 | valid_dir = 0 |
---|
489 | |
---|
490 | if valid_dir: |
---|
491 | timeserial = dir |
---|
492 | if timeserial > newest_timeserial: |
---|
493 | newest_timeserial = timeserial |
---|
494 | |
---|
495 | if newest_timeserial: |
---|
496 | return newest_timeserial |
---|
497 | else: |
---|
498 | return 0 |
---|
499 | |
---|
500 | def checkNewRrdPeriod( self, host, current_timeserial ): |
---|
501 | """ |
---|
502 | Check if current timeserial belongs to recent time period |
---|
503 | or should become a new period (and file). |
---|
504 | |
---|
505 | Returns the serial of the correct time period |
---|
506 | """ |
---|
507 | |
---|
508 | last_timeserial = int( self.getLastRrdTimeSerial( host ) ) |
---|
509 | debug_msg( 9, 'last timeserial of %s is %s' %( host, last_timeserial ) ) |
---|
510 | |
---|
511 | if not last_timeserial: |
---|
512 | serial = current_timeserial |
---|
513 | else: |
---|
514 | |
---|
515 | archive_secs = ARCHIVE_HOURS_PER_RRD * (60 * 60) |
---|
516 | |
---|
517 | if (current_timeserial - last_timeserial) >= archive_secs: |
---|
518 | serial = current_timeserial |
---|
519 | else: |
---|
520 | serial = last_timeserial |
---|
521 | |
---|
522 | return serial |
---|
523 | |
---|
524 | def getFirstTime( self, host, metricname ): |
---|
525 | "Get the first time of a metric we know of" |
---|
526 | |
---|
527 | first_time = 0 |
---|
528 | |
---|
529 | for metric in self.myMetrics[ host ][ metricname ]: |
---|
530 | |
---|
531 | if not first_time or metric['time'] <= first_time: |
---|
532 | |
---|
533 | first_time = metric['time'] |
---|
534 | |
---|
535 | return first_time |
---|
536 | |
---|
537 | def createCheck( self, host, metricname, timeserial ): |
---|
538 | "Check if an .rrd allready exists for this metric, create if not" |
---|
539 | |
---|
540 | debug_msg( 9, 'rrdcreate: using timeserial %s for %s/%s' %( timeserial, host, metricname ) ) |
---|
541 | |
---|
542 | rrd_dir, rrd_file = self.makeRrdPath( host, metricname, timeserial ) |
---|
543 | |
---|
544 | if not os.path.exists( rrd_dir ): |
---|
545 | os.makedirs( rrd_dir ) |
---|
546 | debug_msg( 9, 'created dir %s' %( str(rrd_dir) ) ) |
---|
547 | |
---|
548 | if not os.path.exists( rrd_file ): |
---|
549 | |
---|
550 | interval = self.config.getInterval( self.cluster ) |
---|
551 | heartbeat = 8 * int(interval) |
---|
552 | |
---|
553 | param_step1 = '--step' |
---|
554 | param_step2 = str( interval ) |
---|
555 | |
---|
556 | param_start1 = '--start' |
---|
557 | param_start2 = str( int( self.getFirstTime( host, metricname ) ) - 1 ) |
---|
558 | |
---|
559 | param_ds = 'DS:sum:GAUGE:%d:U:U' %heartbeat |
---|
560 | param_rra = 'RRA:AVERAGE:0.5:1:%s' %(ARCHIVE_HOURS_PER_RRD * 240) |
---|
561 | |
---|
562 | rrdtool.create( str(rrd_file), param_step1, param_step2, param_start1, param_start2, param_ds, param_rra ) |
---|
563 | |
---|
564 | debug_msg( 9, 'created rrd %s' %( str(rrd_file) ) ) |
---|
565 | |
---|
566 | def update( self, host, metricname, timeserial ): |
---|
567 | |
---|
568 | debug_msg( 9, 'rrdupdate: using timeserial %s for %s/%s' %( timeserial, host, metricname ) ) |
---|
569 | |
---|
570 | rrd_dir, rrd_file = self.makeRrdPath( host, metricname, timeserial ) |
---|
571 | |
---|
572 | #timestamp = metric['time'] |
---|
573 | #val = metric['val'] |
---|
574 | |
---|
575 | #update_string = '%s:%s' %(timestamp, val) |
---|
576 | update_string = self.makeUpdateString( host, metricname ) |
---|
577 | |
---|
578 | try: |
---|
579 | |
---|
580 | rrdtool.update( str(rrd_file), str(update_string) ) |
---|
581 | |
---|
582 | except rrdtool.error, detail: |
---|
583 | |
---|
584 | debug_msg( 0, 'EXCEPTION! While trying to update rrd:' ) |
---|
585 | debug_msg( 0, '\trrd %s with %s' %( str(rrd_file), update_string ) ) |
---|
586 | debug_msg( 0, str(detail) ) |
---|
587 | |
---|
588 | return 1 |
---|
589 | |
---|
590 | debug_msg( 9, 'updated rrd %s with %s' %( str(rrd_file), update_string ) ) |
---|
591 | |
---|
592 | def main(): |
---|
593 | "Program startup" |
---|
594 | |
---|
595 | myProcessor = GangliaXMLProcessor() |
---|
596 | |
---|
597 | if DAEMONIZE: |
---|
598 | myProcessor.daemon() |
---|
599 | else: |
---|
600 | myProcessor.run() |
---|
601 | |
---|
602 | def check_dir( directory ): |
---|
603 | "Check if directory is a proper directory. I.e.: Does _not_ end with a '/'" |
---|
604 | |
---|
605 | if directory[-1] == '/': |
---|
606 | directory = directory[:-1] |
---|
607 | |
---|
608 | return directory |
---|
609 | |
---|
610 | def debug_msg( level, msg ): |
---|
611 | |
---|
612 | if (DEBUG_LEVEL >= level): |
---|
613 | sys.stderr.write( msg + '\n' ) |
---|
614 | |
---|
615 | # Let's go |
---|
616 | if __name__ == '__main__': |
---|
617 | main() |
---|