<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Matejunkie &#187; performance</title>
	<atom:link href="http://www.matejunkie.com/tag/performance/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.matejunkie.com</link>
	<description>"Look behind you, a Three-Headed Monkey!"</description>
	<lastBuildDate>Thu, 07 Jan 2010 14:26:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>PNP template for check_apache2.sh</title>
		<link>http://www.matejunkie.com/pnp-template-for-check_apache2-sh/</link>
		<comments>http://www.matejunkie.com/pnp-template-for-check_apache2-sh/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 20:07:52 +0000</pubDate>
		<dc:creator>Mike Adolphs</dc:creator>
				<category><![CDATA[Binary Talks]]></category>
		<category><![CDATA[apache webserver]]></category>
		<category><![CDATA[gplv2]]></category>
		<category><![CDATA[nagios]]></category>
		<category><![CDATA[network monitoring]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[pnp template]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://www.matejunkie.com/?p=1246</guid>
		<description><![CDATA[This is a PNP template which works quite well for me when there&#8217;s need to identify possible bottlenecks or unexpected behavior of the Apache webserver. It shows the CPU usage, req/sec, byte/req and the amount of busy/idle workers in a single graph. Feel free to copy the template from below or head over to Nagios [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.matejunkie.com/wp-content/uploads/2009/09/check_apache2.png"><img class="alignleft size-medium wp-image-1248" title="check_apache2 PNP Template" src="http://www.matejunkie.com/wp-content/uploads/2009/09/check_apache2-300x125.png" alt="check_apache2 PNP Template" width="180" height="75" /></a>This is a PNP template which works quite well for me when there&#8217;s need to identify possible bottlenecks or unexpected behavior of the Apache webserver. It shows the CPU usage, req/sec, byte/req and the amount of busy/idle workers in a single graph. Feel free to copy the template from below or head over <a href="http://exchange.nagios.org/directory/Plugins/Web-Servers/Apache/check_apache2-2Esh/details" title="Nagios Exchange - check_apache2.sh">to Nagios Exchange</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#   This program is free software; you can redistribute it and/or modify
</span><span style="color: #666666; font-style: italic;">#   it under the terms of the GNU General Public License as published by
</span><span style="color: #666666; font-style: italic;">#   the Free Software Foundation; either version 2 of the License, or
</span><span style="color: #666666; font-style: italic;">#   (at your option) any later version.
</span><span style="color: #666666; font-style: italic;">#
</span><span style="color: #666666; font-style: italic;">#   This program is distributed in the hope that it will be useful,
</span><span style="color: #666666; font-style: italic;">#   but WITHOUT ANY WARRANTY; without even the implied warranty of
</span><span style="color: #666666; font-style: italic;">#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
</span><span style="color: #666666; font-style: italic;">#   GNU General Public License for more details.
</span><span style="color: #666666; font-style: italic;">#
</span><span style="color: #666666; font-style: italic;">#   You should have received a copy of the GNU General Public License
</span><span style="color: #666666; font-style: italic;">#   along with this program; if not, write to the Free Software
</span><span style="color: #666666; font-style: italic;">#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
</span>
<span style="color: #666666; font-style: italic;">#   PNP Template for check_apache2.sh
</span><span style="color: #666666; font-style: italic;">#   Author: Mike Adolphs (http://www.matejunkie.com/)
</span>
<span style="color: #000088;">$opt</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;--vertical-label <span style="color: #000099; font-weight: bold;">\&quot;</span>Various stats <span style="color: #000099; font-weight: bold;">\&quot;</span> -l 0 -r --title <span style="color: #000099; font-weight: bold;">\&quot;</span>Apache metrics for <span style="color: #006699; font-weight: bold;">$hostname</span> / <span style="color: #006699; font-weight: bold;">$servicedesc</span><span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;DEF:cpu=<span style="color: #006699; font-weight: bold;">$rrdfile</span>:<span style="color: #006699; font-weight: bold;">$DS[1]</span>:AVERAGE &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;DEF:reqpsec=<span style="color: #006699; font-weight: bold;">$rrdfile</span>:<span style="color: #006699; font-weight: bold;">$DS[2]</span>:AVERAGE &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;DEF:bytepreq=<span style="color: #006699; font-weight: bold;">$rrdfile</span>:<span style="color: #006699; font-weight: bold;">$DS[4]</span>:AVERAGE &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;DEF:wbusy=<span style="color: #006699; font-weight: bold;">$rrdfile</span>:<span style="color: #006699; font-weight: bold;">$DS[5]</span>:AVERAGE &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;DEF:widle=<span style="color: #006699; font-weight: bold;">$rrdfile</span>:<span style="color: #006699; font-weight: bold;">$DS[6]</span>:AVERAGE &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$opt</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;--vertical-label <span style="color: #000099; font-weight: bold;">\&quot;</span>Byte/sec <span style="color: #000099; font-weight: bold;">\&quot;</span> -l 0 -r --title <span style="color: #000099; font-weight: bold;">\&quot;</span>Apache metrics for <span style="color: #006699; font-weight: bold;">$hostname</span> / <span style="color: #006699; font-weight: bold;">$servicedesc</span><span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;DEF:bytepsec=<span style="color: #006699; font-weight: bold;">$rrdfile</span>:<span style="color: #006699; font-weight: bold;">$DS[3]</span>:AVERAGE &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;COMMENT:<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>tLAST<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>tAVERAGE<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>tMAX<span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;LINE2:cpu#008000:<span style="color: #000099; font-weight: bold;">\&quot;</span>CPU usage [%]<span style="color: #000099; font-weight: bold;">\\</span>t <span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:cpu:LAST:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.0lf<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:cpu:AVERAGE:<span style="color: #000099; font-weight: bold;">\&quot;</span> %6.0lf<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:cpu:MAX:<span style="color: #000099; font-weight: bold;">\&quot;</span> %6.0lf<span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;LINE2:reqpsec#0C64E8:<span style="color: #000099; font-weight: bold;">\&quot;</span>Requests/sec<span style="color: #000099; font-weight: bold;">\\</span>t <span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:reqpsec:LAST:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.0lf<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:reqpsec:AVERAGE:<span style="color: #000099; font-weight: bold;">\&quot;</span> %6.0lf<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:reqpsec:MAX:<span style="color: #000099; font-weight: bold;">\&quot;</span> %6.0lf<span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;LINE2:bytepreq#FFA500:<span style="color: #000099; font-weight: bold;">\&quot;</span>Byte/req<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t <span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:bytepreq:LAST:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.0lf<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:bytepreq:AVERAGE:<span style="color: #000099; font-weight: bold;">\&quot;</span> %6.0lf<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:bytepreq:MAX:<span style="color: #000099; font-weight: bold;">\&quot;</span> %6.0lf<span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;LINE2:wbusy#1CC8E8:<span style="color: #000099; font-weight: bold;">\&quot;</span>Busy workers<span style="color: #000099; font-weight: bold;">\\</span>t <span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:wbusy:LAST:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.0lf<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:wbusy:AVERAGE:<span style="color: #000099; font-weight: bold;">\&quot;</span> %6.0lf<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:wbusy:MAX:<span style="color: #000099; font-weight: bold;">\&quot;</span> %6.0lf<span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;LINE2:widle#E80C8C:<span style="color: #000099; font-weight: bold;">\&quot;</span>Idle workers<span style="color: #000099; font-weight: bold;">\\</span>t <span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:widle:LAST:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.0lf<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:widle:AVERAGE:<span style="color: #000099; font-weight: bold;">\&quot;</span> %6.0lf<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:widle:MAX:<span style="color: #000099; font-weight: bold;">\&quot;</span> %6.0lf<span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;COMMENT:<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>tLAST<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>tAVERAGE<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>tMAX<span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;LINE2:bytepsec#E80C3E:<span style="color: #000099; font-weight: bold;">\&quot;</span>Byte/sec<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t <span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:bytepsec:LAST:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.0lf<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:bytepsec:AVERAGE:<span style="color: #000099; font-weight: bold;">\&quot;</span> %6.0lf<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:bytepsec:MAX:<span style="color: #000099; font-weight: bold;">\&quot;</span> %6.0lf<span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.matejunkie.com/pnp-template-for-check_apache2-sh/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>nginx Check Plugin for Nagios</title>
		<link>http://www.matejunkie.com/nginx-check-plugin-for-nagios/</link>
		<comments>http://www.matejunkie.com/nginx-check-plugin-for-nagios/#comments</comments>
		<pubDate>Sun, 24 May 2009 16:34:14 +0000</pubDate>
		<dc:creator>Mike Adolphs</dc:creator>
				<category><![CDATA[Binary Talks]]></category>
		<category><![CDATA[nagios]]></category>
		<category><![CDATA[network monitoring]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[shell scripting]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[webserver]]></category>

		<guid isPermaLink="false">http://www.matejunkie.com/?p=1066</guid>
		<description><![CDATA[Update: Please also consider reading the article regarding Update 1.1 for check_nginx.sh. Ok, this was obvious. Here&#8217;s a Nagios plugin I&#8217;ve just finished to check whether nginx is running and to get some performance data like requests and connections per second as well as requests per connection. Please note that the StubStatus module for nginx [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-193" title="logo_nagios" src="http://www.matejunkie.com/wp-content/uploads/2008/05/logo_nagios.gif" alt="logo_nagios" width="150" height="40" /><span style="color: #ff0000;"><strong>Update:</strong></span> Please also consider reading the article regarding <a title="MonitoringExchange - Update 1.1 on check_nginx.sh" href="http://www.matejunkie.com/update-1-1-nginx-check-plugin-for-nagios/" target="_blank">Update 1.1 for check_nginx.sh</a>.</p>
<p>Ok, this was obvious. Here&#8217;s a Nagios plugin I&#8217;ve just finished to check whether nginx is running and to get some performance data like requests and connections per second as well as requests per connection.</p>
<p>Please note that the <a title="nginx - StubStatus Module" href="http://wiki.nginx.org/NginxHttpStubStatusModule" target="_blank">StubStatus module</a> for nginx must be compiled into it, this isn&#8217;t done by default! And please make sure that you&#8217;ve added a location directive to your nginx configuration like the following as well. The script must be able to access it!</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">location <span style="color: #000000; font-weight: bold;">/</span>nginx_status <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    stub_status on;
    access_log off;
    allow 127.0.0.1;
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<h3>The script</h3>
<p>Feel free to grab the script from below, <a title="MonitoringExchange - check_nginx.sh" href="http://www.monitoringexchange.org/cgi-bin/page.cgi?g=Detailed%2F3089.html" target="_blank">at MonitoringExchange</a> or via svn checkout. Let me know if something&#8217;s not working for you and I&#8217;ll improve it. If you have any questsions do so as well.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ <span style="color: #c20cb9; font-weight: bold;">svn</span> <span style="color: #c20cb9; font-weight: bold;">co</span> http:<span style="color: #000000; font-weight: bold;">//</span>svn.matejunkie.com<span style="color: #000000; font-weight: bold;">/</span>nagios-plugins<span style="color: #000000; font-weight: bold;">/</span>stable<span style="color: #000000; font-weight: bold;">/</span>check_nginx<span style="color: #000000; font-weight: bold;">/</span> check_nginx<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#   This program is free software; you can redistribute it and/or modify</span>
<span style="color: #666666; font-style: italic;">#   it under the terms of the GNU General Public License as published by</span>
<span style="color: #666666; font-style: italic;">#   the Free Software Foundation; either version 2 of the License, or</span>
<span style="color: #666666; font-style: italic;">#   (at your option) any later version.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#   This program is distributed in the hope that it will be useful,</span>
<span style="color: #666666; font-style: italic;">#   but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span style="color: #666666; font-style: italic;">#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<span style="color: #666666; font-style: italic;">#   GNU General Public License for more details.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#   You should have received a copy of the GNU General Public License</span>
<span style="color: #666666; font-style: italic;">#   along with this program; if not, write to the Free Software</span>
<span style="color: #666666; font-style: italic;">#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA</span>
&nbsp;
<span style="color: #007800;">PROGNAME</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">basename</span> $<span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">VERSION</span>=<span style="color: #ff0000;">&quot;Version 1.0,&quot;</span>
<span style="color: #007800;">AUTHOR</span>=<span style="color: #ff0000;">&quot;2009, Mike Adolphs (http://www.matejunkie.com/)&quot;</span>
&nbsp;
<span style="color: #007800;">ST_OK</span>=<span style="color: #000000;">0</span>
<span style="color: #007800;">ST_WR</span>=<span style="color: #000000;">1</span>
<span style="color: #007800;">ST_CR</span>=<span style="color: #000000;">2</span>
<span style="color: #007800;">ST_UK</span>=<span style="color: #000000;">3</span>
<span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">hostname</span></span>=<span style="color: #ff0000;">&quot;localhost&quot;</span>
<span style="color: #007800;">port</span>=<span style="color: #000000;">80</span>
<span style="color: #007800;">path_pid</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run
<span style="color: #007800;">name_pid</span>=<span style="color: #ff0000;">&quot;nginx.pid&quot;</span>
<span style="color: #007800;">status_page</span>=<span style="color: #ff0000;">&quot;nginx_status&quot;</span>
<span style="color: #007800;">output_dir</span>=<span style="color: #000000; font-weight: bold;">/</span>tmp
<span style="color: #007800;">pid_check</span>=<span style="color: #000000;">1</span>
<span style="color: #007800;">secure</span>=<span style="color: #000000;">0</span>
&nbsp;
print_version<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$VERSION</span> <span style="color: #007800;">$AUTHOR</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
print_help<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    print_version <span style="color: #007800;">$PROGNAME</span> <span style="color: #007800;">$VERSION</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$PROGNAME</span> is a Nagios plugin to check whether nginx is running.&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;It also parses the nginx's status page to get requests and&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;connections per second as well as requests per connection. You&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;may have to alter your nginx configuration so that the plugin&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;can access the server's status page.&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;The plugin is highly configurable for this reason. See below for&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;available options.&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$PROGNAME</span> -H localhost -P 80 -p /var/run -n nginx.pid &quot;</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -s nginx_statut -o /tmp [-w INT] [-c INT] [-S] [-N]&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Options:&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -H/--hostname)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Defines the hostname. Default is: localhost&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -P/--port)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Defines the port. Default is: 80&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -p/--path-pid)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Path where nginx's pid file is being stored. You might need&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     to alter this path according to your distribution. Default&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     is: /var/run&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -n/--name_pid)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Name of the pid file. Default is: nginx.pid&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -N/--no-pid-check)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Turn this on, if you don't want to check for a pid file&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     whether nginx is running, e.g. when you're checking a&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     remote server. Default is: off&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -s/--status-page)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Name of the server's status page defined in the location&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     directive of your nginx configuration. Default is:&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     nginx_status&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -o/--output-directory)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Specifies where to write the tmp-file that the check creates.&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Default is: /tmp&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -S/--secure)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     In case your server is only reachable via SSL, use this&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     this switch to use HTTPS instead of HTTP. Default is: off&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -w/--warning)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Sets a warning level for requests per second. Default is: off&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -c/--critical)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Sets a critical level for requests per second. Default is:&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     off&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;$1&quot;</span>; <span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
        -help<span style="color: #000000; font-weight: bold;">|</span>-h<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            print_help
            <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --version<span style="color: #000000; font-weight: bold;">|</span>-v<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            print_version <span style="color: #007800;">$PROGNAME</span> <span style="color: #007800;">$VERSION</span>
            <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --hostname<span style="color: #000000; font-weight: bold;">|</span>-H<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">hostname</span></span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --port<span style="color: #000000; font-weight: bold;">|</span>-P<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">port</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --path-pid<span style="color: #000000; font-weight: bold;">|</span>-p<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">path_pid</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --name-pid<span style="color: #000000; font-weight: bold;">|</span>-n<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">name_pid</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --no-pid-check<span style="color: #000000; font-weight: bold;">|</span>-N<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">pid_check</span>=<span style="color: #000000;">0</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --status-page<span style="color: #000000; font-weight: bold;">|</span>-s<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">status_page</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --output-directory<span style="color: #000000; font-weight: bold;">|</span>-o<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">output_dir</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --secure<span style="color: #000000; font-weight: bold;">|</span>-S<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">secure</span>=<span style="color: #000000;">1</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --warning<span style="color: #000000; font-weight: bold;">|</span>-w<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">warning</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --critical<span style="color: #000000; font-weight: bold;">|</span>-c<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">critical</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Unknown argument: $1&quot;</span>
            print_help
            <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
    <span style="color: #000000; font-weight: bold;">esac</span>
    <span style="color: #7a0874; font-weight: bold;">shift</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
