aboutsummaryrefslogtreecommitdiff
path: root/net-mgmt/nagios-check_cpu_usage
diff options
context:
space:
mode:
authorOlli Hauer <ohauer@FreeBSD.org>2010-12-03 21:52:49 +0000
committerOlli Hauer <ohauer@FreeBSD.org>2010-12-03 21:52:49 +0000
commit352c32a59012d8263dbe38be16d556cfc3494f9a (patch)
treee61b77db52b6868d8aee731f0f8865f65844eeca /net-mgmt/nagios-check_cpu_usage
parenta30cfe7673aa3694524148a28e3f3e4b1f180adb (diff)
downloadports-352c32a59012d8263dbe38be16d556cfc3494f9a.tar.gz
ports-352c32a59012d8263dbe38be16d556cfc3494f9a.zip
Notes
Diffstat (limited to 'net-mgmt/nagios-check_cpu_usage')
-rw-r--r--net-mgmt/nagios-check_cpu_usage/Makefile26
-rw-r--r--net-mgmt/nagios-check_cpu_usage/pkg-descr4
-rw-r--r--net-mgmt/nagios-check_cpu_usage/src/check_cpu_usage120
3 files changed, 150 insertions, 0 deletions
diff --git a/net-mgmt/nagios-check_cpu_usage/Makefile b/net-mgmt/nagios-check_cpu_usage/Makefile
new file mode 100644
index 000000000000..2a0f2cfd4db9
--- /dev/null
+++ b/net-mgmt/nagios-check_cpu_usage/Makefile
@@ -0,0 +1,26 @@
+# New ports collection makefile for: nagios-check_cpu_usage
+# Date created: 2010-11-23
+# Whom: jamrich.majo@gmail.com
+#
+# $FreeBSD$
+#
+
+PORTNAME= nagios-check_cpu_usage
+PORTVERSION= 1.0
+CATEGORIES= net-mgmt
+MASTER_SITES= # none
+DISTFILES= # none
+
+MAINTAINER= jamrich.majo@gmail.com
+COMMENT= Nagios plug-in to check CPU usage
+
+NO_BUILD= yes
+
+PLIST_DIRSTRY= libexec/nagios
+PLIST_FILES= libexec/nagios/check_cpu_usage
+
+do-install:
+ @${MKDIR} ${PREFIX}/libexec/nagios
+ @${INSTALL_SCRIPT} ${.CURDIR}/src/check_cpu_usage ${PREFIX}/libexec/nagios
+
+.include <bsd.port.mk>
diff --git a/net-mgmt/nagios-check_cpu_usage/pkg-descr b/net-mgmt/nagios-check_cpu_usage/pkg-descr
new file mode 100644
index 000000000000..427dec2a1c7d
--- /dev/null
+++ b/net-mgmt/nagios-check_cpu_usage/pkg-descr
@@ -0,0 +1,4 @@
+check_cpu_usage is a plugin intended for use with the Nagios network
+monitoring system. This plugin checks the current CPU load and
+compares the current state to given thresholds, returning the result.
+It is written as shell script.
diff --git a/net-mgmt/nagios-check_cpu_usage/src/check_cpu_usage b/net-mgmt/nagios-check_cpu_usage/src/check_cpu_usage
new file mode 100644
index 000000000000..d9a9e4c8641d
--- /dev/null
+++ b/net-mgmt/nagios-check_cpu_usage/src/check_cpu_usage
@@ -0,0 +1,120 @@
+#!/bin/sh
+#
+# Plugin return codes
+#
+# OK = 0
+# The plugin was able to check the service and it appeared to be
+# functioning properly
+#
+# Warning = 1
+# The plugin was able to check the service, but it appeared to be above
+# some "warning" threshold or did not appear to be working properly
+#
+# Critical = 2
+# The plugin detected that either the service was not running or it was
+# above some "critical" threshold
+#
+# Unknown = 3
+# Invalid command line arguments were supplied to the plugin or low-level
+# failures internal to the plugin (such as unable to fork, or open a tcp
+# socket) that prevent it from performing the specified operation.
+# Higher-level errors (such as name resolution errors, socket timeouts, etc)
+# are outside of the control of plugins and should generally NOT be reported
+# as UNKNOWN states.
+
+# default path
+PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin
+
+ST_OK=0
+ST_WR=1
+ST_CR=2
+ST_UN=3
+
+# Plugin name
+PROGNAME=`basename $0`
+
+# Version
+VERSION="Version 1.0"
+
+# Author
+AUTHOR="Majo Jamrich"
+
+
+print_version() {
+ echo "$PROGNAME $VERSION $1"
+}
+
+print_help() {
+ print_version "($AUTHOR)"
+ echo ""
+ echo "$PROGNAME is a Nagios plugin to check CPU utilization."
+ echo ""
+ echo "Options:"
+ echo ""
+ echo "--warning | -w"
+ echo "--critical | -c"
+ echo "--help | --usage"
+ echo ""
+ echo "Usage:"
+ echo "./check_cpu_usage -w 80 -c 100"
+ echo ""
+ exit $ST_UN
+}
+
+case "$1" in
+ --help|-h|--usage|-u)
+ print_help
+ exit $ST_UN
+ ;;
+ --warning|-w)
+ host=$2
+ ;;
+ --critical|-c)
+ host=$2
+ ;;
+ -V)
+ print_version
+ exit
+ ;;
+ *)
+ echo "Unknown argument: $1"
+ echo "For more information please try -h or --help!"
+ exit $ST_UN
+ ;;
+esac
+shift
+
+if [ `uname` != "FreeBSD" ]; then
+ echo "This plugin is only for FreeBSD."
+fi
+
+if [ -z $1 ] || [ -z $3 ]; then
+ print_help
+ exit $ST_UN
+fi
+
+if [ "$1" -ge "$3" ]; then
+ echo "Warning value must be greater than critical value!"
+ exit $ST_UN
+fi
+
+warn=$1
+crit=$3
+
+cpu_all=$( vmstat -c 2 -n 0 | tail -n 1 | awk '{print $15 " " $16 " " $17}' )
+cpu_user=$( echo $cpu_all | awk '{print $1}')
+cpu_sys=$( echo $cpu_all | awk '{print $2}')
+cpu_idle=$( echo $cpu_all | awk '{print $3}')
+cpu_usage=$(( 100 - $cpu_idle ))
+perfdata="cpu_usage=$cpu_usage%;$warn;$crit; cpu_user=$cpu_user%; cpu_system=$cpu_sys%;"
+
+if [ $( echo "$cpu_usage>$1" | bc ) -gt 0 ] && [ $( echo "$cpu_usage<$3" | bc ) -gt 0 ]; then
+ echo "WARNING - CPU usage is $cpu_usage% for server `hostname`. |$perfdata"
+ exit $ST_WR
+elif [ $( echo "$cpu_usage>$3" | bc ) -gt 0 ]; then
+ echo "CRITICAL - CPU usage is $cpu_usage% for server `hostname`. |$perfdata"
+ exit $ST_CR
+else
+ echo "OK - CPU usage is $cpu_usage% for server `hostname`. |$perfdata"
+ exit $ST_OK
+fi