04.02
Monitoring 18 servers during a live event isn’t an easy task, however there is a easy way to do create a dynamic page which will display you a status of desired servers using Nagios plugins, AJAX and a bit of PHP.
I’m running a cluster of 18 ec2 servers which are used for high capacity real time platform built by Monterosa (company which I work for), we are using Nagios and Munin for monitoring purposes however viewing all necessary data on one page in Nagios is impossible if you run that many servers and each of them has couple of monitors.
I’ve built a simple web page in PHP runing a loop which executes shell command running check_nrpe plugin from Nagios and printing output in browser window.
$hosts = array("host1.abc.com", "host2.abc.com");
foreach ($hosts as $host)
{
$load = shell_exec("/usr/local/nagios/libexec/check_nrpe -H $host -c check_load -a 5.0,4.0,3.0 10.0,6.0,4.0 | cut -d '|' -f 1");
echo "$load;
}
?>
This is good for two servers but not if you have to get status of 18 as it will take ages before you will see anything on your screen.
I started to thinking that I could find some AJAX lib which will load content dynamically and I found this.
Quick implementation made a huge difference:
Status script
First we need a page which will get status of desired host defined by parameter in URL.
$host = $_GET['host'];
$load = shell_exec("/usr/local/nagios/libexec/check_nrpe -H $host -c check_load -a 5.0,4.0,3.0 10.0,6.0,4.0 | cut -d '|' -f 1");
echo $load;
?>
This page will be pulled by AJAX dynamically from static HTML page. You will still have to wait before you will see results however static content will be displayed immediately and dynamic content will follow.
Status page
This page will load AJAX lib and request status for all servers.
CSS style to keep dynamic regions clear:
AJAX libs:
Placeholders:
Last thing is to call AJAX:
Whole page:
<html>
<head>
<title>Dynamic status</title>
<style type="text/css">
.clear {
clear: both;
}
</style>
<script src="js/ajax.js" type="text/javascript"></script>
<script src="js/ajax-dynamic-content.js" type="text/javascript"></script>
</head>
<body>
<div id="host1"><!-- Empty div for dynamic content --></div>
<div id="host2"><!-- Empty div for dynamic content --></div>
<script type="text/javascript">
ajax_loadContent('host1','status.php?host=host1.dns.com');
ajax_loadContent('host2','status.php?host=host2.dns.com');
</script>
</body>
</html>
Here is how the page works for cluster of 18 servers:
This can expand to more than one monitor per server and other types of tweaks as indications of error etc. Sky’s the limit
Good luck !
Hi,
You might want to look at Centreon at centreon.com. Nagios with style.
Marlin
I’ve seen it before but thanks for a link.
Very cool stuff, tnx
hi i wanted to ask how to make nagios to do some script in php im trying from this page
) then make a txt file… but somehow its not creating… can u help me?
http://www.saiweb.co.uk/nagios/nagios-customization-alerting-via-sms-or-anything-you-like
but no luck, please help me out.
for now im trying to run any script if serwer is down… for ex if wp.pl is down (rj45 cable off
I think what you need is event handler.
thx i will try to figure this out
I love the div id host name architecture you implemented, nice!!!
Thanks for the idea.