<?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; kernel</title>
	<atom:link href="http://www.matejunkie.com/tag/kernel/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>Memory check plugin for Nagios</title>
		<link>http://www.matejunkie.com/memory-check-plugin-for-nagios/</link>
		<comments>http://www.matejunkie.com/memory-check-plugin-for-nagios/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 10:50:30 +0000</pubDate>
		<dc:creator>Mike Adolphs</dc:creator>
				<category><![CDATA[Binary Talks]]></category>
		<category><![CDATA[gplv2]]></category>
		<category><![CDATA[kernel]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[nagios]]></category>
		<category><![CDATA[network monitoring]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[shell scripting]]></category>

		<guid isPermaLink="false">http://www.matejunkie.net//?p=752</guid>
		<description><![CDATA[As I&#8217;m currently reworking our large, distributed network monitoring solution, I&#8217;m also integrating own plugins for various purposes. The beginning is made by a check plugin for memory consumption on Linux hosts which checks /proc/meminfo directly instead of other checks which usually use frontends like free or top. Besides that, there&#8217;s really no magic (and [...]]]></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" />As I&#8217;m currently reworking our large, distributed network monitoring solution, I&#8217;m also integrating own plugins for various purposes. The beginning is made by a check plugin for memory consumption on Linux hosts which checks /proc/meminfo directly instead of <a title="Nagios Exchange" href="http://www.nagiosexchange.org/" target="_blank">other checks</a> which usually use frontends like free or top. Besides that, there&#8217;s really no magic (and parsing /proc/meminfo isn&#8217;t magic as well). You&#8217;re able to switch between kilobyte and percentage output, defining warning and critical levels is also possible.<br />
It is sh-compliant, released under the terms of the GPLv2 and as every well written shell script there&#8217;s no need to provide any argument at all. For full help use -h or &#8211;help.</p>
<p>Give it a try if you like and let me know if it doesn&#8217;t work as intended.<br />
Please copy the content below. The script will be reworked and uploaded to Nagios and MonitoringExchange after my vacation at the beginning of July.</p>

<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; version 2 of the License only.</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;">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;">wcdiff</span>=<span style="color: #000000;">0</span>
<span style="color: #007800;">wclvls</span>=<span style="color: #000000;">0</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;
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 the current memory usage via&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;/proc/meminfo. It should work on almost every system where you're&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;able to cat /proc/meminfo. The script itself is written sh-compliant&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;and free software under the terms of the GPLv2.&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> -s/--style kb/perc [-w/--warning] [-c/--critical]&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;  -s/--style)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     You're able to set the output to kilobyte (kb) or percentage&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     (perc) values. Please note that other values will result in&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     termination. Default is: kb&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;     Warning level in kb or percent for the amount of used memory.&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Note that when the style is set to percentage, only values&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     betweeen 0 and 100 are allowed. 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;     Critical level in kb or percent for the amount of used memory.&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Note that when the style is set to percentage, only values&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     between 0 and 100 are allowed. 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;
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;">${lv_wr}</span> <span style="color: #660033;">-gt</span> <span style="color: #800000;">${lv_cr}</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;
val_wclvls<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: #007800;">$style</span> = <span style="color: #ff0000;">&quot;perc&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;">$lv_wr</span>&quot;</span> <span style="color: #660033;">-lt</span> <span style="color: #000000;">0</span> <span style="color: #660033;">-o</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$lv_wr</span>&quot;</span> <span style="color: #660033;">-gt</span> <span style="color: #000000;">100</span> <span style="color: #660033;">-o</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$lv_cr</span>&quot;</span> <span style="color: #660033;">-lt</span> <span style="color: #000000;">0</span> <span style="color: #660033;">-o</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$lv_cr</span>&quot;</span> <span style="color: #660033;">-gt</span> <span style="color: #000000;">100</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>
            val_wcdiff
        <span style="color: #000000; font-weight: bold;">fi</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>                                                                                      
&nbsp;
<span style="color: #007800;">style</span>=<span style="color: #ff0000;">&quot;kb&quot;</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>
        --style<span style="color: #000000; font-weight: bold;">|</span>-s<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">style</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;">lv_wr</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;">lv_cr</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;
<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;">$lv_wr</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;">$lv_cr</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
    val_wcdiff
    val_wclvls
<span style="color: #000000; font-weight: bold;">fi</span>                                   
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$wcdiff</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 levels. The critical level must be higher than the warning level!&quot;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$wclvls</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;Warning and critical level values must be between 0 and 100.&quot;</span>
    <span style="color: #000000; font-weight: bold;">fi</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>                                                                                        
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$wclvls</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;Warning and critical level values must be between 0 and 100.&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>                                                                     
&nbsp;
<span style="color: #007800;">MEM_TOTAL</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;^MemTotal&quot;</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>meminfo<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;">TMP_MEM_FREE</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;^MemFree&quot;</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>meminfo<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;">TMP_MEM_USED</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #007800;">$MEM_TOTAL</span> - <span style="color: #007800;">$TMP_MEM_FREE</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">BUFFERS</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;^Buffers&quot;</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>meminfo<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;">CACHED</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;^Cached&quot;</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>meminfo<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>       
&nbsp;
<span style="color: #007800;">P_MEM_FREE</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;">$TMP_MEM_FREE</span> / <span style="color: #007800;">$MEM_TOTAL</span> * 100&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-9][0-9]//'</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">P_MEM_USED</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;scale=0; 100 - <span style="color: #007800;">$P_MEM_FREE</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: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$style</span> = <span style="color: #ff0000;">&quot;kb&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: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$lv_wr</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;">$lv_cr</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: #800000;">${TMP_MEM_USED}</span> <span style="color: #660033;">-ge</span> <span style="color: #800000;">${lv_wr}</span> <span style="color: #660033;">-a</span> <span style="color: #800000;">${TMP_MEM_USED}</span> <span style="color: #660033;">-lt</span> <span style="color: #800000;">${lv_cr}</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 - Total: <span style="color: #007800;">$MEM_TOTAL</span> kb, Used: <span style="color: #007800;">$TMP_MEM_USED</span> kb, Free: <span style="color: #007800;">$TMP_MEM_FREE</span> kb | 'mem_total'=<span style="color: #007800;">$MEM_TOTAL</span> 'mem_used'=<span style="color: #007800;">$TMP_MEM_USED</span>;<span style="color: #007800;">$lv_wr</span>;<span style="color: #007800;">$lv_cr</span> 'mem_free'=<span style="color: #007800;">$TMP_MEM_FREE</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: #800000;">${TMP_MEM_USED}</span> <span style="color: #660033;">-ge</span> <span style="color: #800000;">${lv_cr}</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 - Total: <span style="color: #007800;">$MEM_TOTAL</span> kb, Used: <span style="color: #007800;">$TMP_MEM_USED</span> kb, Free: <span style="color: #007800;">$TMP_MEM_FREE</span> kb | 'mem_total'=<span style="color: #007800;">$MEM_TOTAL</span> 'mem_used'=<span style="color: #007800;">$TMP_MEM_USED</span>;<span style="color: #007800;">$lv_wr</span>;<span style="color: #007800;">$lv_cr</span> 'mem_free'=<span style="color: #007800;">$TMP_MEM_FREE</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 - Total: <span style="color: #007800;">$MEM_TOTAL</span> kb, Used: <span style="color: #007800;">$TMP_MEM_USED</span> kb, Free: <span style="color: #007800;">$TMP_MEM_FREE</span> kb | 'mem_total'=<span style="color: #007800;">$MEM_TOTAL</span> 'mem_used'=<span style="color: #007800;">$TMP_MEM_USED</span>;<span style="color: #007800;">$lv_wr</span>;<span style="color: #007800;">$lv_cr</span> 'mem_free'=<span style="color: #007800;">$TMP_MEM_FREE</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 - Total: <span style="color: #007800;">$MEM_TOTAL</span> kb, Used: <span style="color: #007800;">$TMP_MEM_USED</span> kb, Free: <span style="color: #007800;">$TMP_MEM_FREE</span> kb | 'mem_total'=<span style="color: #007800;">$MEM_TOTAL</span> 'mem_used'=<span style="color: #007800;">$TMP_MEM_USED</span> 'mem_free'=<span style="color: #007800;">$TMP_MEM_FREE</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;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$style</span> = <span style="color: #ff0000;">&quot;perc&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: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$lv_wr</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;">$lv_cr</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: #800000;">${P_MEM_USED}</span> <span style="color: #660033;">-ge</span> <span style="color: #800000;">${lv_wr}</span> <span style="color: #660033;">-a</span> <span style="color: #800000;">${P_MEM_USED}</span> <span style="color: #660033;">-lt</span> <span style="color: #800000;">${lv_cr}</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 - Used: <span style="color: #007800;">$P_MEM_USED</span>%, Free: <span style="color: #007800;">$P_MEM_FREE</span>% | 'mem_used'=<span style="color: #007800;">$P_MEM_USED</span>;<span style="color: #007800;">$lv_wr</span>;<span style="color: #007800;">$lv_cr</span> 'mem_free'=<span style="color: #007800;">$P_MEM_FREE</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: #800000;">${P_MEM_USED}</span> <span style="color: #660033;">-ge</span> <span style="color: #800000;">${lv_cr}</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 - Used: <span style="color: #007800;">$P_MEM_USED</span>%, Free: <span style="color: #007800;">$P_MEM_FREE</span>% | 'mem_used'=<span style="color: #007800;">$P_MEM_USED</span>;<span style="color: #007800;">$lv_wr</span>;<span style="color: #007800;">$lv_cr</span> 'mem_free'=<span style="color: #007800;">$P_MEM_FREE</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 - Used: <span style="color: #007800;">$P_MEM_USED</span>%, Free: <span style="color: #007800;">$P_MEM_FREE</span>% | 'mem_used'=<span style="color: #007800;">$P_MEM_USED</span>;<span style="color: #007800;">$lv_wr</span>;<span style="color: #007800;">$lv_cr</span> 'mem_free'=<span style="color: #007800;">$P_MEM_FREE</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 - Used: <span style="color: #007800;">$P_MEM_USED</span>%, Free: <span style="color: #007800;">$P_MEM_FREE</span>% | 'mem_used'=<span style="color: #007800;">$P_MEM_USED</span> 'mem_free'=<span style="color: #007800;">$P_MEM_FREE</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;Style (-s) must be either kb (kilobyte) or perc (for percent). kb is&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;being used as the default behavior when you don't provide the -s option.&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;For more information try -h or --help!&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></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.matejunkie.com/memory-check-plugin-for-nagios/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Magic SysRq &#8211; REISUB</title>
		<link>http://www.matejunkie.com/magic-sysrq-reisub/</link>
		<comments>http://www.matejunkie.com/magic-sysrq-reisub/#comments</comments>
		<pubDate>Mon, 09 Feb 2009 03:40:35 +0000</pubDate>
		<dc:creator>Mike Adolphs</dc:creator>
				<category><![CDATA[Binary Talks]]></category>
		<category><![CDATA[kernel]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[magic sysrq]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[reisub]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[xorg]]></category>

		<guid isPermaLink="false">http://www.matejunkie.net//?p=697</guid>
		<description><![CDATA[Ever encoutered a frozen X-Server without the possibility to switch to another console or a rare, but nasty kernel panic? Probably and I guess the majority of the people hit the power button in those cases risking data loss. This is not necessary. There are other ways to restart a frozen Linux system! The kernel [...]]]></description>
			<content:encoded><![CDATA[<p>Ever encoutered a frozen X-Server without the possibility to switch to another console or a rare, but nasty kernel panic? Probably and I guess the majority of the people hit the power button in those cases risking data loss.</p>
<p>This is not necessary. There are other ways to restart a frozen Linux system!</p>
<p>The kernel has a feature called &#8220;<a title="Linux Kernel documentation" href="http://www.mjmwired.net/kernel/Documentation/sysrq.txt" target="_blank">Magic System Request Keys</a>&#8221; &#8211; if it was compiled with the CONFIG_MAGIC_SYSRQ option though. It is available via ALT+PRINT on most systems and provides various low level commands to safely turn of or reboot your computer in case of a failure.</p>
<p>If you want to know whether this feature is available on your machine, ask /proc for it. If it returns a 1 Magic SysRq is active, a 0 indicates that it&#8217;s not.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user<span style="color: #000000; font-weight: bold;">@</span>server:~$ <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>kernel<span style="color: #000000; font-weight: bold;">/</span>sysrq
<span style="color: #000000;">1</span></pre></div></div>

<p>Hold down ALT+PRINT and type slowly REISUB to restart your system. Hold down ALT+PRINT and type REISUO to turn it off.</p>
<p>A short note on what REISUB or REISUO does:</p>
<ol>
<li><strong>R</strong> &#8211; Switches the keyboard from raw to XLATE mode (detatching from the X-Server)</li>
<li><strong>E</strong> &#8211; Sending a SIGTERM to all processes except INIT</li>
<li><strong>I</strong> &#8211; Sending a SIGKILL to all processes except INIT (and that&#8217;s why to type REISUB slowly)</li>
<li><strong>S</strong> &#8211; Syncs all data in the cache to mounted partitions</li>
<li><strong>U</strong> &#8211; Unmounts all mounted partitions and remounts them read-only</li>
<li><strong>B</strong> &#8211; Reboot the system immediately without unmounting or syncing mounted partitions<br />
<strong>or</strong><br />
<strong>O</strong> &#8211; Shut down the system immediately without unmounting or syncing mounted partitions</li>
</ol>
<p>Be aware of the fact that the feature is currently broken in Ubuntu 8.10 because of a problem regarding kbd, evdev and 8.10&#8242;s xserver version. It only works from a text console, therefore not on the X-Server.<br />
It is possible to reconfigure the xorg.conf from kbd to evdev like in the following, but no guarantees:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Section <span style="color: #ff0000;">&quot;InputDevice&quot;</span>
	Identifier	<span style="color: #ff0000;">&quot;Generic Keyboard&quot;</span>
	Driver		<span style="color: #ff0000;">&quot;kbd&quot;</span>
	Option		<span style="color: #ff0000;">&quot;XkbRules&quot;</span>	<span style="color: #ff0000;">&quot;xorg&quot;</span>
	Option		<span style="color: #ff0000;">&quot;XkbModel&quot;</span>	<span style="color: #ff0000;">&quot;pc105&quot;</span>
	Option		<span style="color: #ff0000;">&quot;XkbLayout&quot;</span>	<span style="color: #ff0000;">&quot;de&quot;</span>
EndSection</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Section <span style="color: #ff0000;">&quot;ServerLayout&quot;</span>
        ...
	InputDevice	<span style="color: #ff0000;">&quot;Generic Keyboard&quot;</span>
	Option		<span style="color: #ff0000;">&quot;AutoAddDevices&quot;</span>	<span style="color: #ff0000;">&quot;false&quot;</span>
EndSection</pre></div></div>

<p>It&#8217;ll be fixed in 9.04 coming this April as stated in the <a title="Launchpad Ubuntu - Bug #305762" href="https://bugs.launchpad.net/ubuntu/+source/xorg/+bug/305762" target="_blank">bug description</a> on Launchpad.</p>
<p>One last hint: If your machine doesn&#8217;t have a PRINT/SysRq key and you&#8217;re still able to access the console, yu may also send the commands via echo to the sysrq-trigger as seen in the example below:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user<span style="color: #000000; font-weight: bold;">@</span>server:~$ <span style="color: #7a0874; font-weight: bold;">echo</span> r <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">tee</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>sysrq-trigger</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.matejunkie.com/magic-sysrq-reisub/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