get_wcdiff<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warning</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$critical</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">wclvls</span>=<span style="color: #000000;">1</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #800000;">${warning}</span> <span style="color: #660033;">-gt</span> <span style="color: #800000;">${critical}</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
        <span style="color: #000000; font-weight: bold;">then</span>
            <span style="color: #007800;">wcdiff</span>=<span style="color: #000000;">1</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
    <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warning</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$critical</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">wcdiff</span>=<span style="color: #000000;">2</span>
    <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warning</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$critical</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">wcdiff</span>=<span style="color: #000000;">3</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
val_wcdiff<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$wcdiff</span>&quot;</span> = <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Please adjust your warning/critical thresholds. The warning <span style="color: #000099; font-weight: bold;">\
</span>must be lower than the critical level!&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
    <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$wcdiff</span>&quot;</span> = <span style="color: #000000;">2</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Please also set a critical value when you want to use <span style="color: #000099; font-weight: bold;">\
</span>warning/critical thresholds!&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
    <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$wcdiff</span>&quot;</span> = <span style="color: #000000;">3</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Please also set a warning value when you want to use <span style="color: #000099; font-weight: bold;">\
</span>warning/critical thresholds!&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
check_pid<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$path_pid</span>/<span style="color: #007800;">$name_pid</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">retval</span>=<span style="color: #000000;">0</span>
    <span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #007800;">retval</span>=<span style="color: #000000;">1</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
