Changeset 214


Ignore:
Timestamp:
02/24/06 17:58:01 (18 years ago)
Author:
bastiaans
Message:

jobarchived/jobarchived.conf:

  • import of config

jobarchived/jobarchived.py:

  • added config file support
Location:
trunk/jobarchived
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/jobarchived/jobarchived.py

    r199 r214  
    11#!/usr/bin/env python
    22
    3 import xml.sax
    4 import xml.sax.handler
    5 import socket
    6 import sys
    7 import syslog
    8 import string
    9 import os
    10 import os.path
    11 import time
    12 import thread
    13 import threading
    14 import random
    15 import re
    16 from types import *
    17 import DBClass
    18 
    19 # Specify debugging level here (only when _not_ DAEMONIZE)
    20 #
    21 # 11 = XML: metrics
    22 # 10 = XML: host, cluster, grid, ganglia
    23 # 9  = RRD activity, gmetad config parsing
    24 # 8  = RRD file activity
    25 # 6  = SQL
    26 # 1  = daemon threading
    27 # 0  = errors
    28 #
    29 # default: 0
    30 DEBUG_LEVEL = 1
    31 
    32 # Enable logging to syslog?
    33 #
    34 USE_SYSLOG = 1
    35 
    36 # What level msg'es should be logged to syslog?
    37 #
    38 # default: lvl 0 (errors)
    39 #
    40 SYSLOG_LEVEL = 0
    41 
    42 # Which facility to use in syslog
    43 #
    44 # Syntax I.e.:
    45 #       LOG_KERN, LOG_USER, LOG_MAIL, LOG_DAEMON, LOG_AUTH, LOG_LPR,
    46 #       LOG_NEWS, LOG_UUCP, LOG_CRON and LOG_LOCAL0 to LOG_LOCAL7
    47 #
    48 SYSLOG_FACILITY = syslog.LOG_DAEMON
    49 
    50 # Where is the gmetad.conf located
    51 #
    52 GMETAD_CONF = '/etc/gmetad.conf'
    53 
    54 # Where to grab XML data from
    55 # Normally: local gmetad (port 8651)
    56 #
    57 # Syntax: <hostname>:<port>
    58 #
    59 ARCHIVE_XMLSOURCE = "localhost:8651"
    60 
    61 # List of data_source names to archive for
    62 #
    63 # Syntax: [ "<clustername>", "<clustername>" ]
    64 #
    65 ARCHIVE_DATASOURCES = [ "LISA Cluster", "LISA Test Cluster" ]
    66 
    67 # Where to store the archived rrd's
    68 #
    69 ARCHIVE_PATH = '/data/toga/rrds'
    70 
    71 # Amount of hours to store in one single archived .rrd
    72 #
    73 ARCHIVE_HOURS_PER_RRD = 12
    74 
    75 # Which metrics to exclude from archiving
    76 # NOTE: This can be a regexp or a string
    77 #
    78 ARCHIVE_EXCLUDE_METRICS = [ "^Temp_.*_.*", ".*_Temp_.*", ".*_RPM_.*", ".*_Battery_.*" ]
    79 
    80 # Toga's SQL dbase to use
    81 #
    82 # Syntax: <hostname>/<database>
    83 #
    84 TOGA_SQL_DBASE = "localhost/toga"
    85 
    86 # Wether or not to run as a daemon in background
    87 #
    88 DAEMONIZE = 1
    89 
    90 ######################
    91 #                    #
    92 # Configuration ends #
    93 #                    #
    94 ######################
     3import getopt, syslog, ConfigParser, sys
     4
     5def processArgs( args ):
     6
     7        SHORT_L = 'c:'
     8        LONG_L = 'config='
     9
     10        config_filename = None
     11
     12        try:
     13
     14                opts, args = getopt.getopt( args, SHORT_L, LONG_L )
     15
     16        except getopt.error, detail:
     17
     18                print detail
     19                sys.exit(1)
     20
     21        for opt, value in opts:
     22
     23                if opt in [ '--config', '-c' ]:
     24
     25                        config_filename = value
     26
     27        if not config_filename:
     28
     29                config_filename = '/etc/jobarchived.conf'
     30
     31        try:
     32                return loadConfig( config_filename )
     33
     34        except ConfigParser.NoOptionError, detail:
     35
     36                print detail
     37                sys.exit( 1 )
     38
     39def loadConfig( filename ):
     40
     41        def getlist( cfg_string ):
     42
     43                my_list = [ ]
     44
     45                for item_txt in cfg_string.split( ',' ):
     46
     47                        sep_char = None
     48
     49                        item_txt = item_txt.strip()
     50
     51                        for s_char in [ "'", '"' ]:
     52
     53                                if item_txt.find( s_char ) != -1:
     54
     55                                        if item_txt.count( s_char ) != 2:
     56
     57                                                print 'Missing quote: %s' %item_txt
     58                                                sys.exit( 1 )
     59
     60                                        else:
     61
     62                                                sep_char = s_char
     63                                                break
     64
     65                        if sep_char:
     66
     67                                item_txt = item_txt.split( sep_char )[1]
     68
     69                        my_list.append( item_txt )
     70
     71                return my_list
     72
     73        cfg = ConfigParser.ConfigParser()
     74
     75        cfg.read( filename )
     76
     77        # Which metrics to exclude from archiving
     78        global DEBUG_LEVEL, USE_SYSLOG, SYSLOG_LEVEL, SYSLOG_FACILITY, GMETAD_CONF, ARCHIVE_XMLSOURCE, ARCHIVE_DATASOURCES, ARCHIVE_PATH, ARCHIVE_HOURS_PER_RRD, ARCHIVE_EXCLUDE_METRICS, JOB_SQL_DBASE, DAEMONIZE
     79
     80        # Where to store the archived rrd's
     81        #
     82        ARCHIVE_PATH = cfg.get( 'DEFAULT', 'ARCHIVE_PATH' )
     83
     84        # Amount of hours to store in one single archived .rrd
     85        #
     86        ARCHIVE_HOURS_PER_RRD = cfg.getint( 'DEFAULT', 'ARCHIVE_HOURS_PER_RRD' )
     87
     88        # Specify debugging level here (only when _not_ DAEMONIZE)
     89        #
     90        # 11 = XML: metrics
     91        # 10 = XML: host, cluster, grid, ganglia
     92        # 9  = RRD activity, gmetad config parsing
     93        # 8  = RRD file activity
     94        # 6  = SQL
     95        # 1  = daemon threading
     96        # 0  = errors
     97        #
     98        # default: 0
     99        DEBUG_LEVEL = cfg.getint( 'DEFAULT', 'DEBUG_LEVEL' )
     100
     101        # Enable logging to syslog?
     102        #
     103        USE_SYSLOG = cfg.getboolean( 'DEFAULT', 'USE_SYSLOG' )
     104
     105        # What level msg'es should be logged to syslog?
     106        #
     107        # default: lvl 0 (errors)
     108        #
     109        SYSLOG_LEVEL = cfg.getint( 'DEFAULT', 'SYSLOG_LEVEL' )
     110
     111        # Which facility to use in syslog
     112        #
     113        # Syntax I.e.:
     114        #       LOG_KERN, LOG_USER, LOG_MAIL, LOG_DAEMON, LOG_AUTH, LOG_LPR,
     115        #       LOG_NEWS, LOG_UUCP, LOG_CRON and LOG_LOCAL0 to LOG_LOCAL7
     116        #
     117        try:
     118
     119                SYSLOG_FACILITY = eval( 'syslog.LOG_' + cfg.get( 'DEFAULT', 'SYSLOG_FACILITY' ) )
     120
     121        except AttributeError, detail:
     122
     123                print 'Unknown syslog facility'
     124                sys.exit( 1 )
     125
     126        # Where is the gmetad.conf located
     127        #
     128        GMETAD_CONF = cfg.get( 'DEFAULT', 'GMETAD_CONF' )
     129
     130        # Where to grab XML data from
     131        # Normally: local gmetad (port 8651)
     132        #
     133        # Syntax: <hostname>:<port>
     134        #
     135        ARCHIVE_XMLSOURCE = cfg.get( 'DEFAULT', 'ARCHIVE_XMLSOURCE' )
     136
     137        # List of data_source names to archive for
     138        #
     139        # Syntax: [ "<clustername>", "<clustername>" ]
     140        #
     141        ARCHIVE_DATASOURCES = getlist( cfg.get( 'DEFAULT', 'ARCHIVE_DATASOURCES' ) )
     142
     143        # NOTE: This can be a regexp or a string
     144        #
     145        ARCHIVE_EXCLUDE_METRICS = getlist( cfg.get( 'DEFAULT', 'ARCHIVE_EXCLUDE_METRICS' ) )
     146
     147        # Toga's SQL dbase to use
     148        #
     149        # Syntax: <hostname>/<database>
     150        #
     151        JOB_SQL_DBASE = cfg.get( 'DEFAULT', 'JOB_SQL_DBASE' )
     152
     153        # Wether or not to run as a daemon in background
     154        #
     155        DAEMONIZE = cfg.getboolean( 'DEFAULT', 'DAEMONIZE' )
     156
     157        return True
    95158
    96159###
     
    114177This is TOrque-GAnglia's data Daemon
    115178"""
     179
     180from types import *
     181
     182import DBClass
     183import xml.sax, xml.sax.handler, socket, string, os, os.path, time, thread, threading, random, re
    116184
    117185class DataSQLStore:
     
    438506        def __init__( self ):
    439507
    440                 self.ds = DataSQLStore( TOGA_SQL_DBASE.split( '/' )[0], TOGA_SQL_DBASE.split( '/' )[1] )
     508                self.ds = DataSQLStore( JOB_SQL_DBASE.split( '/' )[0], JOB_SQL_DBASE.split( '/' )[1] )
    441509                self.jobs_processed = [ ]
    442510                self.jobs_to_store = [ ]
     
    14521520        """Program startup"""
    14531521
     1522        if not processArgs( sys.argv[1:] ):
     1523                sys.exit( 1 )
     1524
    14541525        if( DAEMONIZE and USE_SYSLOG ):
    14551526                syslog.openlog( 'jobarchived', syslog.LOG_NOWAIT, SYSLOG_FACILITY )
Note: See TracChangeset for help on using the changeset viewer.