Changeset 471 for trunk/jobmond
- Timestamp:
- 02/22/08 11:34:16 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/jobmond/jobmond.py
r451 r471 22 22 # 23 23 24 import sys, getopt, ConfigParser 25 import time, os, socket, string, re 26 import xdrlib, socket, syslog 27 import xml, xml.sax 24 import sys, getopt, ConfigParser, time, os, socket, string, re 25 import xdrlib, socket, syslog, xml, xml.sax 28 26 from xml.sax import saxutils, make_parser 29 27 from xml.sax import make_parser 30 28 from xml.sax.handler import feature_namespaces 31 29 32 def usage(): 30 VERSION='0.3' 31 32 def usage( ver ): 33 34 print 'jobmond %s' %VERSION 35 36 if ver: 37 return 0 33 38 34 39 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' 40 43 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 41 51 42 52 def processArgs( args ): 43 53 44 SHORT_L = 'p:h c:'45 LONG_L = [ 'help', 'config=', 'pidfile=' ]54 SHORT_L = 'p:hvc:' 55 LONG_L = [ 'help', 'config=', 'pidfile=', 'version' ] 46 56 47 57 global PIDFILE … … 72 82 if opt in [ '--help', '-h' ]: 73 83 74 usage() 84 usage( False ) 85 sys.exit( 0 ) 86 87 if opt in [ '--version', '-v' ]: 88 89 usage( True ) 75 90 sys.exit( 0 ) 76 91 … … 331 346 incompatible = 1 332 347 348 # Gmetric 3.0.1 >< 3.0.3 had a bug in the max metric length 349 # 333 350 if version_patch < 3: 334 351 … … 798 815 myAttrs = { } 799 816 800 myAttrs[ 'name' ] 817 myAttrs[ 'name' ] = str( name ) 801 818 myAttrs[ 'queue' ] = str( queue ) 802 819 myAttrs[ 'owner' ] = str( owner ) … … 833 850 queued_jobs = 0 834 851 852 # Count how many running/queued jobs we found 853 # 835 854 for jobid, jobattrs in self.jobs.items(): 836 855 … … 843 862 running_jobs += 1 844 863 864 # Report running/queued jobs as seperate metric for a nice RRD graph 865 # 845 866 self.dp.multicastGmetric( 'MONARCH-RJ', str( running_jobs ), 'uint32', 'jobs' ) 846 867 self.dp.multicastGmetric( 'MONARCH-QJ', str( queued_jobs ), 'uint32', 'jobs' ) … … 850 871 for jobid, jobattrs in self.jobs.items(): 851 872 873 # Make gmetric values for each job: respect max gmetric value length 874 # 852 875 gmetric_val = self.compileGmetricVal( jobid, jobattrs ) 853 876 metric_increment = 0 854 877 878 # If we have more job info than max gmetric value length allows, split it up 879 # amongst multiple metrics 880 # 855 881 for val in gmetric_val: 856 882 857 883 self.dp.multicastGmetric( 'MONARCH-JOB-' + jobid + '-' + str(metric_increment), val ) 858 884 885 # Increase follow number if this jobinfo is split up amongst more than 1 gmetric 886 # 859 887 metric_increment = metric_increment + 1 860 888 … … 869 897 for val_name, val_value in jobattrs.items(): 870 898 899 # These are our own metric names, i.e.: status, start_timestamp, etc 900 # 871 901 val_list_names_len = len( string.join( val_list.keys() ) ) + len(val_list.keys()) 902 903 # These are their corresponding values 904 # 872 905 val_list_vals_len = len( string.join( val_list.values() ) ) + len(val_list.values()) 873 906 … … 884 917 node_str = node 885 918 919 # Make sure if we add this new info, that the total metric's value length does not exceed METRIC_MAX_VAL_LEN 920 # 886 921 if (val_list_names_len + len(val_name) ) + (val_list_vals_len + len(node_str) ) > METRIC_MAX_VAL_LEN: 887 922 923 # It's too big, we need to make a new gmetric for the additional info 924 # 888 925 val_list[ val_name ] = node_str 889 926 … … 901 938 elif val_value != '': 902 939 940 # Make sure if we add this new info, that the total metric's value length does not exceed METRIC_MAX_VAL_LEN 941 # 903 942 if (val_list_names_len + len(val_name) ) + (val_list_vals_len + len(str(val_value)) ) > METRIC_MAX_VAL_LEN: 904 943 944 # It's too big, we need to make a new gmetric for the additional info 945 # 905 946 gval_lists.append( val_list ) 906 947 … … 915 956 str_list = [ ] 916 957 958 # Now append the value names and values together, i.e.: stop_timestamp=value, etc 959 # 917 960 for val_list in gval_lists: 918 961 … … 972 1015 if self.prot == 'multicast': 973 1016 1017 # Set multicast options 1018 # 974 1019 self.socket.setsockopt( socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 20 ) 975 1020 … … 980 1025 def checkHostProtocol( self, ip ): 981 1026 1027 """Detect if a ip adress is a multicast address""" 1028 982 1029 MULTICAST_ADDRESS_MIN = ( "224", "0", "0", "0" ) 983 1030 MULTICAST_ADDRESS_MAX = ( "239", "255", "255", "255" ) … … 995 1042 if len( units ) == 0: 996 1043 units = GMETRIC_DEFAULT_UNITS 1044 997 1045 if len( typestr ) == 0: 998 1046 typestr = GMETRIC_DEFAULT_TYPE … … 1048 1096 def write_pidfile(): 1049 1097 1050 # Write pidfile if PIDFILE exists 1098 # Write pidfile if PIDFILE is set 1099 # 1051 1100 if PIDFILE: 1052 1101 1053 1102 pid = os.getpid() 1054 1103 1055 pidfile = open( PIDFILE, 'w')1104 pidfile = open( PIDFILE, 'w' ) 1056 1105 1057 1106 pidfile.write( str( pid ) ) … … 1069 1118 sys.exit( 1 ) 1070 1119 1120 # Load appropriate DataGatherer depending on which BATCH_API is set 1121 # and any required modules for the Gatherer 1122 # 1071 1123 if BATCH_API == 'pbs': 1072 1124
Note: See TracChangeset
for help on using the changeset viewer.