get_status<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$secure</span>&quot;</span> = <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #660033;">--no-check-certificate</span> <span style="color: #660033;">-q</span> <span style="color: #660033;">-t</span> <span style="color: #000000;">3</span> <span style="color: #660033;">-T</span> <span style="color: #000000;">3</span> \
http:<span style="color: #000000; font-weight: bold;">//</span><span style="color: #800000;">${hostname}</span>:<span style="color: #800000;">${port}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${status_page}</span> <span style="color: #660033;">-O</span> <span style="color: #800000;">${output_dir}</span><span style="color: #000000; font-weight: bold;">/</span>nginx-status.1
        <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">1</span>
        <span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #660033;">--no-check-certificate</span> <span style="color: #660033;">-q</span> <span style="color: #660033;">-t</span> <span style="color: #000000;">3</span> <span style="color: #660033;">-T</span> <span style="color: #000000;">3</span> \
http:<span style="color: #000000; font-weight: bold;">//</span><span style="color: #800000;">${hostname}</span>:<span style="color: #800000;">${port}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${status_page}</span> <span style="color: #660033;">-O</span> <span style="color: #800000;">${output_dir}</span><span style="color: #000000; font-weight: bold;">/</span>nginx-status.2
    <span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #660033;">-q</span> <span style="color: #660033;">-t</span> <span style="color: #000000;">3</span> <span style="color: #660033;">-T</span> <span style="color: #000000;">3</span> http:<span style="color: #000000; font-weight: bold;">//</span><span style="color: #800000;">${hostname}</span>:<span style="color: #800000;">${port}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${status_page}</span> \
