aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorohauer <ohauer@FreeBSD.org>2010-12-04 05:52:49 +0800
committerohauer <ohauer@FreeBSD.org>2010-12-04 05:52:49 +0800
commit6ec502d7356e6ced34e8287b7ee3f88de2e74776 (patch)
tree5e39c20cf7b016ac828c8640548168a2542e7178
parent9b10314e7d425d3f46e3d4f8b9b0b72644bf4fe3 (diff)
downloadfreebsd-ports-gnome-6ec502d7356e6ced34e8287b7ee3f88de2e74776.tar.gz
freebsd-ports-gnome-6ec502d7356e6ced34e8287b7ee3f88de2e74776.tar.zst
freebsd-ports-gnome-6ec502d7356e6ced34e8287b7ee3f88de2e74776.zip
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. PR: ports/151995 Submitted by: jamrich.majo at gmail.com
-rw-r--r--net-mgmt/Makefile1
-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
4 files changed, 151 insertions, 0 deletions
diff --git a/net-mgmt/Makefile b/net-mgmt/Makefile
index 7029b353bddc..1a0407acd6a6 100644
--- a/net-mgmt/Makefile
+++ b/net-mgmt/Makefile
@@ -115,6 +115,7 @@
SUBDIR += nagios-certexp-plugin
SUBDIR += nagios-check_bacula
SUBDIR += nagios-check_clamav
+ SUBDIR += nagios-check_cpu_usage
SUBDIR += nagios-check_ice
SUBDIR += nagios-check_kumofs
SUBDIR += nagios-check_memcached_paranoid
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