#!/bin/bash
#
# Wildard-plugin to monitor integer and floating point
# performance capabilities of a Condor pool.
#
# Author: Šarūnas Burdulis, sarunas(a)mail.saabnet.com, 2008
#
# Runs 'condor_status -server', 
# gets totals for MIPS and KFLOPS.
#
# Parameters understood:
#
#	config   (required)
# 	autoconf (optional - used by munin-config)
#	suggest  (optional - used by munin-config)
#
# Configurable variables:
#
# 	env.condor_status - Path to condor_status executable,
#		defaults to /usr/local/condor/bin/condor_status
# 	env.constraint - Condor ClassAds constraint(s), as they are
#		specified on the condor_status command line. For example, 
#		to monitor 64-bit Linux nodes only, set:
#		env.constraint 'arch=="x86_64" && opsys=="linux"'
#
# Magic markers - optional - used by installation scripts and
# munin-config:
#
#%# family=contrib
#%# capabilities=autoconf

# optional tag
TAG=`basename $0 | sed 's/^condor_ops_//g'`
if [ -z "$TAG" ]; then
    GRAPHTITLE="MIPS, MFLOPS"
else
    GRAPHTITLE="MIPS, MFLOPS (${TAG})"
fi

# env.condor_status
if [ ! -z "$condor_status" ]; then
    CS="$condor_status"
else
    CS="/usr/local/condor/bin/condor_status"
fi

# env.constraint
if [ ! -z "$constraint" ]; then
    CONS="-constraint ${constraint}"
else
    CONS=
fi
 
if [ "$1" = "autoconf" ]; then
    echo "no"
    exit 1
fi

if [ "$1" = "suggest" ]; then
    echo "For example: condor_ops_Linux-x86_64."
    exit 0
fi

if [ "$1" = "config" ]; then
	echo "graph_title "$GRAPHTITLE""
	echo "graph_order mips_cur mips_max mflops_cur mflops_max"
	echo "graph_args --lower-limit 0 "
	echo 'graph_vlabel MIPS, MFLOPS'
	echo 'graph_scale no'
	echo 'graph_info Shows MIPS and MFLOPS from condor_status.'
	echo 'graph_category htc'
	echo 'graph_period second'
	echo 'mips_cur.label MIPS claimed'
	echo 'mips_cur.draw LINE2'
	echo 'mips_cur.min 0'
	echo 'mips_cur.max 200000'
	echo 'mips_cur.type GAUGE'
	echo "mips_cur.info Total (millions of integer operations)/s in Claimed nodes" 
	echo 'mips_max.label MIPS max. possible'
	echo 'mips_max.draw LINE'
	echo 'mips_max.min 0'
	echo 'mips_max.max 200000'
	echo 'mips_max.type GAUGE'
	echo "mips_max.info Total capability in (millions of integer operations)/s" 
	echo 'mflops_cur.label MFLOPS claimed'
	echo 'mflops_cur.draw LINE2'
	echo 'mflops_cur.min 0'
	echo 'mflops_cur.max 200000'
	echo 'mflops_cur.type GAUGE'
	echo "mflops_cur.info Total (millions of floating point operations)/s in Claimed nodes" 
	echo 'mflops_max.label MFLOPS max. possible'
	echo 'mflops_max.draw LINE'
	echo 'mflops_max.min 0'
	echo 'mflops_max.max 200000'
	echo 'mflops_max.type GAUGE'
	echo "mflops_max.info Total capability in (millions of floating point operations)/s" 
	exit 0
fi

# max possible:
#condor_status -cons 'arch=="x86_64" && opsys=="linux"' -totals -server         
#      Machines Avail  Memory        Disk        MIPS      KFLOPS
# Total      30    30   48960   257925730      104576    31092042
eval $CS $CONS -totals -server | awk 'BEGIN { mipsc=0; mflopsc=0 } /Total/ {mips = $6; kflops = $7; mflops = int(kflops/1000) } END {print "mips_max.value " mips "\nmflops_max.value " mflops}'

# currently using:
#condor_status -cons 'arch=="x86_64" && opsys=="linux"' -totals -server -claimed
#       Machines         MIPS       KFLOPS   AvgLoadAvg
# Total       28       104576     29093286   0.960
eval $CS $CONS -totals -server -claimed | awk 'BEGIN { mipsc=0; mflopsc=0 } /Total/ { mipsc = $3; kflopsc = $4; mflopsc = int(kflopsc/1000) } END {print "mips_cur.value " mipsc "\nmflops_cur.value " mflopsc}'