<span style="color: #660033;">-O</span> <span style="color: #800000;">${output_dir}</span><span style="color: #000000; font-weight: bold;">/</span>nginx-status.1
        <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">1</span>
        <span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #660033;">-q</span> <span style="color: #660033;">-t</span> <span style="color: #000000;">3</span> <span style="color: #660033;">-T</span> <span style="color: #000000;">3</span> http:<span style="color: #000000; font-weight: bold;">//</span><span style="color: #800000;">${hostname}</span>:<span style="color: #800000;">${port}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${status_page}</span> \
<span style="color: #660033;">-O</span> <span style="color: #800000;">${output_dir}</span><span style="color: #000000; font-weight: bold;">/</span>nginx-status.2
    <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
    <span style="color: #007800;">stat_output1</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">stat</span> <span style="color: #660033;">-c</span> <span style="color: #000000; font-weight: bold;">%</span>s <span style="color: #800000;">${output_dir}</span><span style="color: #000000; font-weight: bold;">/</span>nginx-status.1<span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">stat_output2</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">stat</span> <span style="color: #660033;">-c</span> <span style="color: #000000; font-weight: bold;">%</span>s <span style="color: #800000;">${output_dir}</span><span style="color: #000000; font-weight: bold;">/</span>nginx-status.2<span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$stat_output1</span>&quot;</span> = <span style="color: #000000;">0</span> <span style="color: #660033;">-o</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$stat_output2</span>&quot;</span> = <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;UNKNOWN - Local copy/copies of <span style="color: #007800;">$status_page</span> is empty.&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
get_vals<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #007800;">tmp1_reqpsec</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">'^ '</span> <span style="color: #800000;">${output_dir}</span><span style="color: #000000; font-weight: bold;">/</span>nginx-status.1<span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $3}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">tmp2_reqpsec</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">'^ '</span> <span style="color: #800000;">${output_dir}</span><span style="color: #000000; font-weight: bold;">/</span>nginx-status.2<span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $3}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">reqpsec</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #007800;">$tmp2_reqpsec</span> - <span style="color: #007800;">$tmp1_reqpsec</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
    <span style="color: #007800;">tmp1_conpsec</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">'^ '</span> <span style="color: #800000;">${output_dir}</span><span style="color: #000000; font-weight: bold;">/</span>nginx-status.1<span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $2}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">tmp2_conpsec</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">'^ '</span> <span style="color: #800000;">${output_dir}</span><span style="color: #000000; font-weight: bold;">/</span>nginx-status.2<span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $2}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">conpsec</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #007800;">$tmp2_conpsec</span> - <span style="color: #007800;">$tmp1_conpsec</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
    <span style="color: #007800;">reqpcon</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;scale=2; <span style="color: #007800;">$reqpsec</span> / <span style="color: #007800;">$conpsec</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span> -l<span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$reqpcon</span>&quot;</span> = <span style="color: #ff0000;">&quot;.99&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">reqpcon</span>=<span style="color: #ff0000;">&quot;1.00&quot;</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
do_output<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #007800;">output</span>=<span style="color: #ff0000;">&quot;nginx is running. <span style="color: #007800;">$reqpsec</span> requests per second, <span style="color: #007800;">$conpsec</span> <span style="color: #000099; font-weight: bold;">\
</span>connections per second (<span style="color: #007800;">$reqpcon</span> requests per connection)&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
do_perfdata<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #007800;">perfdata</span>=<span style="color: #ff0000;">&quot;'reqpsec'=<span style="color: #007800;">$reqpsec</span> 'conpsec'=<span style="color: #007800;">$conpsec</span> 'conpreq'=<span style="color: #007800;">$reqpcon</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Here we go!</span>
get_wcdiff
val_wcdiff
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #800000;">${pid_check}</span> = <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
    check_pid
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$retval</span>&quot;</span> = <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;There's no pid file for nginx. Is nginx running? Please <span style="color: #000099; font-weight: bold;">\
</span>also make sure whether your pid path and name is correct.&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_CR</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
get_status
get_vals
do_output
do_perfdata
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warning</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$critical</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$reqpsec</span>&quot;</span> <span style="color: #660033;">-ge</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warning</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$reqpsec</span>&quot;</span> <span style="color: #660033;">-lt</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$critical</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;WARNING - <span style="color: #007800;">${output}</span> | <span style="color: #007800;">${perfdata}</span>&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_WR</span>
    <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$reqpsec</span>&quot;</span> <span style="color: #660033;">-ge</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$critical</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;CRITICAL - <span style="color: #007800;">${output}</span> | <span style="color: #007800;">${perfdata}</span>&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_CR</span>
    <span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;OK - <span style="color: #007800;">${output}</span> | <span style="color: #007800;">${perfdata}</span> ]&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_OK</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">else</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;OK - <span style="color: #007800;">${output}</span> | <span style="color: #007800;">${perfdata}</span>&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_OK</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<h3>The License</h3>
