Date: Sat, 6 Nov 2010 20:54:58 GMT From: Marián Jamrich <jamrich.majo@gmail.com> To: freebsd-gnats-submit@FreeBSD.org Subject: ports/151995: nagios check cpu usage Message-ID: <201011062054.oA6KswSC067340@www.freebsd.org> Resent-Message-ID: <201011062100.oA6L0Hi1042514@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 151995 >Category: ports >Synopsis: nagios check cpu usage >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-ports-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Sat Nov 06 21:00:16 UTC 2010 >Closed-Date: >Last-Modified: >Originator: Marián Jamrich >Release: 8.1 >Organization: >Environment: FreeBSD trinity.vx.sk 8.1-STABLE FreeBSD 8.1-STABLE #1 r212791: Wed Nov 3 11:37:30 CET 2010 root@trinity.vx.sk:/usr/obj/usr/src/sys/MYKERNEL amd64 >Description: Nagios Plugin to check your actually CPU utilization. - Marián Jamrich jamrich.majo@gmail.com >How-To-Repeat: >Fix: Patch attached with submission follows: # This is a shell archive. Save it in a file, remove anything before # this line, and then unpack it by entering "sh file". Note, it may # create directories; files and directories will be owned by you and # have default permissions. # # This archive contains: # # /tmp/home/jamrich/port/work/check_cpu_usage # echo x - /tmp/home/jamrich/port/work/check_cpu_usage sed 's/^X//' >/tmp/home/jamrich/port/work/check_cpu_usage << '87363c859dcd04abe63b096e8c513458' X#!/bin/sh X# X# Plugin return codes X# X# OK = 0 X# The plugin was able to check the service and it appeared to be functioning properly X# X# Warning = 1 X# 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 X# X# Critical = 2 X# The plugin detected that either the service was not running or it was above some "critical" threshold X# X# Unknown = 3 X# 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. X XST_OK=0 XST_WR=1 XST_CR=2 XST_UN=3 X X# Plugin name XPROGNAME=`basename $0` X X# Version XVERSION="Version 1.0," X X# Author XAUTHOR="" X X# TOP command Xtop=`which top` Xbc=`which bc` X Xprint_version() { X echo "$VERSION $AUTHOR" X} X Xprint_help() { X print_version $PROGNAME $VERSION X echo "" X echo "$PROGNAME is a Nagios plugin to check CPU utilization." X echo "" X echo "Options:" X echo "" X echo "--warning | -w" X echo "--critical | -c" X echo "--help | --usage" X echo "" X echo "Usage:" X echo "" X echo "./check_cpu_usage -w 80 -c 100" X exit $ST_UN X} X Xcase "$1" in X --help|-h|--usage|-u) X print_help X exit $ST_UN X ;; X --warning|-w) X host=$2 X ;; X --critical|-c) X host=$2 X ;; X *) X echo "Unknown argument: $1" X echo "For more information please try -h or --help!" X exit $ST_UN X ;; Xesac Xshift X Xif [ `uname` != "FreeBSD" ]; then X echo "This plugin is only for FreeBSD." Xfi X Xif [ -z $1 ] || [ -z $3 ]; then X print_help X exit $ST_UN Xfi X Xif [ "$1" -ge "$3" ]; then X echo "Warning value must be greater than critical value!" X exit $ST_UN Xfi X Xcpu_idle=$($top -n -d 2 | /usr/bin/grep idle | /usr/bin/awk '{print $10}' | /usr/bin/sed 's/%//') Xcpu_usage=`echo 100-$cpu_idle| $bc | sed 's/^\./0./'` X X Xif [ $(echo "$cpu_usage>$1"|$bc) -gt 0 ] && [ $(echo "$cpu_usage<$3"|$bc) -gt 0 ]; then X echo "WARNING - CPU usage is $cpu_usage% for server `hostname`. | http_state=$cpu_usage" X exit 1 Xelif [ $(echo "$cpu_usage>$3"|$bc) -gt 0 ]; then X echo "CRITICAL - CPU usage is $cpu_usage% for server `hostname`. | http_state=$cpu_usage" X exit 2 Xelse X echo "OK - CPU usage is $cpu_usage% for server `hostname`. | http_state=$cpu_usage" X exit 0 Xfi 87363c859dcd04abe63b096e8c513458 exit >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201011062054.oA6KswSC067340>