Files
librenms-librenms/includes/polling/applications/apache.inc.php
Tony Murray 7a8e479b61 Unix Agent and Application fixes (#15460)
* Unix Agent and Application fixes

* Apply fixes from StyleCI

---------

Co-authored-by: StyleCI Bot <bot@styleci.io>
2023-10-16 03:40:40 -05:00

81 lines
2.9 KiB
PHP

<?php
// Polls Apache statistics from script via SNMP
use LibreNMS\RRD\RrdDefinition;
$name = 'apache';
if (! empty($agent_data['app'][$name])) {
$apache = $agent_data['app'][$name];
} else {
$options = '-Oqv';
$oid = '.1.3.6.1.4.1.8072.1.3.2.3.1.2.6.97.112.97.99.104.101';
$apache = snmp_get($device, $oid, $options);
}
$apache_data = explode("\n", $apache);
if (count($apache_data) !== 20) {
echo " Incorrect number of datapoints returned from device, skipping\n";
return;
}
[$total_access, $total_kbyte, $cpuload, $uptime, $reqpersec, $bytespersec,
$bytesperreq, $busyworkers, $idleworkers, $score_wait, $score_start,
$score_reading, $score_writing, $score_keepalive, $score_dns,
$score_closing, $score_logging, $score_graceful, $score_idle, $score_open] = $apache_data;
$rrd_def = RrdDefinition::make()
->addDataset('access', 'DERIVE', 0, 125000000000)
->addDataset('kbyte', 'DERIVE', 0, 125000000000)
->addDataset('cpu', 'GAUGE', 0, 125000000000)
->addDataset('uptime', 'GAUGE', 0, 125000000000)
->addDataset('reqpersec', 'GAUGE', 0, 125000000000)
->addDataset('bytespersec', 'GAUGE', 0, 125000000000)
->addDataset('byesperreq', 'GAUGE', 0, 125000000000)
->addDataset('busyworkers', 'GAUGE', 0, 125000000000)
->addDataset('idleworkers', 'GAUGE', 0, 125000000000)
->addDataset('sb_wait', 'GAUGE', 0, 125000000000)
->addDataset('sb_start', 'GAUGE', 0, 125000000000)
->addDataset('sb_reading', 'GAUGE', 0, 125000000000)
->addDataset('sb_writing', 'GAUGE', 0, 125000000000)
->addDataset('sb_keepalive', 'GAUGE', 0, 125000000000)
->addDataset('sb_dns', 'GAUGE', 0, 125000000000)
->addDataset('sb_closing', 'GAUGE', 0, 125000000000)
->addDataset('sb_logging', 'GAUGE', 0, 125000000000)
->addDataset('sb_graceful', 'GAUGE', 0, 125000000000)
->addDataset('sb_idle', 'GAUGE', 0, 125000000000)
->addDataset('sb_open', 'GAUGE', 0, 125000000000);
$fields = [
'access' => intval(trim($total_access, '"')),
'kbyte' => $total_kbyte,
'cpu' => $cpuload,
'uptime' => $uptime,
'reqpersec' => $reqpersec,
'bytespersec' => $bytespersec,
'byesperreq' => $bytesperreq,
'busyworkers' => $busyworkers,
'idleworkers' => $idleworkers,
'sb_wait' => $score_wait,
'sb_start' => $score_start,
'sb_reading' => $score_reading,
'sb_writing' => $score_writing,
'sb_keepalive' => $score_keepalive,
'sb_dns' => $score_dns,
'sb_closing' => $score_closing,
'sb_logging' => $score_logging,
'sb_graceful' => $score_graceful,
'sb_idle' => $score_idle,
'sb_open' => intval(trim($score_open, '"')),
];
$tags = [
'name' => $name,
'app_id' => $app->app_id,
'rrd_name' => ['app', $name, $app->app_id],
'rrd_def' => $rrd_def,
];
data_update($device, 'app', $tags, $fields);
update_application($app, $apache, $fields);