<p>As always this little script is ment to be sh-compliant and released under the terms of the GPL Version 2 only. Feel free to subscribe via rss to get updates on this one. More options will be added in the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matejunkie.com/nginx-check-plugin-for-nagios/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>CPU check plugin for Nagios</title>
		<link>http://www.matejunkie.com/cpu-check-plugin-for-nagios/</link>
		<comments>http://www.matejunkie.com/cpu-check-plugin-for-nagios/#comments</comments>
		<pubDate>Wed, 13 May 2009 10:48:13 +0000</pubDate>
		<dc:creator>Mike Adolphs</dc:creator>
				<category><![CDATA[Binary Talks]]></category>
		<category><![CDATA[cpu]]></category>
		<category><![CDATA[gplv2]]></category>
		<category><![CDATA[jiffies]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[nagios]]></category>
		<category><![CDATA[network monitoring]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[pnp template]]></category>
		<category><![CDATA[shell scripting]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://www.matejunkie.com/?p=970</guid>
		<description><![CDATA[I&#8217;ve just finished version 1.0 of a CPU check plugin which is sh-compliant (as always) and calculates utilization through Jiffies rather than using another third party tool like iostat or top. This means it should work on all Linux machines right out of the box without the need to install additional software. Frankly speaking the [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-193" title="logo_nagios" src="http://www.matejunkie.com/wp-content/uploads/2008/05/logo_nagios.gif" alt="logo_nagios" width="150" height="40" />I&#8217;ve just finished version 1.0 of a CPU check plugin which is sh-compliant (as always) and calculates utilization <a title="Wikipedia - Jiffy" href="http://en.wikipedia.org/wiki/Jiffy_(time)#Use_in_computing" target="_blank">through Jiffies</a> rather than using another third party tool like iostat or top. This means it should work on all Linux machines right out of the box without the need to install additional software.<br />
<a href="http://www.matejunkie.com/wp-content/uploads/2009/05/check_cpu_example01.png"><img class="alignright size-thumbnail wp-image-972" title="check_cpu_example01" src="http://www.matejunkie.com/wp-content/uploads/2009/05/check_cpu_example01-150x150.png" alt="check_cpu_example01" width="150" height="150" /></a>Frankly speaking the performance of the script is slightly worse than the performance of most of the other CPU check plugins due to the sacrifice of parsing iostat or top output, but I nevertheless wanted to do this since calculating CPU utilization through Jiffies instead of parsing another tool&#8217;s output is somewhat different and interesting. I didn&#8217;t take a look into iostat&#8217;s or top&#8217;s source code yet, but I guess these tools doesn&#8217;t do it in another way than parsing /proc/stat as well. The difference in performance isn&#8217;t that huge anyway, a double-digit amount of milliseconds, but not more.</p>
<p>For getting along with the Jiffies, I crawled through the web, especially <a title="Paul Colby's weblog - Calculating cpu utilization via /proc/stat" href="http://colby.id.au/node/39" target="_blank">Paul Colby&#8217;s article</a> about calculating CPU utilization through /proc/stat helped a lot!</p>
<h3>The script</h3>
<p>As always, the script is downloadable <a title="Nagiosexchange - check_cpu.sh" href="http://www.monitoringexchange.org/cgi-bin/page.cgi?g=Detailed%2F3077.html" target="_blank">from NagiosExchange</a>, via svn directly from here or the copy&#8217;n'paste way below. A proper PNP template is included as well.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user<span style="color: #000000; font-weight: bold;">@</span>host ~ $ <span style="color: #c20cb9; font-weight: bold;">svn</span> <span style="color: #c20cb9; font-weight: bold;">co</span> https:<span style="color: #000000; font-weight: bold;">//</span>svn.matejunkie.com<span style="color: #000000; font-weight: bold;">/</span>svn<span style="color: #000000; font-weight: bold;">/</span>nagios-plugins<span style="color: #000000; font-weight: bold;">/</span>stable<span style="color: #000000; font-weight: bold;">/</span>check_cpu<span style="color: #000000; font-weight: bold;">/</span> check_cpu<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#   This program is free software; you can redistribute it and/or modify</span>
<span style="color: #666666; font-style: italic;">#   it under the terms of the GNU General Public License as published by</span>
<span style="color: #666666; font-style: italic;">#   the Free Software Foundation; either version 2 of the License, or</span>
<span style="color: #666666; font-style: italic;">#   (at your option) any later version.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#   This program is distributed in the hope that it will be useful,</span>
<span style="color: #666666; font-style: italic;">#   but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span style="color: #666666; font-style: italic;">#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<span style="color: #666666; font-style: italic;">#   GNU General Public License for more details.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#   You should have received a copy of the GNU General Public License</span>
<span style="color: #666666; font-style: italic;">#   along with this program; if not, write to the Free Software</span>
<span style="color: #666666; font-style: italic;">#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA</span>
&nbsp;
<span style="color: #007800;">PROGNAME</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">basename</span> $<span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">VERSION</span>=<span style="color: #ff0000;">&quot;Version 1.0,&quot;</span>
<span style="color: #007800;">AUTHOR</span>=<span style="color: #ff0000;">&quot;2009, Mike Adolphs (http://www.matejunkie.com/)&quot;</span>
&nbsp;
<span style="color: #007800;">ST_OK</span>=<span style="color: #000000;">0</span>
<span style="color: #007800;">ST_WR</span>=<span style="color: #000000;">1</span>
<span style="color: #007800;">ST_CR</span>=<span style="color: #000000;">2</span>
<span style="color: #007800;">ST_UK</span>=<span style="color: #000000;">3</span>
&nbsp;
<span style="color: #007800;">interval</span>=<span style="color: #000000;">1</span>
&nbsp;
print_version<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$VERSION</span> <span style="color: #007800;">$AUTHOR</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
print_help<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    print_version <span style="color: #007800;">$PROGNAME</span> <span style="color: #007800;">$VERSION</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$PROGNAME</span> is a Nagios plugin to monitor CPU utilization. It makes&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;use of /proc/stat and calculates it through Jiffies rather than&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;using another frontend tool like iostat or top.&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;When using optional warning/critical thresholds all values except&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;idle are aggregated and compared to the thresholds. There's&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;currently no support for warning/critical thresholds for specific&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;usage parameters.&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$PROGNAME</span> [-i/--interval] [-w/--warning] [-c/--critical]&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Options:&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  --interval|-i)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;    Defines the pause between the two times /proc/stat is being&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;    parsed. Higher values could lead to more accurate result.&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;    Default is: 1 second&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  --warning|-w)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;    Sets a warning level for CPU user. Default is: off&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  --critical|-c)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;    Sets a critical level for CPU user. Default is: off&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;$1&quot;</span>; <span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
        --help<span style="color: #000000; font-weight: bold;">|</span>-h<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            print_help
            <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --version<span style="color: #000000; font-weight: bold;">|</span>-v<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            print_version <span style="color: #007800;">$PROGNAME</span> <span style="color: #007800;">$VERSION</span>
            <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --interval<span style="color: #000000; font-weight: bold;">|</span>-i<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">interval</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --warning<span style="color: #000000; font-weight: bold;">|</span>-w<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">warn</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --critical<span style="color: #000000; font-weight: bold;">|</span>-c<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">crit</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Unknown argument: $1&quot;</span>
            print_help
            <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
    <span style="color: #000000; font-weight: bold;">esac</span>
    <span style="color: #7a0874; font-weight: bold;">shift</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
val_wcdiff<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #800000;">${warn}</span> <span style="color: #660033;">-gt</span> <span style="color: #800000;">${crit}</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">wcdiff</span>=<span style="color: #000000;">1</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
get_cpuvals<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #007800;">tmp1_cpu_user</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">'^cpu'</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">stat</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $2}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">tmp1_cpu_nice</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">'^cpu'</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">stat</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $3}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">tmp1_cpu_sys</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">'^cpu'</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">stat</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $4}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">tmp1_cpu_idle</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">'^cpu'</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">stat</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $5}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">tmp1_cpu_iowait</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">'^cpu'</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">stat</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $6}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">tmp1_cpu_irq</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">'^cpu'</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">stat</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $7}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">tmp1_cpu_softirq</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">'^cpu'</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">stat</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $8}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">tmp1_cpu_total</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #007800;">$tmp1_cpu_user</span> + <span style="color: #007800;">$tmp1_cpu_nice</span> + <span style="color: #007800;">$tmp1_cpu_sys</span> + \
<span style="color: #007800;">$tmp1_cpu_idle</span> + <span style="color: #007800;">$tmp1_cpu_iowait</span> + <span style="color: #007800;">$tmp1_cpu_irq</span> + <span style="color: #007800;">$tmp1_cpu_softirq</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
    <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #007800;">$interval</span>
&nbsp;
    <span style="color: #007800;">tmp2_cpu_user</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">'^cpu'</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">stat</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $2}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">tmp2_cpu_nice</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">'^cpu'</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">stat</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $3}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">tmp2_cpu_sys</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">'^cpu'</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">stat</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $4}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">tmp2_cpu_idle</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">'^cpu'</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">stat</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $5}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">tmp2_cpu_iowait</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">'^cpu'</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">stat</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $6}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">tmp2_cpu_irq</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">'^cpu'</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">stat</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $7}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">tmp2_cpu_softirq</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">'^cpu'</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">stat</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $8}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">tmp2_cpu_total</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #007800;">$tmp2_cpu_user</span> + <span style="color: #007800;">$tmp2_cpu_nice</span> + <span style="color: #007800;">$tmp2_cpu_sys</span> + \
