<?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>Linux, Programming, Telephony, Asterisk, Apache, Tips &#38; Tricks &#187; monit</title>
	<atom:link href="http://shahidz.com/tag/monit/feed/" rel="self" type="application/rss+xml" />
	<link>http://shahidz.com</link>
	<description>Passionate About Technology</description>
	<lastBuildDate>Sun, 10 Jan 2010 17:38:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Shell Script To Monit Swap Usage</title>
		<link>http://shahidz.com/shell-script-to-monit-swap-usage/</link>
		<comments>http://shahidz.com/shell-script-to-monit-swap-usage/#comments</comments>
		<pubDate>Fri, 02 Jan 2009 17:44:59 +0000</pubDate>
		<dc:creator>Shahid</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell Script]]></category>
		<category><![CDATA[cron. swap]]></category>
		<category><![CDATA[monit]]></category>
		<category><![CDATA[swap-usage]]></category>
		<category><![CDATA[system admin]]></category>

		<guid isPermaLink="false">http://shahidz.com/shell-script-to-monit-swap-usage/</guid>
		<description><![CDATA[Some time our system started to use more swap area even 100% of swap area and the system crashes. So for a System Admin it would be very helpful when they get informed if the system started to use more swap usage so that system admin can manage the server before crashing. So I wrote [...]]]></description>
			<content:encoded><![CDATA[<p>Some time our system started to use more swap area even 100% of swap area and the system crashes. So for a System Admin it would be very helpful when they get informed if the system started to use more swap usage so that system admin can manage the server before crashing. So I wrote a shell script which will Alert by send mail if the system started to use more that 70% of swap area.</p>
<pre>$ vim swap-usage.sh</pre>
<pre>#!/bin/sh
free -m | grep Swap | while read output;
do
  swap=$(echo $output | awk '{print $2}' )
  used=$(echo $output | awk '{ print $3 }' )
  freed=$(echo $output | awk '{ print $4 }' )
  echo "Swap : $swap"
  echo "Used : $used"
  echo "Free : $freed"
  usep=`expr $used \* 100 / $swap`
  echo $usep
  if [ $usep -ge 70 ]; then
    echo "Swap Usage Alert Total Swap: \"$swap\" Used: \"$used ($usep%)\" Free:
\"$freed\" on $(hostname) as on $(date)" |
     mail -s "Alert: Swap Usage space $usep%" mail1@example.com,mail2@example.com
  fi
done</pre>
<p>This script will send mails to the specified mails, if the system started to use more than 70% of  swap area. For continuously check the swap usage we need to set a cronjob for executing this script. So that the system should monit the swap usage by executing this script.</p>
<p>Edit the corntab file.</p>
<pre>$ sudo crontab -e</pre>
<p>Set the cronjob to to execute the script in every 15 Mints.</p>
<pre>*/15 * * * * ~/scripts/swap-usage.sh</pre>
<p>Restart the Cron</p>
<pre>$ sudo /etc/init.d/cron restart</pre>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fshahidz.com%2Fshell-script-to-monit-swap-usage%2F&amp;linkname=Shell%20Script%20To%20Monit%20Swap%20Usage"><img src="http://shahidz.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://shahidz.com/shell-script-to-monit-swap-usage/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Shell script to notify Hard disk space utilization</title>
		<link>http://shahidz.com/shell-script-to-notify-hard-disk-space-utilization/</link>
		<comments>http://shahidz.com/shell-script-to-notify-hard-disk-space-utilization/#comments</comments>
		<pubDate>Sat, 13 Dec 2008 16:15:33 +0000</pubDate>
		<dc:creator>Shahid</dc:creator>
				<category><![CDATA[Shell Script]]></category>
		<category><![CDATA[hardisk space]]></category>
		<category><![CDATA[monit]]></category>
		<category><![CDATA[notification]]></category>

		<guid isPermaLink="false">http://shahidz.com/shell-script-to-notify-hard-disk-space-utilization/</guid>
		<description><![CDATA[The below script will check the hard disk space usage, using the command du and send an email alert if any of the partition is using more than 85% of space.
vim disk-usage.sh
#!/bin/sh
df -H &#124; grep -vE '^Filesystem&#124;tmpfs&#124;cdrom' &#124; awk '{ print $5 " " $1 }' &#124; while read output;
do
  echo $output
  usep=$(echo [...]]]></description>
			<content:encoded><![CDATA[<p>The below script will check the hard disk space usage, using the command<em> du </em>and send an email alert if any of the partition is using more than 85% of space.</p>
<p>vim disk-usage.sh</p>
<pre>#!/bin/sh
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output;
do
  echo $output
  usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1  )
  partition=$(echo $output | awk '{ print $2 }' )
  if [ $usep -ge 85 ]; then
    echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" |
     mail -s "Alert: Almost out of disk space $usep%" example@example.com
  fi
done</pre>
<p>Set a cronjob to run this script.</p>
<pre>*/30 * * * * /bin/sh /path-to-file/disk-usage.sh</pre>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fshahidz.com%2Fshell-script-to-notify-hard-disk-space-utilization%2F&amp;linkname=Shell%20script%20to%20notify%20Hard%20disk%20space%20utilization"><img src="http://shahidz.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://shahidz.com/shell-script-to-notify-hard-disk-space-utilization/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Monit a service monitoring tool in linux</title>
		<link>http://shahidz.com/monit/</link>
		<comments>http://shahidz.com/monit/#comments</comments>
		<pubDate>Sun, 29 Jun 2008 10:30:58 +0000</pubDate>
		<dc:creator>Shahid</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[]]></category>
		<category><![CDATA[monit]]></category>
		<category><![CDATA[monitoring apache]]></category>
		<category><![CDATA[monitrc]]></category>

		<guid isPermaLink="false">http://shahidz.com/monit/</guid>
		<description><![CDATA[ Monit is a utility for managing and monitoring processes, files, directories and devices on a Unix system. Monit conducts automatic maintenance and repair and can execute meaningful causal actions in error situations. E.g. monit can start a process if it does not run, restart a process if it does not respond and stop a [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://shahidz.com/wp-content/uploads/2008/06/monit-logo.gif" alt="monit-logo.gif" /> <a href="http://www.tildeslash.com/monit/" title="Monit" target="_blank">Monit</a> is a utility for managing and monitoring processes, files, directories and devices on a Unix system. Monit conducts automatic maintenance and repair and can execute meaningful causal actions in error situations. E.g. monit can start a process if it does not run, restart a process if it does not respond and stop a process if it uses to much resources. You may use monit to monitor files, directories and devices for changes, such as timestamps changes, checksum changes or size changes.  Monit will monitor a service and in case of any problems monit will will raise an email alert.</p>
<p><strong>Install the package monit using apt on Ubuntu.</strong></p>
<pre>$ sudo apt-get install monit</pre>
<p>First edit the file  <strong>/etc/default/monit</strong> and change <strong>startup=0</strong> to  <strong>startup=1</strong>. The file should look like below text.</p>
<pre># Defaults for monit initscript
# sourced by /etc/init.d/monit
# installed at /etc/default/monit by maintainer scripts
# Fredrik Steen &lt;stone@debian.org&gt;
# You must set this variable to for monit to start

startup=1

# To change the intervals which monit should run uncomment# and change this variable.
# CHECK_INTERVALS=180</pre>
<p>Edit the monit configuration file<strong> /etc/monit/monitrc</strong> and uncomment the following lines</p>
<pre>$ sudo vim /etc/monit/monitrc</pre>
<p>Start monit in background (run as daemon) and check the services at 2-minute intervals.</p>
<pre>set daemon  120</pre>
<p>You can set the alert recipients here, which will receive the alert for each service. The event alerts may be restricted using the list.</p>
<pre>set alert abc@xyz.com                                   # receive all alerts
set alert hij@xyz.com only on { timeout }       # receive just service-</pre>
<p>Monit has an embedded webserver, which can be used to view the configuration, actual services parameters or manage the services using the web interface.</p>
<pre>set httpd port 2812 and
     use address localhost  # only accept connection from localhost
     allow localhost        # allow localhost to connect to the server and
     allow admin:monit      # require user 'admin' with password 'monit'</pre>
<p>Next session in the configuration file is where the monit monitors the services,  for that we need to specify the service which needs to be monitored. A sample example for monitoring apache is as follows.</p>
<pre>check process apache with pidfile /var/run/apache2.pid
    start program = "/etc/init.d/apache2 start"
    stop program  = "/etc/init.d/apache2 stop"
    if cpu &gt; 60% for 2 cycles then alert
    if cpu &gt; 80% for 5 cycles then restart
    if totalmem &gt; 200.0 MB for 5 cycles then restart
    if children &gt; 250 then restart
    if loadavg(5min) greater than 10 for 8 cycles then stop
    if 3 restarts within 5 cycles then timeout
    group server</pre>
<p>For more examples click <a href="http://www.tildeslash.com/monit/doc/examples.php" title="Monit Examples" target="_blank">here </a><br />
Next we will see some monit commonds.</p>
<p>To satrt monit</p>
<pre>$ sudo /etc/init.d/monit start</pre>
<p>To start the services which the monit is monitorin, sudo monit start all will start all the services in the monit configuration file, if specify a name insted of start all monit will start only the specified service.</p>
<pre>$ sudo monit start all
$ sudo monit start apache</pre>
<p>To get the status of monit services</p>
<pre>$ sudo monit status</pre>
<p>To get the summary of mont services</p>
<pre>$ sudo monit summary</pre>
<p>To stop all the services monitored my monit use <strong>stop all</strong>, or specify the name of the servive you need to stop</p>
<pre>$ sudo monit  stop all
$ sudo monit stop apache</pre>
<p>For more help click <a href="http://www.tildeslash.com/monit/doc/manual.php" target="_blank">here</a></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fshahidz.com%2Fmonit%2F&amp;linkname=Monit%20a%20service%20monitoring%20tool%20in%20linux"><img src="http://shahidz.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://shahidz.com/monit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
