Changeset 471


Ignore:
Timestamp:
02/22/08 11:34:16 (16 years ago)
Author:
bastiaans
Message:

jobmond/jobmond.py:

  • added version, updated usage()
  • added more comments
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/jobmond/jobmond.py

    r451 r471  
    2222#
    2323
    24 import sys, getopt, ConfigParser
    25 import time, os, socket, string, re
    26 import xdrlib, socket, syslog
    27 import xml, xml.sax
     24import sys, getopt, ConfigParser, time, os, socket, string, re
     25import xdrlib, socket, syslog, xml, xml.sax
    2826from xml.sax import saxutils, make_parser
    2927from xml.sax import make_parser
    3028from xml.sax.handler import feature_namespaces
    3129
    32 def usage():
     30VERSION='0.3'
     31
     32def usage( ver ):
     33
     34        print 'jobmond %s' %VERSION
     35
     36        if ver:
     37                return 0
    3338
    3439        print
    35         print 'usage: jobmond [options]'
    36         print 'options:'
    37         print '      --config, -c      configuration file'
    38         print '      --pidfile, -p     pid file'
    39         print '      --help, -h        help'
     40        print 'Purpose:'
     41        print '  The Job Monitoring Daemon (jobmond) reports batch jobs information and statistics'
     42        print '  to Ganglia, which can be viewed with Job Monarch web frontend'
    4043        print
     44        print 'Usage:   jobmond [OPTIONS]'
     45        print
     46        print '  -c, --config=FILE      The configuration file to use (default: /etc/jobmond.conf)'
     47        print '  -p, --pidfile=FILE     Use pid file to store the process id'
     48        print '  -h, --help             Print help and exit'
     49        print '  -v, --version          Print version and exit'
     50        print
    4151
    4252def processArgs( args ):
    4353
    44         SHORT_L         = 'p:hc:'
    45         LONG_L          = [ 'help', 'config=', 'pidfile=' ]
     54        SHORT_L         = 'p:hvc:'
     55        LONG_L          = [ 'help', 'config=', 'pidfile=', 'version' ]
    4656
    4757        global PIDFILE
     
    7282                if opt in [ '--help', '-h' ]:
    7383 
    74                         usage()
     84                        usage( False )
     85                        sys.exit( 0 )
     86
     87                 if opt in [ '--version', '-v' ]:
     88
     89                        usage( True )
    7590                        sys.exit( 0 )
    7691
     
    331346                                                        incompatible = 1
    332347
     348                                                # Gmetric 3.0.1 >< 3.0.3 had a bug in the max metric length
     349                                                #
    333350                                                if version_patch < 3:
    334351
     
    798815                        myAttrs                         = { }
    799816
    800                         myAttrs[ 'name' ]                       = str( name )
     817                        myAttrs[ 'name' ]               = str( name )
    801818                        myAttrs[ 'queue' ]              = str( queue )
    802819                        myAttrs[ 'owner' ]              = str( owner )
     
    833850                queued_jobs     = 0
    834851
     852                # Count how many running/queued jobs we found
     853                #
    835854                for jobid, jobattrs in self.jobs.items():
    836855
     
    843862                                running_jobs += 1
    844863
     864                # Report running/queued jobs as seperate metric for a nice RRD graph
     865                #
    845866                self.dp.multicastGmetric( 'MONARCH-RJ', str( running_jobs ), 'uint32', 'jobs' )
    846867                self.dp.multicastGmetric( 'MONARCH-QJ', str( queued_jobs ), 'uint32', 'jobs' )
     
    850871                for jobid, jobattrs in self.jobs.items():
    851872
     873                        # Make gmetric values for each job: respect max gmetric value length
     874                        #
    852875                        gmetric_val             = self.compileGmetricVal( jobid, jobattrs )
    853876                        metric_increment        = 0
    854877
     878                        # If we have more job info than max gmetric value length allows, split it up
     879                        # amongst multiple metrics
     880                        #
    855881                        for val in gmetric_val:
    856882
    857883                                self.dp.multicastGmetric( 'MONARCH-JOB-' + jobid + '-' + str(metric_increment), val )
    858884
     885                                # Increase follow number if this jobinfo is split up amongst more than 1 gmetric
     886                                #
    859887                                metric_increment        = metric_increment + 1
    860888
     
    869897                for val_name, val_value in jobattrs.items():
    870898
     899                        # These are our own metric names, i.e.: status, start_timestamp, etc
     900                        #
    871901                        val_list_names_len      = len( string.join( val_list.keys() ) ) + len(val_list.keys())
     902
     903                        # These are their corresponding values
     904                        #
    872905                        val_list_vals_len       = len( string.join( val_list.values() ) ) + len(val_list.values())
    873906
     
    884917                                                node_str = node
    885918
     919                                        # Make sure if we add this new info, that the total metric's value length does not exceed METRIC_MAX_VAL_LEN
     920                                        #
    886921                                        if (val_list_names_len + len(val_name) ) + (val_list_vals_len + len(node_str) ) > METRIC_MAX_VAL_LEN:
    887922
     923                                                # It's too big, we need to make a new gmetric for the additional info
     924                                                #
    888925                                                val_list[ val_name ]    = node_str
    889926
     
    901938                        elif val_value != '':
    902939
     940                                # Make sure if we add this new info, that the total metric's value length does not exceed METRIC_MAX_VAL_LEN
     941                                #
    903942                                if (val_list_names_len + len(val_name) ) + (val_list_vals_len + len(str(val_value)) ) > METRIC_MAX_VAL_LEN:
    904943
     944                                        # It's too big, we need to make a new gmetric for the additional info
     945                                        #
    905946                                        gval_lists.append( val_list )
    906947
     
    915956                str_list        = [ ]
    916957
     958                # Now append the value names and values together, i.e.: stop_timestamp=value, etc
     959                #
    917960                for val_list in gval_lists:
    918961
     
    9721015                if self.prot == 'multicast':
    9731016
     1017                        # Set multicast options
     1018                        #
    9741019                        self.socket.setsockopt( socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 20 )
    9751020
     
    9801025        def checkHostProtocol( self, ip ):
    9811026
     1027                """Detect if a ip adress is a multicast address"""
     1028
    9821029                MULTICAST_ADDRESS_MIN   = ( "224", "0", "0", "0" )
    9831030                MULTICAST_ADDRESS_MAX   = ( "239", "255", "255", "255" )
     
    9951042                if len( units ) == 0:
    9961043                        units           = GMETRIC_DEFAULT_UNITS
     1044
    9971045                if len( typestr ) == 0:
    9981046                        typestr         = GMETRIC_DEFAULT_TYPE
     
    10481096def write_pidfile():
    10491097
    1050         # Write pidfile if PIDFILE exists
     1098        # Write pidfile if PIDFILE is set
     1099        #
    10511100        if PIDFILE:
    10521101
    10531102                pid     = os.getpid()
    10541103
    1055                 pidfile = open(PIDFILE, 'w')
     1104                pidfile = open( PIDFILE, 'w' )
    10561105
    10571106                pidfile.write( str( pid ) )
     
    10691118                sys.exit( 1 )
    10701119
     1120        # Load appropriate DataGatherer depending on which BATCH_API is set
     1121        # and any required modules for the Gatherer
     1122        #
    10711123        if BATCH_API == 'pbs':
    10721124
Note: See TracChangeset for help on using the changeset viewer.