<span style="color: #007800;">$tmp2_cpu_idle</span> + <span style="color: #007800;">$tmp2_cpu_iowait</span> + <span style="color: #007800;">$tmp2_cpu_irq</span> + <span style="color: #007800;">$tmp2_cpu_softirq</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
    <span style="color: #007800;">diff_cpu_user</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${tmp2_cpu_user}</span> - <span style="color: #007800;">${tmp1_cpu_user}</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span> -l<span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">diff_cpu_nice</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${tmp2_cpu_nice}</span> - <span style="color: #007800;">${tmp1_cpu_nice}</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span> -l<span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">diff_cpu_sys</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${tmp2_cpu_sys}</span> - <span style="color: #007800;">${tmp1_cpu_sys}</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span> -l<span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">diff_cpu_idle</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${tmp2_cpu_idle}</span> - <span style="color: #007800;">${tmp1_cpu_idle}</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span> -l<span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">diff_cpu_iowait</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${tmp2_cpu_iowait}</span> - <span style="color: #007800;">${tmp1_cpu_iowait}</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span> -l<span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">diff_cpu_irq</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${tmp2_cpu_irq}</span> - <span style="color: #007800;">${tmp1_cpu_irq}</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span> -l<span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">diff_cpu_softirq</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${tmp2_cpu_softirq}</span> - <span style="color: #007800;">${tmp1_cpu_softirq}</span>&quot;</span> \
<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span> -l<span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">diff_cpu_total</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${tmp2_cpu_total}</span> - <span style="color: #007800;">${tmp1_cpu_total}</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span> -l<span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
    <span style="color: #007800;">cpu_user</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;scale=2; (1000*<span style="color: #007800;">${diff_cpu_user}</span>/<span style="color: #007800;">${diff_cpu_total}</span>+5)/10&quot;</span> \
