Skip to content

Instantly share code, notes, and snippets.

@arekinath
Created August 18, 2012 06:32
Show Gist options
  • Save arekinath/3384873 to your computer and use it in GitHub Desktop.
Save arekinath/3384873 to your computer and use it in GitHub Desktop.
Patch for observium nginx app monitor

This patch adds the ability for the Observium (http://www.observium.org/) nginx app monitor to get its data directly from PHP, rather than the standard path via SNMP or via the unix-agent (which doesn't work properly on some operating systems)

For the corresponding nginx config, see http://www.observium.org/wiki/Application/nginx (but make it also accessible to the IP address of your Observium host)

--- includes/polling/applications/nginx.inc.php (revision 3366)
+++ includes/polling/applications/nginx.inc.php (working copy)
@@ -1,18 +1,31 @@
<?php
+$active = $reading = $writing = $waiting = $req = 0;
+
if (!empty($agent_data['app']['nginx']))
{
$nginx = $agent_data['app']['nginx'];
+ list($active, $reading, $writing, $waiting, $req) = explode("\n", $nginx);
} else {
# Polls nginx statistics from script via SNMP
- $nginx = snmp_get($device, "nsExtendOutputFull.5.110.103.105.110.120", "-Ovq", "NET-SNMP-EXTEND-MIB");
+ $data = file_get_contents("http://{$device['hostname']}/nginx-status");
+
+ preg_match("/Active connections:[ ]+([0-9]+)/", $data, $matches);
+ $active = $matches[1];
+
+ preg_match("/Reading:[ ]+([0-9]+).*Writing:[ ]+([0-9]+).*Waiting:[ ]+([0-9]+)/", $data, $matches);
+ $reading = $matches[1];
+ $writing = $matches[2];
+ $waiting = $matches[3];
+
+ preg_match("/[ ]+([0-9]+)[ ]+([0-9]+)[ ]+([0-9]+)/", $data, $matches);
+ $req = $matches[3];
}
$nginx_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/app-nginx-".$app['app_id'].".rrd";
echo(" nginx statistics\n");
-list($active, $reading, $writing, $waiting, $req) = explode("\n", $nginx);
if (!is_file($nginx_rrd))
{
rrdtool_create ($nginx_rrd, "--step 300 \
@luvpreetsingh
Copy link

Where do we have save this patch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment