1
0
mirror of https://github.com/librenms/librenms.git synced 2024-10-07 16:52:45 +00:00

Add NGINX application type, graphing connections. Thanks to Ove

git-svn-id: http://www.observium.org/svn/observer/trunk@1722 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2010-10-22 18:14:59 +00:00
parent bffa075641
commit 458c65fcc2
7 changed files with 161 additions and 0 deletions
html
images/icons
includes/graphs/application
pages/device/apps
includes/polling/applications
scripts

Binary file not shown.

After

(image error) Size: 564 B

BIN
html/images/icons/nginx.png Normal file

Binary file not shown.

After

(image error) Size: 688 B

@ -0,0 +1,38 @@
<?php
include("includes/graphs/common.inc.php");
$nginx_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/app-nginx-".$app['app_id'].".rrd";
if(is_file($nginx_rrd)) {
$rrd_filename = $nginx_rrd;
}
$rrd_options .= ' DEF:a='.$rrd_filename.':Active:AVERAGE ';
$rrd_options .= ' DEF:b='.$rrd_filename.':Reading:AVERAGE ';
$rrd_options .= ' DEF:c='.$rrd_filename.':Writing:AVERAGE ';
$rrd_options .= ' DEF:d='.$rrd_filename.':Waiting:AVERAGE ';
$rrd_options .= 'COMMENT:"Connections Current Average Maximum\n" ';
$rrd_options .= "LINE1:a#22FF22:Active\ \ ";
$rrd_options .= 'GPRINT:a:LAST:"%6.2lf %s" ';
$rrd_options .= 'GPRINT:a:AVERAGE:"%6.2lf %s" ';
$rrd_options .= 'GPRINT:a:MAX:"%6.2lf %s\n" ';
$rrd_options .= 'LINE1.25:b#0022FF:Reading ';
$rrd_options .= 'GPRINT:b:LAST:"%6.2lf %s" ';
$rrd_options .= 'GPRINT:b:AVERAGE:"%6.2lf %s" ';
$rrd_options .= 'GPRINT:b:MAX:"%6.2lf %s\n" ';
$rrd_options .= 'LINE1.25:c#FF0000:Writing ';
$rrd_options .= 'GPRINT:c:LAST:"%6.2lf %s" ';
$rrd_options .= 'GPRINT:c:AVERAGE:"%6.2lf %s" ';
$rrd_options .= 'GPRINT:c:MAX:"%6.2lf %s\n" ';
$rrd_options .= 'LINE1.25:d#00AAAA:Waiting ';
$rrd_options .= 'GPRINT:d:LAST:"%6.2lf %s" ';
$rrd_options .= 'GPRINT:d:AVERAGE:"%6.2lf %s" ';
$rrd_options .= 'GPRINT:d:MAX:"%6.2lf %s\n" ';
?>

@ -0,0 +1,22 @@
<?php
include("includes/graphs/common.inc.php");
$nginx_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/app-nginx-".$app['app_id'].".rrd";
if(is_file($nginx_rrd)) {
$rrd_filename = $nginx_rrd;
}
$rrd_options .= ' -b 1000 ';
$rrd_options .= ' -l 0 ';
$rrd_options .= ' DEF:a='.$rrd_filename.':Requests:AVERAGE ';
$rrd_options .= 'COMMENT:"Requests Current Average Maximum\n" ';
$rrd_options .= "LINE2:a#22FF22:Requests\ \ ";
$rrd_options .= 'GPRINT:a:LAST:"%6.2lf %s" ';
$rrd_options .= 'GPRINT:a:AVERAGE:"%6.2lf %s" ';
$rrd_options .= 'GPRINT:a:MAX:"%6.2lf %s\n" ';
?>

@ -0,0 +1,27 @@
<?php
global $config;
$graphs = array('nginx_connections' => 'nginx Connections',
'nginx_req' => 'nginx requests');
foreach($graphs as $key => $text) {
$graph_type = $key;
$graph_array['height'] = "100";
$graph_array['width'] = "215";
$graph_array['to'] = $now;
$graph_array['id'] = $app['app_id'];
$graph_array['type'] = "application_".$key;
echo('<h3>'.$text.'</h3>');
echo("<tr bgcolor='$row_colour'><td colspan=5>");
include("includes/print-quadgraphs.inc.php");
echo("</td></tr>");
}
?>

@ -0,0 +1,37 @@
<?php
#Polls nginx statistics from script via SNMP
$nginx_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/app-nginx-".$app['app_id'].".rrd";
$nginx_cmd = $config['snmpget'] ." -m NET-SNMP-EXTEND-MIB -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'];
$nginx_cmd .= " nsExtendOutputFull.5.110.103.105.110.120";
$nginx = shell_exec($nginx_cmd);
echo " nginx statistics\n";
list($active, $reading, $writing, $waiting, $req) = explode("\n", $nginx);
if (!is_file($nginx_rrd)) {
rrdtool_create ($nginx_rrd, "--step 300 \
DS:Requests:DERIVE:600:0:125000000000 \
DS:Active:GAUGE:600:0:125000000000 \
DS:Reading:GAUGE:600:0:125000000000 \
DS:Writing:GAUGE:600:0:125000000000 \
DS:Waiting:GAUGE:600:0:125000000000 \
RRA:AVERAGE:0.5:1:600 \
RRA:AVERAGE:0.5:6:700 \
RRA:AVERAGE:0.5:24:775 \
RRA:AVERAGE:0.5:288:797 \
RRA:MIN:0.5:1:600 \
RRA:MIN:0.5:6:700 \
RRA:MIN:0.5:24:775 \
RRA:MIN:0.5:3:600 \
RRA:MAX:0.5:1:600 \
RRA:MAX:0.5:6:700 \
RRA:MAX:0.5:24:775 \
RRA:MAX:0.5:288:797");
}
print "active: $active reading: $reading writing: $writing waiting: $waiting Requests: $req";
rrdtool_update($nginx_rrd, "N:$req:$active:$reading:$writing:$waiting");
?>

37
scripts/nginx-stats Normal file

@ -0,0 +1,37 @@
#!/usr/bin/env python
import urllib2
import re
data = urllib2.urlopen('http://localhost/nginx-status').read()
params = {}
for line in data.split("\n"):
smallstat = re.match(r"\s?Reading:\s(.*)\sWriting:\s(.*)\sWaiting:\s(.*)$", line)
req = re.match(r"\s+(\d+)\s+(\d+)\s+(\d+)", line)
if smallstat:
params["Reading"] = smallstat.group(1)
params["Writing"] = smallstat.group(2)
params["Waiting"] = smallstat.group(3)
elif req:
params["Requests"] = req.group(3)
else:
pass
dataorder = [
"Active",
"Reading",
"Writing",
"Waiting",
"Requests"
]
for param in dataorder:
if param == "Active":
Active = int(params["Reading"]) + int(params["Writing"]) + int(params["Waiting"])
print Active
else:
print params[param]