<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/^\./0./'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">cpu_nice</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;scale=2; (1000*<span style="color: #007800;">${diff_cpu_nice}</span>/<span style="color: #007800;">${diff_cpu_total}</span>+5)/10&quot;</span> \
<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/^\./0./'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">cpu_sys</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;scale=2; (1000*<span style="color: #007800;">${diff_cpu_sys}</span>/<span style="color: #007800;">${diff_cpu_total}</span>+5)/10&quot;</span> \
<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/^\./0./'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">cpu_idle</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;scale=2; (1000*<span style="color: #007800;">${diff_cpu_idle}</span>/<span style="color: #007800;">${diff_cpu_total}</span>+5)/10&quot;</span> \
<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/^\./0./'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">cpu_iowait</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;scale=2; (1000*<span style="color: #007800;">${diff_cpu_iowait}</span>/<span style="color: #007800;">${diff_cpu_total}</span>+5)\<span style="color: #000099; font-weight: bold;">\
</span>/10&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/^\./0./'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">cpu_irq</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;scale=2; (1000*<span style="color: #007800;">${diff_cpu_irq}</span>/<span style="color: #007800;">${diff_cpu_total}</span>+5)/10&quot;</span> \
<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/^\./0./'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">cpu_softirq</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;scale=2; (1000*<span style="color: #007800;">${diff_cpu_softirq}</span>/<span style="color: #007800;">${diff_cpu_total}</span>\<span style="color: #000099; font-weight: bold;">\
</span>+5)/10&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/^\./0./'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">cpu_total</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;scale=2; (1000*<span style="color: #007800;">${diff_cpu_total}</span>/<span style="color: #007800;">${diff_cpu_total}</span>+5)\<span style="color: #000099; font-weight: bold;">\
</span>/10&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/^\./0./'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">cpu_usage</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;(<span style="color: #007800;">${cpu_user}</span>+<span style="color: #007800;">${cpu_nice}</span>+<span style="color: #007800;">${cpu_sys}</span>+<span style="color: #007800;">${cpu_iowait}</span>+\<span style="color: #000099; font-weight: bold;">\
</span><span style="color: #007800;">${cpu_irq}</span>+<span style="color: #007800;">${cpu_softirq}</span>)/1&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
do_output<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #007800;">output</span>=<span style="color: #ff0000;">&quot;user: <span style="color: #007800;">${cpu_user}</span>, nice: <span style="color: #007800;">${cpu_nice}</span>, sys: <span style="color: #007800;">${cpu_sys}</span>, <span style="color: #000099; font-weight: bold;">\
</span>iowait: <span style="color: #007800;">${cpu_iowait}</span>, irq: <span style="color: #007800;">${cpu_irq}</span>, softirq: <span style="color: #007800;">${cpu_softirq}</span> <span style="color: #000099; font-weight: bold;">\
</span>idle: <span style="color: #007800;">${cpu_idle}</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
do_perfdata<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #007800;">perfdata</span>=<span style="color: #ff0000;">&quot;'user'=<span style="color: #007800;">${cpu_user}</span> 'nice'=<span style="color: #007800;">${cpu_nice}</span> 'sys'=<span style="color: #007800;">${cpu_sys}</span> <span style="color: #000099; font-weight: bold;">\
</span>'softirq'=<span style="color: #007800;">${cpu_softirq}</span> 'iowait'=<span style="color: #007800;">${cpu_iowait}</span> 'irq'=<span style="color: #007800;">${cpu_irq}</span> <span style="color: #000099; font-weight: bold;">\
</span>'idle'=<span style="color: #007800;">${cpu_idle}</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warn</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$crit</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
    val_wcdiff
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$wcdiff</span>&quot;</span> = <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Please adjust your warning/critical thresholds. The warning\<span style="color: #000099; font-weight: bold;">\
</span>must be lower than the critical level!&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
get_cpuvals
do_output
do_perfdata
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warn</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$crit</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$cpu_usage</span>&quot;</span> <span style="color: #660033;">-ge</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warn</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$cpu_usage</span>&quot;</span> <span style="color: #660033;">-lt</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$crit</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;WARNING - <span style="color: #007800;">${output}</span> | <span style="color: #007800;">${perfdata}</span>&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_WR</span>
    <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$cpu_usage</span>&quot;</span> <span style="color: #660033;">-ge</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$crit</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;CRITICAL - <span style="color: #007800;">${output}</span> | <span style="color: #007800;">${perfdata}</span>&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_CR</span>
    <span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;OK - <span style="color: #007800;">${output}</span> | <span style="color: #007800;">${perfdata}</span>&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_OK</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">else</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;OK - <span style="color: #007800;">${output}</span> | <span style="color: #007800;">${perfdata}</span>&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_OK</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#   This program is free software; you can redistribute it and/or modify
