diff --git a/backup/netbackup_jobs/README b/backup/netbackup_jobs/README new file mode 100644 index 0000000..cb2b66c --- /dev/null +++ b/backup/netbackup_jobs/README @@ -0,0 +1,17 @@ +Gmetric script pulled from http://ganglia.info/gmetric + +If you are the author of the script, and have an updated version, please fork the repo and +submit a pull request. For additional information about the repository, please see the +README in the repository top-level. + +Author: Jordi Prats Catala (CESCA) + +Description: + +Measures the number of active and queued jobs on NetBackup + +Language: Bash + +Category: Backup Monitoring::NetBackup + +Dependencies: Netbackup, grep, wc diff --git a/backup/netbackup_jobs/netbackup_jobs.sh b/backup/netbackup_jobs/netbackup_jobs.sh new file mode 100755 index 0000000..71a4895 --- /dev/null +++ b/backup/netbackup_jobs/netbackup_jobs.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +### Author: Jordi Prats Catala - CESCA - 2007 +### License to use, modify, and distribute under the GPL +### http://www.gnu.org/licenses/gpl.txt + +ACTIVE=`/usr/openv/netbackup/bin/admincmd/bpdbjobs -noheader | grep Active | wc -l` +QUEUE=`/usr/openv/netbackup/bin/admincmd/bpdbjobs -noheader | grep -i Queued | wc -l` + +VALUEACTIVE=${ACTIVE## * } +/usr/bin/gmetric -t uint16 -n NB_active_jobs -v$VALUEACTIVE -u '#' + +VALUEQUEUE=${QUEUE## * } +/usr/bin/gmetric -t uint16 -n NB_queued_jobs -v$VALUEQUEUE -u '#' diff --git a/memcached/ganglia_memcached.pl b/cache/memcached.pl/ganglia_memcached.pl similarity index 100% rename from memcached/ganglia_memcached.pl rename to cache/memcached.pl/ganglia_memcached.pl diff --git a/cache/memcached.sh/README b/cache/memcached.sh/README new file mode 100644 index 0000000..dccf43a --- /dev/null +++ b/cache/memcached.sh/README @@ -0,0 +1,17 @@ +Gmetric script pulled from http://ganglia.info/gmetric + +If you are the author of the script, and have an updated version, please fork the repo and +submit a pull request. For additional information about the repository, please see the +README in the repository top-level. + +Author: Ben Hartshorne + +Description: + +Measures MemCache: num objects, bypets used, num connections, hit percentage + +Language: bash + +Category: Application::memcached + +Dependencies: memcached 1.1.13+ diff --git a/cache/memcached.sh/memcached.sh b/cache/memcached.sh/memcached.sh new file mode 100755 index 0000000..b6a1e7d --- /dev/null +++ b/cache/memcached.sh/memcached.sh @@ -0,0 +1,201 @@ +#!/bin/bash + +### $Id: mcd_gmetric.sh 16661 2006-11-07 00:56:33Z ben $ + +### This script queries a memcached server running +### on localhost and reports a few statistics to +### ganglia. +### It reports +### *mcd_curr_items - the number of objects stored +### *mcd_curr_bytes - current bytes used +### *mcd_curr_conns - current number of connections +### *mcd_hit_perc - hits / gets for current time duration +### (current hit percentage) +### For more description on any of these metrics, +### see the protocols.txt file in the MCD docs. + +### Copyright Simply Hired, Inc. 2006 +### License to use, modify, and distribute under the GPL +### http://www.gnu.org/licenses/gpl.txt + +VERSION=1.0 + +GMETRIC="/usr/bin/gmetric" +GMETRIC_ARGS="-c /etc/gmond.conf" +STATEFILE="/var/lib/ganglia/metrics/mcd.stats" +ERROR_NOTROOT="/tmp/mcd_gmetric_notroot" +ERROR_CANT_CONNECT="/tmp/mcd_gmetric_cant_connect" +ERROR_CREATE="/tmp/mcd_gmetric_create_statefile_failed" +ERROR_GETS_EMPTY="/tmp/mcd_gets_empty" + +MCD_CONF="/etc/sysconfig/memcached" + +# get system configuration +if [ -e ${MCD_CONF} ] +then + source ${MCD_CONF} + MCD_PORT=${PORT} +fi +MCD_PORT=${MCD_PORT:-11211} + +date=`date +%s` + +if [ $UID -ne 0 ] +then + if [ -e $ERROR_NOTROOT ] ; then exit 1; fi + echo "Error: this script must be run as root." + touch $ERROR_NOTROOT + exit 1 +fi +rm -f $ERROR_NOTROOT + +if [ "x$1" == "x-h" ] +then + echo "Usage: mcd_gmetric.sh [--clean]" + echo " --clean delete all tmp files" + exit 0 +fi + +if [ "x$1" == "x--clean" ] +then + rm -f $STATEFILE $ERROR_NOTROOT $ERROR_CANT_CONNECT $ERROR_CREATE + retval=$? + if [ $retval -ne 0 ] + then + echo "failed to clean up." + exit 1 + else + echo "All cleaned up." + exit 0 + fi +fi + +# if the GMETRIC program isn't installed, compain +if [ ! -e $GMETRIC ] +then + if [ -e $ERROR_GMETRIC ] ; then exit 1; fi + echo "" + echo "Error: GMETRIC doesn't seem to be installed." + echo "$GMETRIC doesn't exist." + echo "" + touch $ERROR_GMETRIC + exit 1 +fi + +# get current statistics +exec 3>&2 #turn off STDERR +exec 2>/dev/null +stats_array=(`echo "stats" | nc localhost $MCD_PORT`) +retval=$? +exec 2>&1 #turn on STDERR +exec 3>&- + +if [ $retval -ne 0 ] +then + if [ -e $ERROR_CANT_CONNECT ] ; then exit 1 ; fi + echo "I can't connect to mcd." + echo "Bummer. " + touch $ERROR_CANT_CONNECT + exit 1 +fi + +mcd_curr_items=`echo ${stats_array[23]}|tr -c -d [0-9]` #this tr thing is because there's a trailing ^M on the string from netcat that breaks bc. +mcd_curr_bytes=`echo ${stats_array[29]}|tr -c -d [0-9]` +mcd_curr_conns=`echo ${stats_array[32]}|tr -c -d [0-9]` +mcd_total_gets=`echo ${stats_array[41]}|tr -c -d [0-9]` +mcd_total_sets=`echo ${stats_array[44]}|tr -c -d [0-9]` +mcd_total_hits=`echo ${stats_array[47]}|tr -c -d [0-9]` + +if [ -z "$mcd_total_gets" ] +then +# this actually happens rather often for some reason, so I'm just going to fail silently. +# if [ -e $ERROR_GETS_EMPTY ] ; then exit 1 ; fi +# echo "" +# echo "ERROR: mcd_total_gets empty." +# echo "" + exit 1 +fi +rm -f $ERROR_GETS_EMPTY + + +# save and turn off /STDERR for the statefile tests +exec 3>&2 +exec 2>/dev/null + +# if the statefile doesn't exist, we either havn't +# run yet or there's something bigger wrong. +if [ ! -e $STATEFILE ] +then + if [ ! -d `dirname $STATEFILE` ] + then + mkdir -p `dirname $STATEFILE` + fi + echo "$date $mcd_curr_items $mcd_curr_bytes $mcd_curr_conns $mcd_total_gets $mcd_total_sets $mcd_total_hits" > $STATEFILE + if [ ! -e $STATEFILE ] + then + # if it didn't exist and we couldn't create + # it, we should just scream bloody murder and die. + # only scream once though... + if [ -e $ERROR_CREATE ] + then + exit 1 + fi + echo "" + echo "ERROR: couldn't create $STATEFILE" + echo "" + touch $ERROR_CREATE + exit 1 + fi + echo "Created statefile. Exitting." + exit 0 +fi + +# restore stderr +exec 2>&3 +exec 3>&- + +old_stats_array=(`cat $STATEFILE`) +old_date=${old_stats_array[0]} +old_mcd_curr_items=${old_stats_array[1]} +old_mcd_curr_bytes=${old_stats_array[2]} +old_mcd_curr_conns=${old_stats_array[3]} +old_mcd_total_gets=${old_stats_array[4]} +old_mcd_total_sets=${old_stats_array[5]} +old_mcd_total_hits=${old_stats_array[6]} + +echo "$date $mcd_curr_items $mcd_curr_bytes $mcd_curr_conns $mcd_total_gets $mcd_total_sets $mcd_total_hits" > $STATEFILE + +time_diff=$(($date - $old_date)) +mcd_total_gets_diff=$(($mcd_total_gets - $old_mcd_total_gets)) +mcd_total_sets_diff=$(($mcd_total_sets - $old_mcd_total_sets)) +mcd_total_hits_diff=$(($mcd_total_hits - $old_mcd_total_hits)) + +if [ $time_diff -eq 0 ] +then + if [ -e $ERROR_TIMEDIFF ] ; then exit 1 ; fi + echo "something is broken." + echo "time_diff is 0." + touch $ERROR_TIMEDIFF + exit 1 +fi + +# none of these numbers should be less than 1, but if they are, just send back 1. +if [ $mcd_total_gets_diff -le 1 ] ; then mcd_total_gets_diff=1 ; fi +if [ $mcd_total_sets_diff -le 1 ] ; then mcd_total_sets_diff=1 ; fi +if [ $mcd_total_hits_diff -le 1 ] ; then mcd_total_hits_diff=1 ; fi + +mcd_gets_per_sec=`echo "scale=3;${mcd_total_gets_diff}/${time_diff}"|bc` +mcd_sets_per_sec=`echo "scale=3;${mcd_total_sets_diff}/${time_diff}"|bc` +mcd_hits_per_sec=`echo "scale=3;${mcd_total_hits_diff}/${time_diff}"|bc` +mcd_hit_perc=`echo "scale=3; ${mcd_total_hits_diff} * 100 / ${mcd_total_gets_diff}" | bc` + + +$GMETRIC $GMETRIC_ARGS --name="mcd_seconds_measured" --value=${time_diff} --type=uint32 --units="secs" +$GMETRIC $GMETRIC_ARGS --name="mcd_items_cached" --value=${mcd_curr_items} --type=uint32 --units="items" +$GMETRIC $GMETRIC_ARGS --name="mcd_bytes_used" --value=${mcd_curr_bytes} --type=uint32 --units="bytes" +$GMETRIC $GMETRIC_ARGS --name="mcd_conns" --value=${mcd_curr_conns} --type=uint32 --units="connections" +$GMETRIC $GMETRIC_ARGS --name="mcd_gets" --value=${mcd_gets_per_sec} --type=float --units="gps" +$GMETRIC $GMETRIC_ARGS --name="mcd_sets" --value=${mcd_sets_per_sec} --type=float --units="sps" +$GMETRIC $GMETRIC_ARGS --name="mcd_cache_hits" --value=${mcd_hits_per_sec} --type=float --units="hps" +$GMETRIC $GMETRIC_ARGS --name="mcd_cache_hit%" --value=${mcd_hit_perc} --type=float --units="%" + diff --git a/database/mysql_replication/README b/database/mysql_replication/README new file mode 100644 index 0000000..0a08c09 --- /dev/null +++ b/database/mysql_replication/README @@ -0,0 +1,17 @@ +Gmetric script pulled from http://ganglia.info/gmetric + +If you are the author of the script, and have an updated version, please fork the repo and +submit a pull request. For additional information about the repository, please see the +README in the repository top-level. + +Author: C Viven Rajendra + +Description: + +gmetric to monitor mysql replication delay between master and slave + +Language: Python + +Category: MYSQL replication + +Dependencies: None diff --git a/database/mysql_replication/mysql_replication.py b/database/mysql_replication/mysql_replication.py new file mode 100755 index 0000000..bc02966 --- /dev/null +++ b/database/mysql_replication/mysql_replication.py @@ -0,0 +1,52 @@ +#!/usr/bin/python +############################################################### +# gmetric to monitor mysql replication delay between master and slave +# put this in a cronjob on the slave for every minute or 5 mins or however +# often you desire it to run, be sure to check the parameters +# given below +############################################################### +# REQs: python, gmetric +# DATE: 01 July 2008 +# C Viven Rajendra, vivenrajendra@gmail.com +############################################################### +import commands, os + +######################################### +# change these to the appropriate values +username = "root" +use_passwd = True # change this to False if you do not use a password to connect +password = "db" +## do not change below two default values unless you have done it on your machine +mcast_channel = '239.2.11.71' +mcast_port = 8649 +########################################## + + + +# mysql -u root -pdb -e 'show slave status\G' | grep 'Seconds_Behind_Master' + +## do not touch anything below unless you are sure of what you are doing ########## + +if __name__ == "__main__": + gmetricCommand_usingPassword = "mysql -u " + username + " -p" + password +" -e 'show slave status\G' | grep 'Seconds_Behind_Master'" + gmetricCommand_withoutPassword = "mysql -u " + username + " -e 'show slave status\G' | grep 'Seconds_Behind_Master'" + s = None + o = None + if use_passwd: + s,o = commands.getstatusoutput(gmetricCommand_usingPassword) + else: + s,o = commands.getstatusoutput(gmetricCommand_withoutPassword) + print "status", s + print "output", o + if o == "" or s!=0 or s==256: + print "Error : Probabaly, this is not a slave." + elif s==0: + o = o.split() + print o[0] + print o[1] + if o[1] == "NULL": + print "Error : Probabaly, slave cannot connect to master or try 'mysql>start slave'." + else: + gangliaMetric = "/usr/bin/gmetric --name=mysql_SecondsBehindMaster --value=" + str(o[1]) + " --type=uint8 --units=seconds --mcast_channel='" + mcast_channel +"' --mcast_port=" + str(mcast_port) + print gangliaMetric + res = os.system(gangliaMetric) diff --git a/mysql/ganglia_mysql_stats.pl b/database/mysql_stats/ganglia_mysql_stats.pl similarity index 100% rename from mysql/ganglia_mysql_stats.pl rename to database/mysql_stats/ganglia_mysql_stats.pl diff --git a/database/mysql_threads/README b/database/mysql_threads/README new file mode 100644 index 0000000..2cfebf2 --- /dev/null +++ b/database/mysql_threads/README @@ -0,0 +1,17 @@ +Gmetric script pulled from http://ganglia.info/gmetric + +If you are the author of the script, and have an updated version, please fork the repo and +submit a pull request. For additional information about the repository, please see the +README in the repository top-level. + +Author: Steve Traylen + +Description: + +Publishes the number of mysql threads ( active connections). + +Language: bash + +Category: Database :: MySQL :: Connections + +Dependencies: mysql diff --git a/database/mysql_threads/mysql_threads.sh b/database/mysql_threads/mysql_threads.sh new file mode 100755 index 0000000..fa17c22 --- /dev/null +++ b/database/mysql_threads/mysql_threads.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# Source a conf file read only by root to get the mysql USER +# we should use. +if [ ! -f /etc/mysql-threads-gmetric.conf ] ; then + echo "/etc/mysql-threads-gmetric.conf does not exist" + exit 1 +fi + +. /etc/mysql-threads-gmetric.conf + +# Check there is a gmond.conf file. +if [ ! -f /etc/gmond.conf ] ; then + echo "/etc/gmond.conf does not exist" + exit 1 +fi + +# Work out what multicast channel we are on (rather assumes there is only one space). +MCAST=`grep '^mcast_channel' /etc/gmond.conf | cut -d' ' -f 2` +PORT=`grep '^mcast_port' /etc/gmond.conf | cut -d' ' -f 2` +TTL=`grep '^mcast_ttl' /etc/gmond.conf | cut -d' ' -f 2` + +[ -z "$MCAST" ] && MCAST="239.2.11.70" +[ -z "$PORT" ] && PORT=8649 +[ -z "$TTL" ] && TTL=1 + + +STRING=`mysqladmin -u $USER status` +THREADS=`echo $STRING | sed 's/.*Threads: \([0-9]*\) .*/\1/'` + + +gmetric -tuint32 -c$MCAST -p$PORT -l$TTL -x180 -d300 -nmysql_threads -v$THREADS + + diff --git a/database/oracle_connections/README b/database/oracle_connections/README new file mode 100644 index 0000000..fc37a3d --- /dev/null +++ b/database/oracle_connections/README @@ -0,0 +1,17 @@ +Gmetric script pulled from http://ganglia.info/gmetric + +If you are the author of the script, and have an updated version, please fork the repo and +submit a pull request. For additional information about the repository, please see the +README in the repository top-level. + +Author: Craig Simpson + +Description: + +Reports number of Oracle Client Connections + +Language: sh + +Category: Network :: Oracle Connections + +Dependencies: ps netstat grep diff --git a/database/oracle_connections/oracle_connections.sh b/database/oracle_connections/oracle_connections.sh new file mode 100755 index 0000000..290a6dc --- /dev/null +++ b/database/oracle_connections/oracle_connections.sh @@ -0,0 +1,5 @@ +#!/bin/sh +CLIENT="/usr/bin/gmetric" +VALUE=`/bin/ps -ef |/bin/grep -c LOCAL` +$CLIENT -t uint16 -n ORACLE_Connections -v $VALUE + diff --git a/disk/ganglia_disk_stats.pl b/disk/diskio.pl/ganglia_disk_stats.pl similarity index 100% rename from disk/ganglia_disk_stats.pl rename to disk/diskio.pl/ganglia_disk_stats.pl diff --git a/disk/diskio.py/README b/disk/diskio.py/README new file mode 100644 index 0000000..5bdd537 --- /dev/null +++ b/disk/diskio.py/README @@ -0,0 +1,17 @@ +Gmetric script pulled from http://ganglia.info/gmetric + +If you are the author of the script, and have an updated version, please fork the repo and +submit a pull request. For additional information about the repository, please see the +README in the repository top-level. + +Author: Jason J. W. Williams + +Description: + +Measures Disk IO (Reads & Writes) & Sends That Back To gmetad + +Language: Python + +Category: Disk :: Performance + +Dependencies: python, PCP (Performance CoPilot) diff --git a/disk/diskio.py/diskio.py b/disk/diskio.py/diskio.py new file mode 100755 index 0000000..7964fce --- /dev/null +++ b/disk/diskio.py/diskio.py @@ -0,0 +1,58 @@ +#!/usr/bin/python +############################################################### +# gmetric For Disk IO +############################################################### +# REQs: pminfo, gmetric +# DATE: 21 December 2004 +# (C)2004 DigiTar, All Rights Reserved +############################################################### + +import os, re, time + +### Set Sampling Interval (in secs) +interval = 1 + +### Set PCP Config Parameters +cmdPminfo = "/usr/bin/pminfo -f " +reDiskIO = re.compile(r'"(\w+)"] value (\d+)\n') # RegEx To Compute Value + +### Set Ganglia Config Parameters +gangliaMetricType = "uint32" +gangliaMcastPort = "8649" +### NOTE: To add a new PCP disk metric, add the appropriate entry to each dictionary item of gangliaMetrics +### Each "vertical" column of the dictionary is a different metric entry group. +gangliaMetrics = { "pcpmetric": ["disk.dev.read", "disk.dev.write", "disk.dev.blkread", "disk.dev.blkwrite"], \ + "name": ["diskio_readbytes", "diskio_writebytes", "diskio_readblks", "diskio_writeblks"], \ + "unit": ["Kbytes/s", "Kbytes/s", "Blocks/s", "Blocks/s"], \ + "type": ["uint32", "uint32", "uint32", "uint32"]} +cmdGmetric = "/usr/bin/gmetric" + +### Zero Sample Lists +### NOTE: Make sure each sample array has as many (device) sub-arrays as there are pcpmetrics being sampled +### NOTE: Sub-arrays are artificially sized at 4 disk devices...if you have more disk devices than 4, increase this size. +lastSample = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]] +currSample = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]] + +### Read PCP Metrics +while(1): + # Interate Through Each PCP Disk IO Metric Desired + for x in range(0, len(gangliaMetrics["pcpmetric"])): + pminfoInput, pminfoOutput = os.popen2(cmdPminfo + gangliaMetrics["pcpmetric"][x], 't') + deviceLines = pminfoOutput.readlines() + pminfoInput.close() + pminfoOutput.close() + + # Output Metric Data For Each Device Returned By The PCP Metric + deviceIndex = 2 # Skip the first two lines in the buffer + while(deviceIndex < len(deviceLines)): + result = reDiskIO.search(deviceLines[deviceIndex]) + if(result): + currSample[x][deviceIndex] = int(result.group(2)) + cmdExec = cmdGmetric + " --name=" + gangliaMetrics["name"][x] + "_" + \ + result.group(1) + " --value=" + str((currSample[x][deviceIndex] - lastSample[x][deviceIndex])) + \ + " --type=" + gangliaMetrics["type"][x] + " --units=\"" + gangliaMetrics["unit"][x] + "\"" + \ + " --mcast_port=" + gangliaMcastPort + gmetricResult = os.system(cmdExec) + lastSample[x][deviceIndex] = currSample[x][deviceIndex] + deviceIndex = deviceIndex + 1 + time.sleep(interval) \ No newline at end of file diff --git a/disk/diskusage/README b/disk/diskusage/README new file mode 100644 index 0000000..cf42ebc --- /dev/null +++ b/disk/diskusage/README @@ -0,0 +1,17 @@ +Gmetric script pulled from http://ganglia.info/gmetric + +If you are the author of the script, and have an updated version, please fork the repo and +submit a pull request. For additional information about the repository, please see the +README in the repository top-level. + +Author: Ryan Sweet + +Description: + +report disk percent used for each local filesystem + +Language: perl + +Category: Disk::Usage + +Dependencies: df, perl>5.0 diff --git a/disk/diskusage/diskusage.pl b/disk/diskusage/diskusage.pl new file mode 100755 index 0000000..85636e6 --- /dev/null +++ b/disk/diskusage/diskusage.pl @@ -0,0 +1,21 @@ +#!/usr/bin/perl +# contributed by ryan sweet +my $gmetric="gmetric"; +my @df = `df -kl | grep -v "Filesystem"`; # RS: get info from df, leave out first line + +my $calcpercentused; +foreach (@df) # RS: for each line of df output +{ + my @line = split(/\s+/, $_); # RS: split the line on whitespace + my @reversed = reverse @line; # RS: reverse the order of @line - this is because IRIX df outputs different items than linux + my $size = $reversed[4]; # RS: the filesystem size is the fifth element in the reversed list + my $used = $reversed[3]; + # RS: calculated percent used (df gets it wrong sometimes) is (100(used))/size + $used = $used * 100; + $calcpercentused = int($used/$size); + my $fsname=$line[5]; # RS: get the mount point + $fsname =~ s/\//_/; # RS: replace / with _ + if ($fsname eq "_") { $fsname="_root"; } + # RS: send the data to gmond using gmetric + system("$gmetric --name=disk_percent_used$fsname --value=$calcpercentused --type=uint8 --units=\precent_free"); +} diff --git a/health/hplog_fanspeed/README b/health/hplog_fanspeed/README new file mode 100644 index 0000000..639eb77 --- /dev/null +++ b/health/hplog_fanspeed/README @@ -0,0 +1,17 @@ +Gmetric script pulled from http://ganglia.info/gmetric + +If you are the author of the script, and have an updated version, please fork the repo and +submit a pull request. For additional information about the repository, please see the +README in the repository top-level. + +Author: Jordi Prats Catala (CESCA) + +Description: + +Measures fan speed using HP's tools + +Language: Perl + +Category: Health Monitoring::Fan speed + +Dependencies: /sbin/hplog diff --git a/health/hplog_fanspeed/hplog_fanspeed.pl b/health/hplog_fanspeed/hplog_fanspeed.pl new file mode 100755 index 0000000..b59bd43 --- /dev/null +++ b/health/hplog_fanspeed/hplog_fanspeed.pl @@ -0,0 +1,36 @@ +#!/usr/bin/perl + +### Author: Jordi Prats Catala - CESCA - 2007 +### License to use, modify, and distribute under the GPL +### http://www.gnu.org/licenses/gpl.txt + +@HPLOGRES=`/sbin/hplog -f`; + +shift @HPLOGRES; +pop @HPLOGRES; + +for $line (@HPLOGRES) +{ + $line=~s/\(\s*(\d+)\)/ $1 /; + @values=split(/\s+/,$line); + @values=reverse @values; + + my $speed=shift @values; + $speed=~s/\W+//ig; + + shift @values; # desc. speed + shift @values; # redundant + shift @values; # status + + pop @values; #null + pop @values; #ID + + my $description=""; + + $description.=$_ for (reverse @values); + + #some cleaning + $description=~s/\W//g; + + system("/usr/bin/gmetric --name ".$description." --value ".$speed." --type uint16 --units rpm"); +} diff --git a/health/ipmi_temp/README b/health/ipmi_temp/README new file mode 100644 index 0000000..6c49213 --- /dev/null +++ b/health/ipmi_temp/README @@ -0,0 +1,17 @@ +Gmetric script pulled from http://ganglia.info/gmetric + +If you are the author of the script, and have an updated version, please fork the repo and +submit a pull request. For additional information about the repository, please see the +README in the repository top-level. + +Author: Dave Love + +Description: + +Temperature data via IPMI + +Language: shell + +Category: Health Monitoring::Temperature + +Dependencies: bash, ipmitool diff --git a/health/ipmi_temp/ipmi_temp.sh b/health/ipmi_temp/ipmi_temp.sh new file mode 100755 index 0000000..c8c9e4d --- /dev/null +++ b/health/ipmi_temp/ipmi_temp.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +# Sending temperature data to Ganglia via ipmitool sensor readings. +# Any args are passed as extra args to gmetric. + +# Dave Love / , 2008-07, public domain + +# Can be run from cron, for instance: +# # The multicast channel is currently different on each cluster, +# # due to Streamline. This is for Ganglia 2 config. +# */5 * * * * root /usr/local/sbin/gmetric-temp -c $(awk '/^mcast_channel / {print $2}' /etc/gmond.conf) + +# Avoid sending at the same time as all other nodes (modulo lack of +# synchronization of cron on each host and the slowness of ipmitool, +# which perhaps makes this irrelevant). +sleep $(($RANDOM / 1000)) + +# Sample output from `ipmitool sdr type Temperature': +# X4100: +# sys.tempfail | 03h | ok | 23.0 | Predictive Failure Deasserted +# mb.t_amb | 05h | ok | 7.0 | 31 degrees C +# fp.t_amb | 14h | ok | 12.0 | 25 degrees C +# pdb.t_amb | 1Bh | ok | 19.0 | 27 degrees C +# io.t_amb | 22h | ok | 15.0 | 26 degrees C +# p0.t_core | 29h | ok | 3.0 | 44 degrees C +# p1.t_core | 32h | ok | 3.1 | 43 degrees C +# X2200: +# CPU 0 Temp | 90h | ok | 3.1 | 44 degrees C +# CPU 1 Temp | 91h | ok | 3.2 | 48 degrees C +# Ambient Temp0 | 92h | ok | 7.6 | 33 degrees C +# Ambient Temp1 | 97h | ok | 7.6 | 44 degrees C +# Supermicro: +# CPU 1 | 00h | ok | 7.1 | 45 degrees C +# CPU 2 | 01h | ok | 7.1 | 47 degrees C +# System | 02h | ok | 7.1 | 33 degrees C + +ipmitool sdr type Temperature | + + # filter out non-readings, e.g. + # CPU 1 | 00h | ns | 7.1 | No Reading + grep 'degrees C' | + + # Initially collapsing multiple spaces helps the matching. + # Then pick out the sensor name and value, separating them with |. + # Temperatures always seem to be integer, but allow them to be float. + sed -e 's/ */ /g' \ + -e "s/\([^|][^|]*\) |.* \([0-9.][0-9.]*\) degrees C$/\1|\2/" | + + while IFS='|' read name value; do + # Ganglia (at least the ancient version we have) doesn't like + # spaces in names -- substitute underscores. + gmetric -n ${name// /_} -v $value -t float -u Celsius "$@" + done diff --git a/health/lm_sensors/README b/health/lm_sensors/README new file mode 100644 index 0000000..f0d8191 --- /dev/null +++ b/health/lm_sensors/README @@ -0,0 +1,17 @@ +Gmetric script pulled from http://ganglia.info/gmetric + +If you are the author of the script, and have an updated version, please fork the repo and +submit a pull request. For additional information about the repository, please see the +README in the repository top-level. + +Author: Mike Snitzer + +Description: + +lm_sensors bash script to report cpu temp and fan speed + +Language: Bash + +Category: Health Monitoring::CPU + +Dependencies: lm_sensors diff --git a/health/lm_sensors/lm_sensors.sh b/health/lm_sensors/lm_sensors.sh new file mode 100755 index 0000000..2d0503a --- /dev/null +++ b/health/lm_sensors/lm_sensors.sh @@ -0,0 +1,44 @@ +#!/bin/bash +# author: Mike Snitzer +# desc: used to make lm_sensors metrics available to ganglia + +# /etc/sysconfig/ganglia is used to specify INTERFACE +CONFIG=/etc/sysconfig/ganglia +[ -f $CONFIG ] && . $CONFIG + +#default to eth0 +if [ -z "$MCAST_IF" ]; then + MCAST_IF=eth0 +fi + +GMETRIC_BIN=/usr/bin/gmetric +# establish a base commandline +GMETRIC="$GMETRIC_BIN -i $MCAST_IF" + +SENSORS=/usr/bin/sensors + +# load the lm_sensors modules +module=`/sbin/lsmod | awk '{print $1}' | grep i2c-piix4` +if [ -z "$module" ]; then + /sbin/modprobe i2c-piix4 + # lm87 is for supermicro P3TDLE, replace when appropriate + /sbin/modprobe lm87 +fi + +# send cpu temps if gmond is running +`/sbin/service gmond status > /dev/null` +if [ $? -eq 0 ]; then + # send cpu temperatures + let count=0 + for temp in `${SENSORS} | grep emp | cut -b 13-16`; do + $GMETRIC -t float -n "cpu${count}_temp" -u "C" -v $temp + let count+=1 + done + + # send cpu fan speed + let count=0 + for fan in `${SENSORS} | grep fan | cut -b 9-14`; do + $GMETRIC -t uint32 -n "cpu${count}_fan" -u "RPM" -v $fan + let count+=1 + done +fi \ No newline at end of file diff --git a/hpc/pbs_jobs/README b/hpc/pbs_jobs/README new file mode 100644 index 0000000..3653853 --- /dev/null +++ b/hpc/pbs_jobs/README @@ -0,0 +1,17 @@ +Gmetric script pulled from http://ganglia.info/gmetric + +If you are the author of the script, and have an updated version, please fork the repo and +submit a pull request. For additional information about the repository, please see the +README in the repository top-level. + +Author: Matt Cuttler + +Description: + +Displays the number of running PBS batch jobs on a given compute node + +Language: Bourne Shell + +Category: Statistics :: Cluster + +Dependencies: PBS or OpenPBS diff --git a/hpc/pbs_jobs/pbs_jobs.sh b/hpc/pbs_jobs/pbs_jobs.sh new file mode 100755 index 0000000..8ca3c6b --- /dev/null +++ b/hpc/pbs_jobs/pbs_jobs.sh @@ -0,0 +1,17 @@ +#!/bin/sh +# +# Simple script which displays the number of running PBS batch +# jobs on a given compute node (usually something boring like +# zero, one or two for for SMP compute nodes). +# +# Contributed by Matt Cuttler + + +GMETRIC="/usr/bin/gmetric" +NODE=`/bin/hostname -s` + +# Might have to change path to reflect your PBS install.. +QSTAT=`/usr/local/PBS/bin/qstat -n | grep -i $NODE | wc -l` + +$GMETRIC --name PBSJOBS --type uint16 --units jobs --value $QSTAT + diff --git a/hpc/sge_jobs/README b/hpc/sge_jobs/README new file mode 100644 index 0000000..70f8d27 --- /dev/null +++ b/hpc/sge_jobs/README @@ -0,0 +1,17 @@ +Gmetric script pulled from http://ganglia.info/gmetric + +If you are the author of the script, and have an updated version, please fork the repo and +submit a pull request. For additional information about the repository, please see the +README in the repository top-level. + +Author: Jesse Becker + +Description: + +Reports number of jobs running, queued, and in error states. + +Language: Shell + +Category: Statistics :: Cluster + +Dependencies: awk diff --git a/hpc/sge_jobs/sge_jobs.sh b/hpc/sge_jobs/sge_jobs.sh new file mode 100755 index 0000000..69f7105 --- /dev/null +++ b/hpc/sge_jobs/sge_jobs.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +#adjust for the local environment +source /usr/local/sge/default/common/settings.sh + +qstat | awk ' + BEGIN { pending=running=error=0; } + /^[ 1-9][0-9]/ && ($5 ~ /^qw/) { pending++; } + /^[ 1-9][0-9]/ && ($5 ~ /[rRt]/) { running++; } + /^[ 1-9][0-9]/ && ($5 ~ /E/ ) { error++; } + END { + cmd="/usr/bin/gmetric --name sge_pending --value "pending" --type uint16"; + system(cmd); + cmd="/usr/bin/gmetric --name sge_running --value "running" --type uint16"; + system(cmd); + cmd="/usr/bin/gmetric --name sge_error --value "error" --type uint16"; + system(cmd); + #print "Pending="pending" Running="running" Errors="error; + }' + + +exit + +####################################################################### + + +QP=`grep ' qw ' /tmp/qstat.$$ | wc -l` +if [ $QP -ge 3 ]; then + QP=$(($QP-2)) +fi +/usr/bin/gmetric --name sge_pending --value $QP --type uint16 + +QP=`grep ' [rRt] ' /tmp/qstat.$$ | wc -l` +if [ $QP -ge 3 ]; then + QP=$(($QP-2)) +fi +/usr/bin/gmetric --name sge_running --value $QP --type uint16 + +QP=`grep ' E ' /tmp/qstat.$$ | wc -l` +if [ $QP -ge 3 ]; then + QP=$(($QP-2)) +fi +/usr/bin/gmetric --name sge_error --value $QP --type uint16 + diff --git a/http/apache_error/README b/http/apache_error/README new file mode 100644 index 0000000..f4d5322 --- /dev/null +++ b/http/apache_error/README @@ -0,0 +1,17 @@ +Gmetric script pulled from http://ganglia.info/gmetric + +If you are the author of the script, and have an updated version, please fork the repo and +submit a pull request. For additional information about the repository, please see the +README in the repository top-level. + +Author: Nicolas Marchildon + +Description: + +Reports the number of web server error response codes + +Language: Perl + +Category: Services::HTTP + +Dependencies: Getopt::Long diff --git a/http/apache_error/apache_error.pl b/http/apache_error/apache_error.pl new file mode 100755 index 0000000..cafd45e --- /dev/null +++ b/http/apache_error/apache_error.pl @@ -0,0 +1,122 @@ +#!/usr/bin/perl +# +# Feeds ganglia with web server error rate information. +# +# Can be called by Apache by setting up a special logger: +# +# LogFormat "%>s" status_only +# CustomLog "|/path/to/apache-logs-to-ganglia.pl -d 10" status_only +# +# +# Author: Nicolas Marchildon (nicolas@marchildon.net) +# Date: $Date: 2002/11/26 04:15:19 $ +# Revision: $Revision: 1.3 $ + + +use Getopt::Long; + +# Defaults +$DELAY = 20; +$METRIC = 'Apache'; + +# Parse command line +GetOptions( { d => \$DELAY, delay => \$DELAY, + m => \$METRIC, metric => \$METRIC + }, + 'd|delay=i', + 'p|port=i', + 'h|host=s', + 'm|metric=s'); + +# Validate command line +if ( length($DELAY) == 0 + || length($METRIC) == 0) { + print STDERR < 0) { + $percent500 = 100 * $count500 / $total; + } else { + $percent500 = 0; + } + broadcast $METRIC."ErrorPercentage", $percent500, "float", "%" ; + broadcast $METRIC."ErrorRate", $errorRate, "float", "requests" ; + broadcast $METRIC."RequestRate", $totalRate, "float", "requests" ; + $count500 = 0; + $countOther = 0; + $start = time; + print "ok.\n"; +} + +sub parse_line { + my $line = shift; + #print LOGS "Got: '$line'\n"; + #system("logger Got: '$line'"); + $_ = $line; + if (/5\d\d/) { + $count500++; + } else { + $countOther++; + } + lock $count500; + +} + +while (true) { + eval { + local $SIG{ALRM} = sub { die "alarm clock restart" }; + alarm $DELAY; + while (<>) { + parse_line $_; + } + alarm 0; + }; + if ($@ and $@ !~ /alarm clock restart/) { die } + report; +} diff --git a/haproxy/gmetric_haproxy.sh b/http/haproxy/gmetric_haproxy.sh similarity index 100% rename from haproxy/gmetric_haproxy.sh rename to http/haproxy/gmetric_haproxy.sh diff --git a/lighttpd/gmetric_lighttpd.sh b/http/lighttpd/gmetric_lighttpd.sh similarity index 100% rename from lighttpd/gmetric_lighttpd.sh rename to http/lighttpd/gmetric_lighttpd.sh diff --git a/mail/ganglia_powermta.php b/mail/powermta/ganglia_powermta.php similarity index 100% rename from mail/ganglia_powermta.php rename to mail/powermta/ganglia_powermta.php diff --git a/mail/qmail/README b/mail/qmail/README new file mode 100644 index 0000000..160d7ef --- /dev/null +++ b/mail/qmail/README @@ -0,0 +1,17 @@ +Gmetric script pulled from http://ganglia.info/gmetric + +If you are the author of the script, and have an updated version, please fork the repo and +submit a pull request. For additional information about the repository, please see the +README in the repository top-level. + +Author: Pablo Godel + +Description: + +Ganglia gmetric script to display local/remote queue message count. + +Language: PHP + +Category: Network::Email + +Dependencies: php, qmail diff --git a/mail/qmail/qmail.php b/mail/qmail/qmail.php new file mode 100755 index 0000000..bf20272 --- /dev/null +++ b/mail/qmail/qmail.php @@ -0,0 +1,69 @@ +#!/usr/bin/php +__toString(); + + if ( $qdir[0] != '.' ) + { + foreach( new DirectoryIterator($path.DIRECTORY_SEPARATOR.$qdir) as $file ) { + $fname = $file->__toString(); + if ( $fname[0] != '.') $total++; + } + + } + + } + + return $total; + + } + + public function countRemote() + { + $path = $this->queue_path.DIRECTORY_SEPARATOR.'remote'; + $remote = $this->countQueue( $path ); + + return $remote; + } + + public function countLocal() + { + + $path = $this->queue_path.DIRECTORY_SEPARATOR.'local'; + $local = $this->countQueue( $path ); + + return $local; + } + +} + +$q = new Qmail(); + +$r = $q->countRemote(); +$l = $q->countLocal(); + +exec( "/usr/bin/gmetric --name qmail_remote_queue --value $r --type int16 --units Messages" ); +exec( "/usr/bin/gmetric --name qmail_local_queue --value $l --type int16 --units Messages" ); \ No newline at end of file diff --git a/network/connections_list/README b/network/connections_list/README new file mode 100644 index 0000000..9612ebd --- /dev/null +++ b/network/connections_list/README @@ -0,0 +1,17 @@ +Gmetric script pulled from http://ganglia.info/gmetric + +If you are the author of the script, and have an updated version, please fork the repo and +submit a pull request. For additional information about the repository, please see the +README in the repository top-level. + +Author: Mirko Mariotti + +Description: + +List of connections established from or to a given port + +Language: Perl + +Category: Network :: usage + +Dependencies: none diff --git a/network/connections_list/connections_list.pl b/network/connections_list/connections_list.pl new file mode 100755 index 0000000..b143c41 --- /dev/null +++ b/network/connections_list/connections_list.pl @@ -0,0 +1,39 @@ +#!/usr/bin/perl + +$gmetric="/usr/local/ganglia/bin/gmetric"; +$iface="eth0"; +$port="22"; +$metricname="active_ssh"; + + +@connlist=`netstat -atn`; +$esta="none"; + +foreach $i(@connlist) +{ + if ($i=~/ESTABLISHED/) + { + $_=$i; + ($arg1,$arg2,$arg3,$from,$to,$state)=split(" "); + $_=$from; + ($fromaddr,$fromport)=split(":"); + $fromaddr=~s/\n//g; + $fromport=~s/\n//g; + $_=$to; + ($toaddr,$toport)=split(":"); + $toaddr=~s/\n//g; + $toport=~s/\n//g; + if ($toport eq $port ) + { + $esta=$esta."To:$toaddr "; + $esta=~s/none//; + } + if ($fromport eq $port ) + { + $esta=$esta."From:$toaddr "; + $esta=~s/none//; + } + } +} +#print "$gmetric -n$metricname -v\"$esta\" -tstring -i$iface"; +`$gmetric -n$metricname -v\"$esta\" -tstring -i$iface`; diff --git a/network/ib_perf/README b/network/ib_perf/README new file mode 100644 index 0000000..c2cd8a5 --- /dev/null +++ b/network/ib_perf/README @@ -0,0 +1,17 @@ +Gmetric script pulled from http://ganglia.info/gmetric + +If you are the author of the script, and have an updated version, please fork the repo and +submit a pull request. For additional information about the repository, please see the +README in the repository top-level. + +Author: Hristo Iliev + +Description: + +Measures average InfiniBand network performance + +Language: Python + +Category: Network :: InfiniBand + +Dependencies: OFED binaries diff --git a/network/ib_perf/ib_perf.py b/network/ib_perf/ib_perf.py new file mode 100755 index 0000000..4f70d2a --- /dev/null +++ b/network/ib_perf/ib_perf.py @@ -0,0 +1,105 @@ +#!/usr/bin/python +import os +import sys +import re +import time +from string import atoi + +# Adjust to match your site configuration +PIDFILE = '/var/run/ibstat.py.pid' +PERFQUERY = '/usr/bin/perfquery' +GMETRIC = '/opt/ganglia/lx-x86/bin/gmetric' + +r = re.compile('^(RcvBytes|XmtBytes)[^0-9]*([0-9]+)') +rr = re.compile('^(RcvPkts|XmtPkts)[^0-9]*([0-9]+)') + +def get_ib_stats(): + global r, rr + rxbytes = 0 + txbytes = 0 + rxpkts = 0 + txpkts = 0 + p = os.popen(PERFQUERY + " -r", 'r') + ll = p.readlines() + p.close() + for l in ll: + m = r.match(l) + if m: + if m.groups()[0] == 'RcvBytes': + rxbytes = atoi(m.groups()[1]) + else: + txbytes = atoi(m.groups()[1]) + m = rr.match(l) + if m: + if m.groups()[0] == 'RcvPkts': + rxpkts = atoi(m.groups()[1]) + else: + txpkts = atoi(m.groups()[1]) + return (rxbytes, txbytes, rxpkts, txpkts) + +def main(): + oldtime = time.time() + bytes = get_ib_stats() + rbytes = 0 + tbytes = 0 + rpkts = 0 + tpkts = 0 + while True: + time.sleep(1) + newtime = time.time() + bytes = get_ib_stats() + rbytes += bytes[0] + tbytes += bytes[1] + rpkts += bytes[2] + tpkts += bytes[3] + # 20 seconds averaging. Adjust if necessary. + if (newtime - oldtime) >= 20.0: + os.spawnl(os.P_WAIT, GMETRIC, 'gmetric', + '--name=ib_bytes_in', + '--value=%f' % (rbytes/(newtime - oldtime)), + '--type=float', + '--units=bytes/sec') + os.spawnl(os.P_WAIT, GMETRIC, 'gmetric', + '--name=ib_bytes_out', + '--value=%f' % (tbytes/(newtime - oldtime)), + '--type=float', + '--units=bytes/sec') + os.spawnl(os.P_WAIT, GMETRIC, 'gmetric', + '--name=ib_pkts_in', + '--value=%f' % (rpkts/(newtime - oldtime)), + '--type=float', + '--units=packets/sec') + os.spawnl(os.P_WAIT, GMETRIC, 'gmetric', + '--name=ib_pkts_out', + '--value=%f' % (tpkts/(newtime - oldtime)), + '--type=float', + '--units=packets/sec') + oldtime = newtime + rbytes = tbytes = 0 + rpkts = tpkts = 0 + +# Double-fork daemonization +if __name__ == "__main__": + try: + pid = os.fork() + if pid > 0: + sys.exit(0) + except OSError, e: + print >>sys.stderr, "fork #1 failed: %d (%s)" % (e.errno, e.stre +rror) + sys.exit(1) + + os.chdir("/") + os.setsid() + os.umask(0) + + try: + pid = os.fork() + if pid > 0: + open(PIDFILE, 'w').write("%d" % pid) + sys.exit(0) + except OSError, e: + print >>sys.stderr, "fork #2 failed: %d (%s)" % (e.errno, e.stre +rror) + + main() diff --git a/network/lvs_active_inactive_connections/README b/network/lvs_active_inactive_connections/README new file mode 100644 index 0000000..01a9a30 --- /dev/null +++ b/network/lvs_active_inactive_connections/README @@ -0,0 +1,17 @@ +Gmetric script pulled from http://ganglia.info/gmetric + +If you are the author of the script, and have an updated version, please fork the repo and +submit a pull request. For additional information about the repository, please see the +README in the repository top-level. + +Author: Frank Zwart + +Description: + +Dynamically monitor available LVS VIP\'s active & inactive connections + +Language: Bash + +Category: network::LVS + +Dependencies: none diff --git a/network/lvs_active_inactive_connections/lvs_active_inactive_connections.sh b/network/lvs_active_inactive_connections/lvs_active_inactive_connections.sh new file mode 100755 index 0000000..21a0051 --- /dev/null +++ b/network/lvs_active_inactive_connections/lvs_active_inactive_connections.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# Frank Zwart frank.kanariepietje.nl +# Script detects VIP\\\'s in use and collects active/inactive connections + + +`cat /proc/net/ip_vs > /tmp/ganglia_ipvs_tmp` +echo \\\"TCP\\\" >> /tmp/ganglia_ipvs_tmp + +ACTIVE_CONNECTIONS=0 +INACTIVE_CONNECTIONS=0 + +while read VAL1 VAL2 VAL3 VAL4 VAL5 VAL6 VAL7; do + + if [ \\\"${VAL1}\\\" = \\\"TCP\\\" ] ; then + if [[ ${PREVIOUS_WAS_REALSERVER} = \\\"YES\\\" ]] && [[ ${SERVICE} != \\\"\\\" ]];then + H1=`echo ${SERVICE} | cut -b1-4` + H2=`echo ${SERVICE} | cut -b5-8` + H3=`echo ${SERVICE} | cut -b10-13` + SERVICE=`printf \\\"VIP_%d.%d.%d.%d_port_%d\\\" 0x${H1%??} 0x${H1#??} 0x${H2%??} 0x${H2#??} 0x${H3}` + /usr/bin/gmetric --type uint32 --units ActiveConnections --name ${SERVICE}-Active --value ${ACTIVE_CONNECTIONS} + /usr/bin/gmetric --type uint32 --units InactiveConnections --name ${SERVICE}-Inactive --value ${INACTIVE_CONNECTIONS} + ACTIVE_CONNECTIONS=0 + INACTIVE_CONNECTIONS=0 + fi + SERVICE=${VAL2} + PROTOCOL=${VAL1} + elif [ \\\"${VAL3}\\\" = \\\"Route\\\" ]; then + ACTIVE_CONNECTIONS=`expr ${ACTIVE_CONNECTIONS} + ${VAL5}` + INACTIVE_CONNECTIONS=`expr ${INACTIVE_CONNECTIONS} + ${VAL6}` + PREVIOUS_WAS_REALSERVER=\\\"YES\\\" + fi +done < /tmp/ganglia_ipvs_tmp \ No newline at end of file diff --git a/network/lvs_connections/README b/network/lvs_connections/README new file mode 100644 index 0000000..31331f2 --- /dev/null +++ b/network/lvs_connections/README @@ -0,0 +1,17 @@ +Gmetric script pulled from http://ganglia.info/gmetric + +If you are the author of the script, and have an updated version, please fork the repo and +submit a pull request. For additional information about the repository, please see the +README in the repository top-level. + +Author: Lorn Kay + +Description: + +Monitor IPVS (LVS) Real Server connections + +Language: BASH + +Category: Network::LVS + +Dependencies: Working LVS Load Balancer. See: www.linuxvirtualserver.org diff --git a/network/lvs_connections/lvs_connections.sh b/network/lvs_connections/lvs_connections.sh new file mode 100755 index 0000000..1e00904 --- /dev/null +++ b/network/lvs_connections/lvs_connections.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# +# watch_lvs +# +# +# Simple script to report the number of established connections to +# each real server in an LVS cluster. See www.linuxvirtualserver.org. +# +# You must set the list of "servers" and the LVS "serviceport" before +# using this script. +# +servers="127.0.0.1 10.0.0.2 10.0.0.3 10.0.0.4 10.0.0.5 10.0.0.6" + +# Load balanced service in this example is telnet. +serviceport="23" + +for server in $servers +do + + totalconnections=`/sbin/ipvsadm -L -c -n | grep "$server:$serviceport" |grep ESTABLISHED | wc -l` + + # Pull out last octet of host IP for Ganglia report. + host=`/bin/echo $server | /bin/cut -d"." -f 4-` + + # Using a hack to set the hostname in the loopback case. + if [ "$host" = "1" ]; then + host="localhost" + fi + + /usr/bin/gmetric --name host_$host_port_$serviceport --value $totalconnections --type int16 --units Connections + +done diff --git a/network/lvs_connections_enhanced/README b/network/lvs_connections_enhanced/README new file mode 100644 index 0000000..396f65e --- /dev/null +++ b/network/lvs_connections_enhanced/README @@ -0,0 +1,17 @@ +Gmetric script pulled from http://ganglia.info/gmetric + +If you are the author of the script, and have an updated version, please fork the repo and +submit a pull request. For additional information about the repository, please see the +README in the repository top-level. + +Author: Jordi Prats Catala (CESCA) + +Description: + +Monitor IPVS (LVS) Real Server connections (extends Lorn Kay's script) + +Language: bash + +Category: Network::LVS + +Dependencies: LVS Load Balancer diff --git a/network/lvs_connections_enhanced/lvs_connections_enhanced.sh b/network/lvs_connections_enhanced/lvs_connections_enhanced.sh new file mode 100755 index 0000000..520b774 --- /dev/null +++ b/network/lvs_connections_enhanced/lvs_connections_enhanced.sh @@ -0,0 +1,39 @@ +#!/bin/bash +# +# watch_lvs +# +# +# Simple script to report the number of established connections to +# each real server in an LVS cluster. See www.linuxvirtualserver.org. +# +# You must set the list of "servers" and the LVS "serviceport" and +# "servicesports" before using this script. +# +# +# Original: Lorn Kay +# Modified: Jordi Prats Catala - CESCA - 2007 +# + +servers="192.168.11.1 192.168.11.2 192.168.11.121 192.168.11.122" +servicesports="8080 80 81 8089 2641" + +for serviceport in $servicesports + do + for server in $servers + do + + totalconnections=`/sbin/ipvsadm -L -c -n | grep "$server:$serviceport" |grep ESTABLISHED | wc -l` + + # Pull out last octet of host IP for Ganglia report. + host=`/bin/echo $server | /bin/cut -d"." -f 4-` + + # Using a hack to set the hostname in the loopback case. + if [ "$host" = "1" ]; then + host="localhost" + fi + + /usr/bin/gmetric --name host_${server}_port_${serviceport} --value $totalconnections --type uint16 --units Connections + + done + +done diff --git a/network/tcp_established/README b/network/tcp_established/README new file mode 100644 index 0000000..7099ef0 --- /dev/null +++ b/network/tcp_established/README @@ -0,0 +1,17 @@ +Gmetric script pulled from http://ganglia.info/gmetric + +If you are the author of the script, and have an updated version, please fork the repo and +submit a pull request. For additional information about the repository, please see the +README in the repository top-level. + +Author: Fredrik Steen + +Description: + +Get number of TCP_ESTABLISHED + +Language: Bourne Shell + +Category: Network + +Dependencies: egrep, netstat diff --git a/network/tcp_established/tcp_established.sh b/network/tcp_established/tcp_established.sh new file mode 100755 index 0000000..0e3bf8d --- /dev/null +++ b/network/tcp_established/tcp_established.sh @@ -0,0 +1,4 @@ +#!/bin/sh +CLIENT="/usr/local/bin/gmetric" +VALUE=`/bin/netstat -t -n|egrep "ESTABLISHED"|wc -l` +$CLIENT -t uint16 -n TCP_ESTABLISHED -v $VALUE diff --git a/network/tcp_established_time_wait/README b/network/tcp_established_time_wait/README new file mode 100644 index 0000000..76dd73e --- /dev/null +++ b/network/tcp_established_time_wait/README @@ -0,0 +1,17 @@ +Gmetric script pulled from http://ganglia.info/gmetric + +If you are the author of the script, and have an updated version, please fork the repo and +submit a pull request. For additional information about the repository, please see the +README in the repository top-level. + +Author: Lester Vecsey + +Description: + +Faster approach to getting established and time_wait TCP connection counts + +Language: Bourne Shell + +Category: Network TCP + +Dependencies: none diff --git a/network/tcp_established_time_wait/tcp_established_time_wait.sh b/network/tcp_established_time_wait/tcp_established_time_wait.sh new file mode 100755 index 0000000..a583ab4 --- /dev/null +++ b/network/tcp_established_time_wait/tcp_established_time_wait.sh @@ -0,0 +1,17 @@ + +#!/bin/sh + +CLIENT="/usr/bin/gmetric" + +TCP=(`egrep TCP /proc/net/sockstat`) + +inuse=${TCP[2]} +orphan=${TCP[4]} +time_wait=${TCP[6]} +alloc=${TCP[8]} +mem=${TCP[10]} + +let "established=$inuse-$orphan" + +$CLIENT -t uint16 -n tcp_established -v $established +exec $CLIENT -t uint16 -n tcp_time_wait -v $time_wait diff --git a/network/webpage_loadtime/README b/network/webpage_loadtime/README new file mode 100644 index 0000000..68ebeba --- /dev/null +++ b/network/webpage_loadtime/README @@ -0,0 +1,17 @@ +Gmetric script pulled from http://ganglia.info/gmetric + +If you are the author of the script, and have an updated version, please fork the repo and +submit a pull request. For additional information about the repository, please see the +README in the repository top-level. + +Author: C Viven Rajendra + +Description: + +gmetric to monitor how long it take for a web page to load textually + +Language: Python + +Category: Network::Latency + +Dependencies: urllib2 diff --git a/network/webpage_loadtime/webpage_loadtime.py b/network/webpage_loadtime/webpage_loadtime.py new file mode 100755 index 0000000..b5b8fa9 --- /dev/null +++ b/network/webpage_loadtime/webpage_loadtime.py @@ -0,0 +1,46 @@ +#!/usr/bin/python +############################################################### +# gmetric to monitor how long it take for a web page to load textually +# put this in a cronjob for every minute or 5 mins or however often +# you desire it to run, change the url to want to monitor below +############################################################### +# REQs: python, gmetric +# DATE: 01 July 2008 +# C Viven Rajendra, vivenrajendra@gmail.com +############################################################### +import time, os, urllib2 +import urllib2, gzip, StringIO + +######################################### +# change this to the appropriate values +url_to_monitor = "http://www.cse.iitb.ac.in" +## do not change below two default values unless you have done it on your machine +mcast_channel = '239.2.11.71' +mcast_port = 8649 +########################################## + + +def get(uri): + try: + request = urllib2.Request(uri) + request.add_header("Accept-encoding", "gzip") + usock = urllib2.urlopen(request) + data = usock.read() + if usock.headers.get('content-encoding', None) == 'gzip': + data = gzip.GzipFile(fileobj=StringIO.StringIO(data)).read() + return data + except Exception, e: + print e # your error handling here + +def wget_time(urli): + start_t = time.time() + get(urli) + end_t = time.time() + total_delay = end_t - start_t + gangliaMetric = "/usr/bin/gmetric --name=wget.index.page --value=" + str(total_delay) + " --type=double --units=seconds --mcast_channel='" + mcast_channel +"' --mcast_port=" + str(mcast_port)" + res = os.system(gangliaMetric) + + +if __name__ == "__main__": + wget_time(url_to_monitor) + \ No newline at end of file diff --git a/nfs/nfs_client_calls/README b/nfs/nfs_client_calls/README new file mode 100644 index 0000000..54cc7f3 --- /dev/null +++ b/nfs/nfs_client_calls/README @@ -0,0 +1,17 @@ +Gmetric script pulled from http://ganglia.info/gmetric + +If you are the author of the script, and have an updated version, please fork the repo and +submit a pull request. For additional information about the repository, please see the +README in the repository top-level. + +Author: Karl Kopper + +Description: + +Linux NFS client GETATTR, READ and WRITE calls. + +Language: BASH + +Category: Linux::NFS + +Dependencies: None diff --git a/nfs/nfs_client_calls/nfs_client_calls.sh b/nfs/nfs_client_calls/nfs_client_calls.sh new file mode 100755 index 0000000..5e5252f --- /dev/null +++ b/nfs/nfs_client_calls/nfs_client_calls.sh @@ -0,0 +1,54 @@ +#!/bin/bash +# +# Linux NFS Client statistics +# +# Report number of NFS client read, write and getattr calls since we were last called. +# +# (Use utility "nfsstat -c" to look at the same thing). +# +# Note: Uses temp files in /tmp +# + +# GETATTR +if [ -f /tmp/nfsclientgetattr ]; then + thisnfsgetattr=`cat /proc/net/rpc/nfs | tail -1 | awk '{printf "%s\n",$4}'` + lastnfsgetattr=`cat /tmp/nfsclientgetattr` + let "deltagetattr = thisnfsgetattr - lastnfsgetattr" + # echo "delta getattr $deltagetattr" + /usr/bin/gmetric -nnfsgetattr -v$deltagetattr -tuint16 -ucalls +fi + +# READ +if [ -f /tmp/nfsclientread ]; then + thisnfsread=`cat /proc/net/rpc/nfs | tail -1 | awk '{printf "%s\n",$9}'` + lastnfsread=`cat /tmp/nfsclientread` + let "deltaread = thisnfsread - lastnfsread" + # echo "delta read $deltaread" + /usr/bin/gmetric -nnfsread -v$deltaread -tuint16 -ucalls +fi + +# WRITE +if [ -f /tmp/nfsclientwrite ]; then + thisnfswrite=`cat /proc/net/rpc/nfs | tail -1 | awk '{printf "%s\n",$10} +'` + lastnfswrite=`cat /tmp/nfsclientwrite` + let "deltawrite = thisnfswrite - lastnfswrite" + # echo "delta write $deltawrite" + /usr/bin/gmetric -nnfswrite -v$deltawrite -tuint16 -ucalls +fi + +# NFS Quality Assurance RATIO (nfsqaratio) +# If this value shrinks too much then perhaps an application +# program change introduced excessive GETATTR calls into production. +if [ "$deltagetattr" -ne 0 ];then + let "nfsqaratio = (deltaread + deltawrite) / deltagetattr" + /usr/bin/gmetric -nnfsqaratio -v$nfsqaratio -tuint16 -ucalls +fi + + +# Update the old values on disk for the next time around. (We ignore +# the fact that they have probably already changed while we made this +# calculation). +cat /proc/net/rpc/nfs | tail -1 | awk '{printf "%s\n",$9}' > /tmp/nfsclientread +cat /proc/net/rpc/nfs | tail -1 | awk '{printf "%s\n",$10}' > /tmp/nfsclientwrite +cat /proc/net/rpc/nfs | tail -1 | awk '{printf "%s\n",$4}' > /tmp/nfsclientgetattr \ No newline at end of file diff --git a/nfs/nfs_stats/README b/nfs/nfs_stats/README new file mode 100644 index 0000000..1d42e23 --- /dev/null +++ b/nfs/nfs_stats/README @@ -0,0 +1,17 @@ +Gmetric script pulled from http://ganglia.info/gmetric + +If you are the author of the script, and have an updated version, please fork the repo and +submit a pull request. For additional information about the repository, please see the +README in the repository top-level. + +Author: Greg Wimpey + +Description: + +Linux NFS client and/or server GETATTR, READ, and WRITE calls (extends K. Kopper's script) + +Language: Perl + +Category: Linux :: NFS + +Dependencies: none diff --git a/nfs/nfs_stats/nfs_stats.pl b/nfs/nfs_stats/nfs_stats.pl new file mode 100755 index 0000000..7f93347 --- /dev/null +++ b/nfs/nfs_stats/nfs_stats.pl @@ -0,0 +1,124 @@ +#!/usr/bin/perl +# +# Calculate NFS client and server stats and send them to ganglia +# Inspired by Karl Kopper's client stats BASH script from +# http://ganglia.sourceforge.net/gmetric/view.php?id=26 +# +# Author: Greg Wimpey, Colorado School of Mines 20 May 2004 +# Email: gwimpey mines edu +# +# This script may be freely copied, distributed, or modified +# as long as authorship and copyright information is maintained. +# Copyright 2004 Colorado School of Mines +# +$nfsproc='/proc/net/rpc/nfs'; +$nfsdproc='/proc/net/rpc/nfsd'; +$tmpclient='/tmp/nfsclientstats'; +$tmpserver='/tmp/nfsserverstats'; +# +# initialize everything in case we can't read it +# (note that by initializing time to 0, we don't get spike on first run) +# +$oldcgetattr=0; +$oldcread=0; +$oldcwrite=0; +$oldctime=0; +$rcgetattr=0.0; +$rcread=0.0; +$rcwrite=0.0; +$nfsqaratio=-1.0; +$oldsgetattr=0; +$oldsread=0; +$oldswrite=0; +$oldstime=0; +$rsgetattr=0.0; +$rsread=0.0; +$rswrite=0.0; +$nfsdqaratio=-1.0; + +if ( -r $nfsproc ) { # we are a client + + open NFS,"<$nfsproc" || die "can't open $nfsproc for reading\n"; + $clienttime=time; + while () { + if(/^proc3/) { # change here if NFS version != 3 + @newstats=split; + $clientgetattr=$newstats[3]; + $clientread=$newstats[8]; + $clientwrite=$newstats[9]; + } + } + close NFS; + + if ( -r $tmpclient) { + open CLIENT,"<$tmpclient" || die "can't open $tmpclient for reading\n"; + $junk= || die "can't read stats from $tmpclient\n"; + @oldstats=split ' ',$junk; + close CLIENT; + $oldcgetattr=$oldstats[0]; + $oldcread=$oldstats[1]; + $oldcwrite=$oldstats[2]; + $oldctime=$oldstats[3]; + } + + open CLIENT,">$tmpclient" || die "can't open $tmpclient for writing\n"; + print CLIENT "$clientgetattr $clientread $clientwrite $clienttime\n"; + close CLIENT; + $ictime=1.0/($clienttime-$oldctime); + $rcgetattr=($clientgetattr-$oldcgetattr)*$ictime; + $rcread=($clientread-$oldcread)*$ictime; + $rcwrite=($clientwrite-$oldcwrite)*$ictime; + $nfsqaratio=$rcgetattr != 0 ? ($rcread+$rcwrite)/$rcgetattr : -1.0; +} + +if ( -r $nfsdproc ) { # we are a server + + open NFSD,"<$nfsdproc" || die "can't open $nfsdproc for reading\n"; + $servertime=time; + while () { + if(/^proc3/) { # change here if NFSD version != 3 + @newstats=split; + $servergetattr=$newstats[3]; + $serverread=$newstats[8]; + $serverwrite=$newstats[9]; + } + } + close NFSD; + + if ( -r $tmpserver) { + open SERVER,"<$tmpserver" || die "can't open $tmpserver for reading\n"; + $junk= || die "can't read stats from $tmpserver\n"; + @oldstats=split ' ',$junk; + close SERVER; + $oldsgetattr=$oldstats[0]; + $oldsread=$oldstats[1]; + $oldswrite=$oldstats[2]; + $oldstime=$oldstats[3]; + } + + open SERVER,">$tmpserver" || die "can't open $tmpserver for writing\n"; + print SERVER "$servergetattr $serverread $serverwrite $servertime\n"; + close SERVER; + $istime=1.0/($servertime-$oldstime); + $rsgetattr=($servergetattr-$oldsgetattr)*$istime; + $rsread=($serverread-$oldsread)*$istime; + $rswrite=($serverwrite-$oldswrite)*$istime; + $nfsdqaratio=$rsgetattr != 0 ? ($rsread+$rswrite)/$rsgetattr : -1.0; +} + +# +# so that all nodes are reporting, we send back defaults even if +# this node is not both client and server +# + +system("/usr/bin/gmetric -nnfsgetattr -v$rcgetattr -tfloat -ucalls/sec"); +system("/usr/bin/gmetric -nnfsread -v$rcread -tfloat -ucalls/sec"); +system("/usr/bin/gmetric -nnfswrite -v$rcwrite -tfloat -ucalls/sec"); +system("/usr/bin/gmetric -nnfsqaratio -v$nfsqaratio -tfloat -ucalls"); + +system("/usr/bin/gmetric -nnfsdgetattr -v$rsgetattr -tfloat -ucalls/sec"); +system("/usr/bin/gmetric -nnfsdread -v$rsread -tfloat -ucalls/sec"); +system("/usr/bin/gmetric -nnfsdwrite -v$rswrite -tfloat -ucalls/sec"); +system("/usr/bin/gmetric -nnfsdqaratio -v$nfsdqaratio -tfloat -ucalls"); + +exit 0; diff --git a/nfs/ganglia_nfs_stats.pl b/nfs/nfs_stats_vvuksan/ganglia_nfs_stats.pl similarity index 100% rename from nfs/ganglia_nfs_stats.pl rename to nfs/nfs_stats_vvuksan/ganglia_nfs_stats.pl diff --git a/power/apc_stats/README b/power/apc_stats/README new file mode 100644 index 0000000..c60ce8c --- /dev/null +++ b/power/apc_stats/README @@ -0,0 +1,17 @@ +Gmetric script pulled from http://ganglia.info/gmetric + +If you are the author of the script, and have an updated version, please fork the repo and +submit a pull request. For additional information about the repository, please see the +README in the repository top-level. + +Author: Greg Wimpey + +Description: + +Collects statistics from an APC UPS monitored by apcupsd + +Language: Perl + +Category: Statistics::Power + +Dependencies: apcupsd diff --git a/power/apc_stats/apc_stats.pl b/power/apc_stats/apc_stats.pl new file mode 100755 index 0000000..9481a20 --- /dev/null +++ b/power/apc_stats/apc_stats.pl @@ -0,0 +1,59 @@ +#!/usr/bin/perl +# +# Grab APC Uninterruptible Power Supply (UPS) stats and report to ganglia +# Requires that apcupsd and associated utilities (i.e., apcaccess) are +# installed. This script has been tested on a RedHat Linux 7.3 system +# running on an APC SmartUPS5000 power supply connected via serial port. +# You may find apcupsd at: http://www.apcupsd.com +# +# This script creates 3 metrics: +# ups_load: Load on UPS as percentage of capacity +# ups_batt_chg: Battery charge as percentage of capacity +# ups_time_left: UPS runtime left in minutes +# +# a typical /etc/cron.d line for this script would be: +# +# * * * * * root /usr/local/bin/apcups_metric > /dev/null 2>&1 +# +# Author: Greg Wimpey, Colorado School of Mines 26 May 2004 +# Email: gwimpey mines edu +# +# This script may be freely copied, distributed, or modified +# as long as authorship and copyright information is maintained. +# Copyright 2004 Colorado School of Mines +# +# + +$apcaccess='/sbin/apcaccess'; # location of apcaccess command +$statusarg='status'; # argument for apcaccess +$gmetric='/usr/bin/gmetric'; # ganglia gmetric command + +# initialize metrics +$loadpct=0.0; +$bcharge=0.0; +$timeleft=0.0; + +( -x $apcaccess ) || die "Can't execute $apcaccess\n"; + +open APC,"$apcaccess $statusarg |" || + die "Can't open pipe from $apcaccess $statusarg\n"; +while () { + @field = split ':'; + if ($field[0] =~ /LOADPCT/) { + ($loadpct,$junk) = split ' ',$field[1]; + } + elsif ($field[0] =~ /BCHARGE/) { + ($bcharge,$junk) = split ' ',$field[1]; + } + elsif ($field[0] =~ /TIMELEFT/) { + ($timeleft,$junk) = split ' ',$field[1]; + } +} +close APC; + +# send metrics to ganglia as floats +system("$gmetric -nups_load -v$loadpct -tfloat -u%"); +system("$gmetric -nups_batt_chg -v$bcharge -tfloat -u%"); +system("$gmetric -nups_time_left -v$timeleft -tfloat -umins"); + +exit 0; diff --git a/system/filehandles_inuse_2.4_kernel/README b/system/filehandles_inuse_2.4_kernel/README new file mode 100644 index 0000000..dc84ad1 --- /dev/null +++ b/system/filehandles_inuse_2.4_kernel/README @@ -0,0 +1,17 @@ +Gmetric script pulled from http://ganglia.info/gmetric + +If you are the author of the script, and have an updated version, please fork the repo and +submit a pull request. For additional information about the repository, please see the +README in the repository top-level. + +Author: Lester Vecsey + +Description: + +file descriptors in use + +Language: Bourne Shell + +Category: Filesystem :: fd's in use + +Dependencies: Linux 2.4.x /proc diff --git a/system/filehandles_inuse_2.4_kernel/filehandles_inuse_2.4_kernel.sh b/system/filehandles_inuse_2.4_kernel/filehandles_inuse_2.4_kernel.sh new file mode 100755 index 0000000..ee50d5d --- /dev/null +++ b/system/filehandles_inuse_2.4_kernel/filehandles_inuse_2.4_kernel.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +CLIENT="/usr/bin/gmetric" + +FDS=(`< /proc/sys/fs/file-nr`) + +system_reserved=${FDS[0]} +current_used=${FDS[1]} +fd_limit=${FDS[2]} + +#echo $system_reserved +#echo $current_used +#echo $fd_limit + +exec $CLIENT -t uint16 -n fd_inuse -v $current_used diff --git a/system/io_user_load/README b/system/io_user_load/README new file mode 100644 index 0000000..ee8bfdc --- /dev/null +++ b/system/io_user_load/README @@ -0,0 +1,17 @@ +Gmetric script pulled from http://ganglia.info/gmetric + +If you are the author of the script, and have an updated version, please fork the repo and +submit a pull request. For additional information about the repository, please see the +README in the repository top-level. + +Author: Andrei Chevel + +Description: + +The script measures a range of values (eth0 in and out, scsi in and out, etc.) + +Language: bash + +Category: I/O usage + user load + +Dependencies: none diff --git a/system/io_user_load/io_user_load.sh b/system/io_user_load/io_user_load.sh new file mode 100755 index 0000000..dae6a44 --- /dev/null +++ b/system/io_user_load/io_user_load.sh @@ -0,0 +1,20 @@ +#!/usr/local/bin/bash +TOP=/usr/bin/top +AWK=/bin/awk +GMETRIC=/usr/bin/gmetric + +$TOP -ibn 1 | $AWK /COMMAND/,/++++++++++/ | head -2 | tail -1 > /tmp/t$$ +$GMETRIC --name UserName --value `$AWK '{print($2)}' /tmp/t$$` --type string --units 'name' +$GMETRIC --name UserProg --value `$AWK '{print($12)}' /tmp/t$$` --type string --units 'name' +$GMETRIC --name UserCPU --value `$AWK '{print($9)}' /tmp/t$$` --type float --units '%' +$GMETRIC --name UserTime --value `$AWK '{print($11)}' /tmp/t$$` --type string --units 'min:sec' + +$GMETRIC --name eth0_out --value ` grep eth0 /proc/net/dev | awk -F\: '{print($2)}' | awk '{print($9)}' ` --type uint32 --units 'bytes' +$GMETRIC --name eth1_out --value ` grep eth1 /proc/net/dev | awk -F\: '{print($2)}' | awk '{print($9)}' ` --type uint32 --units 'bytes' + + +$GMETRIC --name eth0_in --value ` grep eth0 /proc/net/dev | awk -F\: '{print($2)}' | awk '{print($1)}' ` --type uint32 --units 'bytes' +$GMETRIC --name eth1_in --value ` grep eth1 /proc/net/dev | awk -F\: '{print($2)}' | awk '{print($1)}' ` --type uint32 --units 'bytes' + +$GMETRIC --name SCSI0read --value ` grep 'Total transfers' /proc/scsi/aic7xxx/0 | awk -F\( '{print($2)}' | awk '{print($1)}' ` --type uint32 --units 'qnty' +$GMETRIC --name SCSI0writ --value ` grep 'Total transfers' /proc/scsi/aic7xxx/0 | awk -F\( '{print($2)}' | awk '{print($4)}' ` --type uint32 --units 'qnty' diff --git a/system/logged_in_users/README b/system/logged_in_users/README new file mode 100644 index 0000000..8c85def --- /dev/null +++ b/system/logged_in_users/README @@ -0,0 +1,17 @@ +Gmetric script pulled from http://ganglia.info/gmetric + +If you are the author of the script, and have an updated version, please fork the repo and +submit a pull request. For additional information about the repository, please see the +README in the repository top-level. + +Author: Miles Davis + +Description: + +Reports the number of users logged in (from 'who -q') + +Language: bash + +Category: Resource :: Users + +Dependencies: none diff --git a/system/logged_in_users/logged_in_users.sh b/system/logged_in_users/logged_in_users.sh new file mode 100755 index 0000000..a5f4f19 --- /dev/null +++ b/system/logged_in_users/logged_in_users.sh @@ -0,0 +1,18 @@ +#!/bin/sh +# +# Report number of users logged in. Sorry it's not more exciting. :) +# +# Miles Davis +# +CLIENT="/usr/bin/gmetric" + +# Last line in output of "who -q" is in the form "^# users=N$", so just +# grab the last line & split on the equals sign. This works on Linux, IRIX, +# Solaris, & probably most other un*xes. +USERS=`who -q | tail -1 | cut -d = -f 2` + +#echo $USERS + +$CLIENT -t uint16 -n users -v $USERS + +exit $? \ No newline at end of file diff --git a/system/per_user_stats/README b/system/per_user_stats/README new file mode 100644 index 0000000..a8cb739 --- /dev/null +++ b/system/per_user_stats/README @@ -0,0 +1,17 @@ +Gmetric script pulled from http://ganglia.info/gmetric + +If you are the author of the script, and have an updated version, please fork the repo and +submit a pull request. For additional information about the repository, please see the +README in the repository top-level. + +Author: Ryan Sweet + +Description: + +reports per user stats for mem/cpu/mum_procs from ps output + +Language: perl + +Category: Statistics::PerUser + +Dependencies: perl, ps diff --git a/system/per_user_stats/per_user_stats.pl b/system/per_user_stats/per_user_stats.pl new file mode 100755 index 0000000..d45903f --- /dev/null +++ b/system/per_user_stats/per_user_stats.pl @@ -0,0 +1,64 @@ +#!/usr/bin/perl +# +# a simple script to report some per user stats to ganglia +# contributed by Ryan Sweet +# +my $gmetric="gmetric"; +my $users,@ps; + +# RS: get ps aux output and skip the first line +# RS: ps has different behaviour on IRIX vs Linux +my $uname=`uname`; +if ( $uname =~ /Linux/ ) +{ + @ps=`ps aux| grep -v USER`; +}else{ + # RS: pcpu is repeated because this ps doesn't give %mem stats + @ps=`ps -eo user,pid,pcpu,pcpu,vsz,rss,tty,state,stime,time,comm`; +} + + +# RS: iterate over each line of the ps output +foreach my $line (@ps) +{ + # RS: eat any leading whitespace + $line =~ s/^\s+//; + + # RS: split the line on whitespace, assigning vars + my ($user,$pid,$cpu,$mem,$vsz,$rss,$tty,$stat,$start,$time,$command,@args) = split(/\s+/, $line); + + # RS: populate the hash %users with references to the cumulative cpu,memz,time vars + $users->{$user}{cpu}+=$cpu; + $users->{$user}{mem}+=$mem; + $users->{$user}{vsz}+=$vsz; + # RS: calculate the time in seconds rather than min:sec + my ($min,$sec)=split(/:/,$time); + $sec+=($min*60); + $users->{$user}{time}+=$time; + $users->{$user}{procs}+=1; # total number of procs per user + +} + +# RS: for each user that was found, send the stats to gmond +foreach my $user (keys %$users) +{ + # cpu total + system("gmetric --name=cpu_percent_$user --value=$users->{$user}{cpu} --type=float --units=\%cpu"); + + # mem total (only reported on linux) + if ( $uname =~ /Linux/ ) + { + system("gmetric --name=mem_percent_$user --value=$users->{$user}{mem} --type=float --units=\%mem"); + } + + # vsz total + system("gmetric --name=mem_vsz_kb_$user --value=$users->{$user}{vsz} --type=float --units=kilobytes"); + + # cputime total + system("gmetric --name=cpu_total_time_sec_$user --value=$users->{$user}{time} --type=float --units=seconds"); + + # processes total + system("gmetric --name=procs_total_$user --value=$users->{$user}{procs} --type=float --units=processes"); + + +} diff --git a/system/per_user_stats_ustat/README b/system/per_user_stats_ustat/README new file mode 100644 index 0000000..9bf77ab --- /dev/null +++ b/system/per_user_stats_ustat/README @@ -0,0 +1,17 @@ +Gmetric script pulled from http://ganglia.info/gmetric + +If you are the author of the script, and have an updated version, please fork the repo and +submit a pull request. For additional information about the repository, please see the +README in the repository top-level. + +Author: Alexander Sudakov + +Description: + +reports per user stats for "cpu", "mem" , "rss" , "num_procs", "time" using USTAT + +Language: Perl + +Category: Statistics::PerUser + +Dependencies: none diff --git a/system/per_user_stats_ustat/per_user_stats_ustat.pl b/system/per_user_stats_ustat/per_user_stats_ustat.pl new file mode 100755 index 0000000..19705e4 --- /dev/null +++ b/system/per_user_stats_ustat/per_user_stats_ustat.pl @@ -0,0 +1,366 @@ +#!/usr/bin/perl + +# effective tools to view users activity on each node + +# V 1.0 (c) Alexander Sudakov +# saa@univ.kiev.ua +# scriprt collect such metrics as : +# cpu -cpu % used by user +# mem -memory % used by user +# rss -rss +# time -time +# procs -number of process + +# and something else but it needs to be correctly uncomented and cheked !!!! + + + +# V 1.1 (c) orest +# Boyko Nikolay +# orest@univ.kiev.ua +# litTle fix this system proceses (demons ) - they are reported +# as one virtual user "__SYSTEM__" + +# implemented on LINUX 2.2.x REDHAT this mosix kernel patch + +$GMETRIC="/usr/bin/gmetric "; + +#$PORT=8649; +#$MCHANNEL="239.2.17.71"; +#$GMETRIC"="/usr/bin/gmetric --mcast_port=$PORT --mcast_channel=\"$MCHANNEL\" "; + +use FileHandle; + use Fcntl ':flock'; # import LOCK_* constants +$UPDATE_TIME=1; +my $pcp = new FileHandle; +$| = 1; +#@user_params = ("nproc","cpu_time", "real_time", "nproc_pcnt", +# "cpu_time_pcnt", "real_time_pcnt", "ksec"); +$lock_file="/var/lock/.stat.pl"; + +# IF you want to see metrics "rss" , "time", "procs" just uncomment them here and "some" other code in script +@user_params = ("cpu", + "mem" +# ,"rss", +# "time", +# "procs" + ); +@proc_params = (); + +@host_params = ( +# "3_3V", +# "5V", +# "12V", +# "fan1", +# "fan2", + "CPU1_temp", + "CPU2_temp", + "Temp" +# "swap_in", + # "swap_out", + # "disk_bin", + # "disk_bout", + # "sys_ints", + # "sys_contsw" +); +%param_units = ( + "nproc_pcnt" => "%", + "cpu_time_pcnt" => "%", + "real_time_pcnt"=> "%", + "ksec" => "", + "cur_proc" => "", + "3_3V" => "V", + "5V" => "V", + "12V" => "V", + "fan1" => "RPM", + "fan2" => "RPM", + "CPU1_temp" => "C", + "CPU2_temp" => "C", + "Temp" => "C", + "swap_in" => "KByts/c", + "swap_out" => "KByts/c", + "disk_bin" => "blocks/c", + "disk_bout" => "blocks/c", + "sys_ints" => "blocks/c", + "sys_contsw" => "blocks/c", + "cpu" => "%", + "mem" => "%", + "time" => "sec", + "rss" => "Byts", + "procs" => "" +); + +%param_types = ( + "nproc_pcnt" => "float", + "cpu_time_pcnt" => "float", + "real_time_pcnt"=> "float", + "ksec" => "float", + "cur_proc" => "uint32", + "3_3V" => "float", + "5V" => "float", + "12V" => "float", + "fan1" => "uint32", + "fan2" => "uint32", + "CPU1_temp" => "float", + "CPU2_temp" => "float", + "Temp" => "float", + "swap_in" => "uint32", + "swap_out" => "uint32", + "disk_bin" => "uint32", + "disk_bout" => "uint32", + "sys_ints" => "uint32", + "sys_contsw" => "uint32", + "cpu" => "float", + "mem" => "float", + "time" => "uint32", + "rss" => "uint32", + "procs" => "uint32" +); + +%user_info=(); +sub get_users (){ + if($pid_ul=open (USTAT,"-|")){ + while (){ + ($user, $passwd, $uid)=split(/:/); + #print "$user"; + #print "$user $uid\n"; + foreach $param (@user_params){ + #if($uid < 1000 ){ + # $user_info{"__SYSTEM__"}{$param}=0; + #delete ($user_info{"__SYSTEM__"}{$param}); + #} else { + $user_info{$user}{$param}=0; + #} + } + #$user_info{"__SYSTEM__"}{$param}=0; + + } + close(USTAT); + foreach $param (@user_params){ + delete($user_info{"__SYSTEM__"}{$param}); + } + } else { + print "cannot fork: $!" unless defined $pid_ul; + exec("ypcat passwd"); + } +} +# +# +# +sub update_stats(){ + foreach my $usr (keys %user_info){ + foreach $param (@user_params){ + #print "$usr $param $user_info{$usr}{$param}\n"; + my $name="user--$usr--$param"; + #print ">>> $name\n"; + system("$GMETRIC --name=$name --type=$param_types{$param} --value=$user_info{$usr}{$param} --units=$param_units{$param} -i eth0 -l 1"); + } + } + foreach my $param (@host_params){ + system("$GMETRIC --name=$param --type=$param_types{$param} --value=$host_info{$param} --units=$param_units{$param} -i eth0 -l 1"); + } + +} +# +# +# +sub get_user_procs (){ + #my %tmp_uproc = (); + #foreach $user (keys %user_info){ + # print "$user\n"; + #} + + my @tup = `/bin/mps haux`; + foreach my $ln (@tup){ + $ln =~ s/^\s+//; + + # RS: split the line on whitespace, assigning vars + my ($user,$pid,$cpu,$mem,$vsz,$rss,$tty,$node,$stat,$start,$time,$command,@args) = split(/\s+/, $ln); + if(!exists $user_info{$user}){ + # print "$user\n"; + $user="__SYSTEM__"; + } + #print "$user\n"; + $user_info{$user}{"cpu"}+=$cpu; + $user_info{$user}{"mem"}+=$mem; + + +# $user_info{$user}{"rss"}+=($rss*1024); + # RS: calculate the time in seconds rather than min:sec +# my ($min,$sec)=split(/:/,$time); +# $sec+=($min*60); +# $user_info{$user}{"time"}+=$time; +# $user_info{$user}{"procs"}+=1; # total number of procs per user + + } + #foreach $user (keys %user_info){ + # print "$user\n"; + #} +} +# +# +# +sub get_sensors(){ + my $sd = `/usr/local/bin/sensors 2>/dev/null`; +#3.3V: +3.30 V (min = +3.12 V, max = +3.47 V) +#5V: +5.18 V (min = +4.73 V, max = +5.26 V) +#12V: +12.12 V (min = +11.37 V, max = +12.62 V) +#fan1: 3443 RPM (min = 3000 RPM, div = 2) +#fan2: 3497 RPM (min = 3000 RPM, div = 2) +#temp1: +30?C (min = +10?C, max = +60?C) +#CPU_Temp: +28?C (min = +10?C, max = +60?C) +#CPU2_Temp: +28?C (min = +10?C, max = +60?C) +#vid: +1.75 V + #print "$sd\n"; + #return; + #$sd =~ m/^3\.3V:[\t ]+\+([0-9]+)/m; + #if($sd =~ /^3\.3V:[\t ]+\+([0-9.]+) V[ \t]+/m) { + # $host_info{"3_3V"}=$1+0; + #print $host_info{"3_3V"}; + #} else { + # $host_info{"3_3V"}=0; + #} + #if($sd =~ /^5V:[\t ]+\+([0-9.]+) V[ \t]+/m) { + # $host_info{"5V"}=$1+0; + #}else { + # $host_info{"5V"}=0; + #} + #if($sd =~ /^12V:[\t ]+\+([0-9.]+) V[ \t]+/m) { + # $host_info{"12V"}=$1+0; + #}else { + # $host_info{"12V"}=0; + #} + #if($sd =~ /^fan1:[\t ]+([0-9]+) RPM[ \t]+/m) { + # $host_info{"fan1"}=$1+0; + #}else { + # $host_info{"fan1"}=0; + #} + #if($sd =~ /^fan2:[\t ]+([0-9]+) RPM[ \t]+/m) { + # $host_info{"fan2"}=$1+0; + #}else { + # $host_info{"fan2"}=0; + #} + if($sd =~ /^CPU_Temp:[\t ]+\+([0-9.]+)?C[ \t]+/m) { + $host_info{"CPU1_temp"}=$1+0; + }else { + $host_info{"CPU1_temp"}=0; + } + if($sd =~ /^CPU2_Temp:[\t ]+\+([0-9.]+)?C[ \t]+/m) { + $host_info{"CPU2_temp"}=$1+0; + }else { + $host_info{"CPU2_temp"}=0; + } + if($sd =~ /^temp1:[\t ]+\+([0-9.]+)?C[ \t]+/m) { + $host_info{"Temp"}=$1+0; + }else { + $host_info{"Temp"}=0; + } + + + #print %host_info; +} +# +# +# +sub get_user_stats (){ + if($pid_st=open (USTAT,"-|") ){ + $_=; + ($tot_nproc, $pcnt_tot_nproc, $tot_re, + $pcnt_tot_re, $tot_cp, $pcnt_tot_cp, + $tot_avio, $tot_ksec) = split(); + $tot_re+=0.; $tot_avio+=0.; $tot_cp+=0.; $tot_ksec+=0.; + $pcnt_tot_nproc+=0.; $pcnt_tot_re+=0.; $pcnt_tot_cp+=0.; + + foreach (){ + ($user,$nproc,$pcnt_nproc,$re, + $pcnt_re,$cp,$pcnt_cp,$avio,$ksec) = split(); + $re+=0.; $avio+=0.; $cp+=0.; $ksec+=0.; + $pcnt_nproc+=0.; $pcnt_re+=0.; $pcnt_cp+=0.; + $user_info{$user}{"nproc_pcnt"}=$pcnt_nproc; + $user_info{$user}{"cpu_time_pcnt"}=$pcnt_cp; + $user_info{$user}{"real_time_pcnt"}=$pcnt_re; + $user_info{$user}{"ksec"}=exp($ksec/($tot_ksec+0.0001)); + $user_info{$user}{"cur_proc"}=0; + #$ksec/=$tot_ksec; + #$ksec=log($ksec); + #print "$user: $ksec $pcnt_cp\n"; + } + close USTAT; + } else { + print "cannot fork: $!" unless defined $pid_st; + exec("sa -m -K -c"); + } + +} + +sub get_open_fds(){ + #`cat /proc/sys/fs/file-nr`; + split(' ',`cat /proc/sys/fs/file-nr`); + system("$GMETRIC --name=files_used --type=uint32 --value=@_[1] -i eth0 -l 1"); + #print "@_[1]\n"; +}; + +#$pid_pcp=open ($pcp,"-|"); +#if($pid_pcp){ + +defined(my $pid = fork) or die "Can't fork: $!"; +exit if $pid; +setsid or die "Can't start a new session: $!"; + + + while (1){ + #@_=`vmstat 2>/dev/null`; + #$ln=""; + #foreach $l (@_){ + #print $l; + # if($l =~ /swpd|free/i ) { + # next; + # } else { + # $ln =$l; + # } + #} + #print $ln; + #exit 0; + #print $ln; + #($ld_avg_1min, $mem_swapped, $mem_free, $mem_buff, $mem_cache, + #$host_info{"swap_in"}, + #$host_info{"swap_out"}, + #$host_info{"disk_bin"}, + #$host_info{"disk_bout"}, + #$host_info{"sys_ints"}, + #$host_info{"sys_contsw"}, + #$cpu_u, $cpu_sys, $cpu_idle) = split(/[ \t\n]+/,$ln); + #print "$ld_avg_1min $disk_bout\n"; + +# unless (open(LOCK,">>$lock_file")){ +# print "Cannot open $lock_file\n"; +# exit (1); +# } +# unless (flock(LOCK,LOCK_EX|LOCK_NB)) { +# close (LOCK); +# exit(0); +# } + get_users; + #get_user_stats; + get_user_procs; + get_sensors; + update_stats; + get_open_fds; +# flock(LOCK,LOCK_UN); +# close (LOCK); + +# foreach $user (keys %user_info){ +# $user_info{$user}{"ksec"} /= $tot_ksec; +# print "$user: $user_info{$user}{\"ksec\"} $user_info{$user}{\"nproc_pcnt\"} $user_info{$user}{\"cpu_time_pcnt\"} $user_info{$user}{\"real_time_pcnt\"}\n" ; +# } +# } + # sleep 300; + #} +#} else { +# print "cannot fork: $!" unless defined $pid_pcp; + +# exec("pmstat -t $UPDATE_TIME -T $UPDATE_TIME 2>/dev/null"); + sleep 15; + +} + \ No newline at end of file diff --git a/system/resource_usage_rank/README b/system/resource_usage_rank/README new file mode 100644 index 0000000..8771a57 --- /dev/null +++ b/system/resource_usage_rank/README @@ -0,0 +1,17 @@ +Gmetric script pulled from http://ganglia.info/gmetric + +If you are the author of the script, and have an updated version, please fork the repo and +submit a pull request. For additional information about the repository, please see the +README in the repository top-level. + +Author: Sumanth J.V + +Description: + +Displays the top 5 resource hungry processes currently running. + +Language: BASH + +Category: Resource::Monitoring + +Dependencies: sed, awk, seq, top diff --git a/system/resource_usage_rank/resource_usage_rank.sh b/system/resource_usage_rank/resource_usage_rank.sh new file mode 100755 index 0000000..c3d0d9e --- /dev/null +++ b/system/resource_usage_rank/resource_usage_rank.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# Author Sumanth J.V (sumanth@cse.unl.edu) +# Date 17-June-2002 + +# Ensure that top, seq, sed , awk are in ur path +# Also check if this is the right location of gmetric +GMETRIC=/usr/bin/gmetric + +list=(` + top -b -n 1 |\ + sed -n -e "11,15p" |\ + awk '{print $12, $2, $9, $10, $11}' +`) + +for i in `seq 0 5 24` +do + let id=id+1 + + val="Proc:${list[${i}]}_User:${list[$((${i}+1))]}\ + _CPU:${list[$((${i}+2))]}_Mem:${list[$((${i}+3))]}\ + _Time:${list[$((${i}+4))]}" + + $GMETRIC --name "Resource_Usage_Rank ${id}" \ + --value $val --type string --units ' ' +done + +exit 0