Index: trunk/jobmond/jobmond.py
===================================================================
--- trunk/jobmond/jobmond.py	(revision 451)
+++ trunk/jobmond/jobmond.py	(revision 471)
@@ -22,26 +22,36 @@
 #
 
-import sys, getopt, ConfigParser
-import time, os, socket, string, re
-import xdrlib, socket, syslog
-import xml, xml.sax
+import sys, getopt, ConfigParser, time, os, socket, string, re
+import xdrlib, socket, syslog, xml, xml.sax
 from xml.sax import saxutils, make_parser
 from xml.sax import make_parser
 from xml.sax.handler import feature_namespaces
 
-def usage():
+VERSION='0.3'
+
+def usage( ver ):
+
+	print 'jobmond %s' %VERSION
+
+	if ver:
+		return 0
 
 	print
-	print 'usage: jobmond [options]'
-	print 'options:'
-	print '      --config, -c      configuration file'
-	print '      --pidfile, -p     pid file'
-	print '      --help, -h        help'
+	print 'Purpose:'
+	print '  The Job Monitoring Daemon (jobmond) reports batch jobs information and statistics'
+	print '  to Ganglia, which can be viewed with Job Monarch web frontend'
 	print
+	print 'Usage:	jobmond [OPTIONS]'
+	print
+	print '  -c, --config=FILE	The configuration file to use (default: /etc/jobmond.conf)'
+	print '  -p, --pidfile=FILE	Use pid file to store the process id'
+	print '  -h, --help		Print help and exit'
+	print '  -v, --version          Print version and exit'
+	print
 
 def processArgs( args ):
 
-	SHORT_L		= 'p:hc:'
-	LONG_L		= [ 'help', 'config=', 'pidfile=' ]
+	SHORT_L		= 'p:hvc:'
+	LONG_L		= [ 'help', 'config=', 'pidfile=', 'version' ]
 
 	global PIDFILE
@@ -72,5 +82,10 @@
 		if opt in [ '--help', '-h' ]:
  
-			usage()
+			usage( False )
+			sys.exit( 0 )
+
+		 if opt in [ '--version', '-v' ]:
+
+		 	usage( True )
 			sys.exit( 0 )
 
@@ -331,4 +346,6 @@
 							incompatible = 1
 
+						# Gmetric 3.0.1 >< 3.0.3 had a bug in the max metric length
+						#
 						if version_patch < 3:
 
@@ -798,5 +815,5 @@
 			myAttrs				= { }
 
-			myAttrs[ 'name' ]			= str( name )
+			myAttrs[ 'name' ]		= str( name )
 			myAttrs[ 'queue' ]		= str( queue )
 			myAttrs[ 'owner' ]		= str( owner )
@@ -833,4 +850,6 @@
 		queued_jobs	= 0
 
+		# Count how many running/queued jobs we found
+		#
 		for jobid, jobattrs in self.jobs.items():
 
@@ -843,4 +862,6 @@
 				running_jobs += 1
 
+		# Report running/queued jobs as seperate metric for a nice RRD graph
+		#
 		self.dp.multicastGmetric( 'MONARCH-RJ', str( running_jobs ), 'uint32', 'jobs' )
 		self.dp.multicastGmetric( 'MONARCH-QJ', str( queued_jobs ), 'uint32', 'jobs' )
@@ -850,11 +871,18 @@
 		for jobid, jobattrs in self.jobs.items():
 
+			# Make gmetric values for each job: respect max gmetric value length
+			#
 			gmetric_val		= self.compileGmetricVal( jobid, jobattrs )
 			metric_increment	= 0
 
+			# If we have more job info than max gmetric value length allows, split it up
+			# amongst multiple metrics
+			#
 			for val in gmetric_val:
 
 				self.dp.multicastGmetric( 'MONARCH-JOB-' + jobid + '-' + str(metric_increment), val )
 
+				# Increase follow number if this jobinfo is split up amongst more than 1 gmetric
+				#
 				metric_increment	= metric_increment + 1
 
@@ -869,5 +897,10 @@
 		for val_name, val_value in jobattrs.items():
 
+			# These are our own metric names, i.e.: status, start_timestamp, etc
+			#
 			val_list_names_len	= len( string.join( val_list.keys() ) ) + len(val_list.keys())
+
+			# These are their corresponding values
+			#
 			val_list_vals_len	= len( string.join( val_list.values() ) ) + len(val_list.values())
 
@@ -884,6 +917,10 @@
 						node_str = node
 
+					# Make sure if we add this new info, that the total metric's value length does not exceed METRIC_MAX_VAL_LEN
+					#
 					if (val_list_names_len + len(val_name) ) + (val_list_vals_len + len(node_str) ) > METRIC_MAX_VAL_LEN:
 
+						# It's too big, we need to make a new gmetric for the additional info
+						#
 						val_list[ val_name ]	= node_str
 
@@ -901,6 +938,10 @@
 			elif val_value != '':
 
+				# Make sure if we add this new info, that the total metric's value length does not exceed METRIC_MAX_VAL_LEN
+				#
 				if (val_list_names_len + len(val_name) ) + (val_list_vals_len + len(str(val_value)) ) > METRIC_MAX_VAL_LEN:
 
+					# It's too big, we need to make a new gmetric for the additional info
+					#
 					gval_lists.append( val_list )
 
@@ -915,4 +956,6 @@
 		str_list	= [ ]
 
+		# Now append the value names and values together, i.e.: stop_timestamp=value, etc
+		#
 		for val_list in gval_lists:
 
@@ -972,4 +1015,6 @@
 		if self.prot == 'multicast':
 
+			# Set multicast options
+			#
 			self.socket.setsockopt( socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 20 )
 
@@ -980,4 +1025,6 @@
 	def checkHostProtocol( self, ip ):
 
+		"""Detect if a ip adress is a multicast address"""
+
 		MULTICAST_ADDRESS_MIN   = ( "224", "0", "0", "0" )
 		MULTICAST_ADDRESS_MAX   = ( "239", "255", "255", "255" )
@@ -995,4 +1042,5 @@
 		if len( units ) == 0:
 			units		= GMETRIC_DEFAULT_UNITS
+
 		if len( typestr ) == 0:
 			typestr		= GMETRIC_DEFAULT_TYPE
@@ -1048,10 +1096,11 @@
 def write_pidfile():
 
-	# Write pidfile if PIDFILE exists
+	# Write pidfile if PIDFILE is set
+	#
 	if PIDFILE:
 
 		pid	= os.getpid()
 
-		pidfile	= open(PIDFILE, 'w')
+		pidfile	= open( PIDFILE, 'w' )
 
 		pidfile.write( str( pid ) )
@@ -1069,4 +1118,7 @@
 		sys.exit( 1 )
 
+	# Load appropriate DataGatherer depending on which BATCH_API is set
+	# and any required modules for the Gatherer
+	#
 	if BATCH_API == 'pbs':
 