</span><span style="color: #666666; font-style: italic;">#   it under the terms of the GNU General Public License as published by
</span><span style="color: #666666; font-style: italic;">#   the Free Software Foundation; either version 2 of the License, or
</span><span style="color: #666666; font-style: italic;">#   (at your option) any later version.
</span><span style="color: #666666; font-style: italic;">#
</span><span style="color: #666666; font-style: italic;">#   This program is distributed in the hope that it will be useful,
</span><span style="color: #666666; font-style: italic;">#   but WITHOUT ANY WARRANTY; without even the implied warranty of
</span><span style="color: #666666; font-style: italic;">#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
</span><span style="color: #666666; font-style: italic;">#   GNU General Public License for more details.
</span><span style="color: #666666; font-style: italic;">#
</span><span style="color: #666666; font-style: italic;">#   You should have received a copy of the GNU General Public License
</span><span style="color: #666666; font-style: italic;">#   along with this program; if not, write to the Free Software
</span><span style="color: #666666; font-style: italic;">#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
</span>
<span style="color: #666666; font-style: italic;">#   PNP Template for check_cpu.sh
</span><span style="color: #666666; font-style: italic;">#   Author: Mike Adolphs (http://www.matejunkie.com/
</span>
<span style="color: #000088;">$opt</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;--vertical-label <span style="color: #000099; font-weight: bold;">\&quot;</span>CPU [%]<span style="color: #000099; font-weight: bold;">\&quot;</span> -u 100 -l 0 -r --title <span style="color: #000099; font-weight: bold;">\&quot;</span>CPU Usage for <span style="color: #006699; font-weight: bold;">$hostname</span> / <span style="color: #006699; font-weight: bold;">$servicedesc</span><span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>  <span style="color: #0000ff;">&quot;DEF:used=<span style="color: #006699; font-weight: bold;">$rrdfile</span>:<span style="color: #006699; font-weight: bold;">$DS[1]</span>:AVERAGE &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span>  <span style="color: #0000ff;">&quot;DEF:nice=<span style="color: #006699; font-weight: bold;">$rrdfile</span>:<span style="color: #006699; font-weight: bold;">$DS[2]</span>:AVERAGE &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span>  <span style="color: #0000ff;">&quot;DEF:sys=<span style="color: #006699; font-weight: bold;">$rrdfile</span>:<span style="color: #006699; font-weight: bold;">$DS[3]</span>:AVERAGE &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span>  <span style="color: #0000ff;">&quot;DEF:iowait=<span style="color: #006699; font-weight: bold;">$rrdfile</span>:<span style="color: #006699; font-weight: bold;">$DS[4]</span>:AVERAGE &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span>  <span style="color: #0000ff;">&quot;DEF:irq=<span style="color: #006699; font-weight: bold;">$rrdfile</span>:<span style="color: #006699; font-weight: bold;">$DS[5]</span>:AVERAGE &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span>  <span style="color: #0000ff;">&quot;DEF:softirq=<span style="color: #006699; font-weight: bold;">$rrdfile</span>:<span style="color: #006699; font-weight: bold;">$DS[6]</span>:AVERAGE &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span>  <span style="color: #0000ff;">&quot;DEF:idle=<span style="color: #006699; font-weight: bold;">$rrdfile</span>:<span style="color: #006699; font-weight: bold;">$DS[7]</span>:AVERAGE &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;COMMENT:<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>tLAST<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>tAVERAGE<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>tMAX<span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;AREA:used#E80C3E:<span style="color: #000099; font-weight: bold;">\&quot;</span>user<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span>:STACK &quot;</span> <span style="color: #339933;">;</span> 
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:used:LAST:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #009933; font-weight: bold;">%%</span><span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:used:AVERAGE:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:used:MAX:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;AREA:nice#E8630C:<span style="color: #000099; font-weight: bold;">\&quot;</span>nice<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span>:STACK &quot;</span> <span style="color: #339933;">;</span> 
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:nice:LAST:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #009933; font-weight: bold;">%%</span><span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:nice:AVERAGE:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:nice:MAX:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;AREA:sys#008000:<span style="color: #000099; font-weight: bold;">\&quot;</span>sys<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\&quot;</span>:STACK &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:sys:LAST:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #009933; font-weight: bold;">%%</span><span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:sys:AVERAGE:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:sys:MAX:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;AREA:iowait#0CE84D:<span style="color: #000099; font-weight: bold;">\&quot;</span>iowait<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span>:STACK &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:iowait:LAST:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #009933; font-weight: bold;">%%</span><span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:iowait:AVERAGE:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:iowait:MAX:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;AREA:irq#3E00FF:<span style="color: #000099; font-weight: bold;">\&quot;</span>irq<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\&quot;</span>:STACK &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:irq:LAST:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #009933; font-weight: bold;">%%</span><span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:irq:AVERAGE:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:irq:MAX:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;AREA:softirq#1CC8E8:<span style="color: #000099; font-weight: bold;">\&quot;</span>softirq<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span>:STACK &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:softirq:LAST:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #009933; font-weight: bold;">%%</span><span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:softirq:AVERAGE:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:softirq:MAX:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;AREA:idle#FFFF00:<span style="color: #000099; font-weight: bold;">\&quot;</span>idle<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span>:STACK &quot;</span> <span style="color: #339933;">;</span> 
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:idle:LAST:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #009933; font-weight: bold;">%%</span><span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:idle:AVERAGE:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:idle:MAX:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h3>The License</h3>
<p><a href="http://www.matejunkie.com/wp-content/uploads/2009/05/check_cpu_example02.png"><img class="alignright size-thumbnail wp-image-973" title="check_cpu_example02" src="http://www.matejunkie.com/wp-content/uploads/2009/05/check_cpu_example02-150x150.png" alt="check_cpu_example02" width="150" height="150" /></a>As always this little script is ment to be sh-compliant and released under the terms of the GPL Version 2 only. Feel free to subscribe via rss to get updates on this one. More options will be added in the future.<br />
I&#8217;ll probably add an option to make use of iostat or top and to calculate utilization per CPU soon so that you&#8217;re able to choose your own way.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matejunkie.com/cpu-check-plugin-for-nagios/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Visualizing spam</title>
		<link>http://www.matejunkie.com/visualizing-spam/</link>
		<comments>http://www.matejunkie.com/visualizing-spam/#comments</comments>
		<pubDate>Sun, 08 Feb 2009 03:10:39 +0000</pubDate>
		<dc:creator>Mike Adolphs</dc:creator>
				<category><![CDATA[Binary Talks]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[geoip]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[google maps]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[spam]]></category>

		<guid isPermaLink="false">http://www.matejunkie.net//?p=686</guid>
		<description><![CDATA[After yesterday&#8217;s bauble with geoiplookup I was thinking about a more appropriate use of looking up the location of an IP. So what&#8217;s better than visualizing the areas of the world where most spam comes from, I guessed. Therefore I took a look at the IX&#8217;s blacklist project NiX Spam and downloaded a snapshot of [...]]]></description>
			<content:encoded><![CDATA[<p>After yesterday&#8217;s bauble with geoiplookup I was thinking about a more appropriate use of looking up the location of an IP. So what&#8217;s better than visualizing the areas of the world where most spam comes from, I guessed.</p>
<p>Therefore I took a look at the IX&#8217;s blacklist project <a title="NiX Spam" href="http://www.heise.de/ix/nixspam/dnsbl_en/" target="_blank">NiX Spam</a> and downloaded a snapshot of the <a title="NiX Spam Blacklist snapshot" href="http://www.ix.de/nixspam/nixspam.blackmatches" target="_blank">blacklist&#8217;s content</a> (save, right click as&#8230; you&#8217;ve been warned!) which includes a maximum of 40.000 IP addresses. The plain text file comes with a timestamp and the blacklisted IP addresses.<br />
After some more or less simple batch-processing I&#8217;ve had a file including all the relevant GeoIP information, the longitude and latitude values of each IP. What was missing was a method to display them in a graphical way, e.g. on a world map.</p>
<p>Couldn&#8217;t be Google Maps a solution with its well documented and comprehensive <a title="Google Maps API documentation" href="http://code.google.com/apis/maps/" target="_blank">API</a>? So I digged into the Google Maps API and after an hour I was able to change the batch-processing in a way to create the proper output for creating markers on a map, including the well-know tooltip balloons including IP address and timestamp after clicking on a marker.</p>
<p>First tests with a few dozens data sets went just fine, but in this very special moment right before crossing the finish line, my browser decided to stop working for a couple of minutes.<br />
It turned out that 40.000 markers, combined with a tooltip, was way too much data to be handled by the browser. Navigating or zooming the map just wasn&#8217;t possible. Even after I&#8217;ve reduced the amount of data sets to 10.000 it was slow as hell.</p>
<p><a href="http://www.matejunkie.com/wp-content/uploads/2009/02/googleearth_10000markers.png"><img class="size-thumbnail wp-image-688 alignleft" style="margin-left: 6px; margin-right: 6px;" title="Google Maps - 10.000 markers" src="http://www.matejunkie.com/wp-content/uploads/2009/02/googleearth_10000markers-150x150.png" alt="Google Maps - 10.000 markers" width="200" height="200" /></a>Besides the performance issues it turned out that the visualization is almost useless because of the many overlapping markers as you can see on the left. Spammer mostly use botnets,  thousands of Zombie PCs, distributed all over the world.<br />
Sure, it is possible to see areas with a much higher density than other regions, but these are also the regions where internet is accessible from almost everywhere. It&#8217;s easily explainable that there are less Spammers in the australian outback or South America&#8217;s jungle.</p>
<p>But each drawback has also its advantages. Besides the fact that I gained more knowledge of vim, sed and awk once more, it won&#8217;t be too hard to complete this.<br />
With a slightly different approach, e.g. abandoning the longitude/latitude data and prefering the city&#8217;s name, it&#8217;d be possible to present shrinking or growing markers based on the amount of machines in a specific city. This would drastically reduce the amount of markers and is not that hard to implement.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matejunkie.com/visualizing-spam/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
