From nobody@FreeBSD.org  Sat Nov  6 20:54:59 2010
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id EA085106566C
	for <freebsd-gnats-submit@FreeBSD.org>; Sat,  6 Nov 2010 20:54:58 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id D8A658FC08
	for <freebsd-gnats-submit@FreeBSD.org>; Sat,  6 Nov 2010 20:54:58 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id oA6KswTD067353
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 6 Nov 2010 20:54:58 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id oA6KswSC067340;
	Sat, 6 Nov 2010 20:54:58 GMT
	(envelope-from nobody)
Message-Id: <201011062054.oA6KswSC067340@www.freebsd.org>
Date: Sat, 6 Nov 2010 20:54:58 GMT
From: Marin Jamrich <jamrich.majo@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: nagios check cpu usage
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         151995
>Category:       ports
>Synopsis:       net-mgmt/nagios-plugins: new plugin to check CPU usage
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    ohauer
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Nov 06 21:00:16 UTC 2010
>Closed-Date:    Fri Dec 03 22:04:29 UTC 2010
>Last-Modified:  Fri Dec 03 22:04:29 UTC 2010
>Originator:     Marin 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.

- Marin 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:
State-Changed-From-To: open->feedback 
State-Changed-By: ohauer 
State-Changed-When: Mon Nov 22 21:57:07 UTC 2010 
State-Changed-Why:  
Hi Marian, 

can you try to include your script in a port? 
It should be not so hard to do this, you can use 
for example ports-mgmt/portlint as starting point. 

Additional some good documentation how to create and  
test a port can be found here: 
http://www.freebsd.org/doc/en_US.ISO8859-1/books/porters-handbook/ 


http://www.freebsd.org/cgi/query-pr.cgi?pr=151995 
Responsible-Changed-From-To: freebsd-ports-bugs->ohauer 
Responsible-Changed-By: ohauer 
Responsible-Changed-When: Tue Nov 23 23:13:34 UTC 2010 
Responsible-Changed-Why:  
Hi Marian, 

your first port Makefile was nearly perfect ;) 

If possible use next time tar instead of rar if you provide 
additional files. 

I've reworked the port to not download the script. The script 
can be delivered with the port since it is a small one. 

Do you really need values behind the "." or is a full 
integer OK? If so "vmstat -c 2 -n 0 | tail -n 1" or "uptime" 
is a way faster than "top -n -d 2 | awk ..." 

I've uploaded the rewritten port for your review, feel free 
to change the vmstat command back to top it is only a suggestion. 

http://people.freebsd.org/~ohauer/diffs/nagios-check_cpu_usage/ 


http://www.freebsd.org/cgi/query-pr.cgi?pr=151995 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: ports/151995: commit references a PR
Date: Fri,  3 Dec 2010 21:52:54 +0000 (UTC)

 ohauer      2010-12-03 21:52:49 UTC
 
   FreeBSD ports repository
 
   Modified files:
     net-mgmt             Makefile 
   Added files:
     net-mgmt/nagios-check_cpu_usage Makefile pkg-descr 
     net-mgmt/nagios-check_cpu_usage/src check_cpu_usage 
   Log:
   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
   
   Revision  Changes    Path
   1.228     +1 -0      ports/net-mgmt/Makefile
   1.1       +26 -0     ports/net-mgmt/nagios-check_cpu_usage/Makefile (new)
   1.1       +4 -0      ports/net-mgmt/nagios-check_cpu_usage/pkg-descr (new)
   1.1       +120 -0    ports/net-mgmt/nagios-check_cpu_usage/src/check_cpu_usage (new)
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: feedback->closed 
State-Changed-By: ohauer 
State-Changed-When: Fri Dec 3 22:03:35 UTC 2010 
State-Changed-Why:  
Committed with minor changes (approved by submitter per mail). 
- add Makefile 
- use vmstat instead of top 
Thanks! 



http://www.freebsd.org/cgi/query-pr.cgi?pr=151995 
>Unformatted:
