1<?php
2
3// Polls Apache statistics from script via SNMP
4use LibreNMS\RRD\RrdDefinition;
5
6$name = 'apache';
7$app_id = $app['app_id'];
8if (! empty($agent_data['app'][$name])) {
9    $apache = $agent_data['app'][$name];
10} else {
11    $options = '-Oqv';
12    $oid = '.1.3.6.1.4.1.8072.1.3.2.3.1.2.6.97.112.97.99.104.101';
13    $apache = snmp_get($device, $oid, $options);
14}
15
16echo ' apache';
17
18[$total_access, $total_kbyte, $cpuload, $uptime, $reqpersec, $bytespersec,
19    $bytesperreq, $busyworkers, $idleworkers, $score_wait, $score_start,
20    $score_reading, $score_writing, $score_keepalive, $score_dns,
21    $score_closing, $score_logging, $score_graceful, $score_idle, $score_open] = explode("\n", $apache);
22
23$rrd_name = ['app', $name, $app_id];
24$rrd_def = RrdDefinition::make()
25    ->addDataset('access', 'DERIVE', 0, 125000000000)
26    ->addDataset('kbyte', 'DERIVE', 0, 125000000000)
27    ->addDataset('cpu', 'GAUGE', 0, 125000000000)
28    ->addDataset('uptime', 'GAUGE', 0, 125000000000)
29    ->addDataset('reqpersec', 'GAUGE', 0, 125000000000)
30    ->addDataset('bytespersec', 'GAUGE', 0, 125000000000)
31    ->addDataset('byesperreq', 'GAUGE', 0, 125000000000)
32    ->addDataset('busyworkers', 'GAUGE', 0, 125000000000)
33    ->addDataset('idleworkers', 'GAUGE', 0, 125000000000)
34    ->addDataset('sb_wait', 'GAUGE', 0, 125000000000)
35    ->addDataset('sb_start', 'GAUGE', 0, 125000000000)
36    ->addDataset('sb_reading', 'GAUGE', 0, 125000000000)
37    ->addDataset('sb_writing', 'GAUGE', 0, 125000000000)
38    ->addDataset('sb_keepalive', 'GAUGE', 0, 125000000000)
39    ->addDataset('sb_dns', 'GAUGE', 0, 125000000000)
40    ->addDataset('sb_closing', 'GAUGE', 0, 125000000000)
41    ->addDataset('sb_logging', 'GAUGE', 0, 125000000000)
42    ->addDataset('sb_graceful', 'GAUGE', 0, 125000000000)
43    ->addDataset('sb_idle', 'GAUGE', 0, 125000000000)
44    ->addDataset('sb_open', 'GAUGE', 0, 125000000000);
45
46$fields = [
47    'access'       => intval(trim($total_access, '"')),
48    'kbyte'        => $total_kbyte,
49    'cpu'          => $cpuload,
50    'uptime'       => $uptime,
51    'reqpersec'    => $reqpersec,
52    'bytespersec'  => $bytespersec,
53    'byesperreq'   => $bytesperreq,
54    'busyworkers'  => $busyworkers,
55    'idleworkers'  => $idleworkers,
56    'sb_wait'      => $score_wait,
57    'sb_start'     => $score_start,
58    'sb_reading'   => $score_reading,
59    'sb_writing'   => $score_writing,
60    'sb_keepalive' => $score_keepalive,
61    'sb_dns'       => $score_dns,
62    'sb_closing'   => $score_closing,
63    'sb_logging'   => $score_logging,
64    'sb_graceful'  => $score_graceful,
65    'sb_idle'      => $score_idle,
66    'sb_open'      => intval(trim($score_open, '"')),
67];
68
69$tags = compact('name', 'app_id', 'rrd_name', 'rrd_def');
70data_update($device, 'app', $tags, $fields);
71update_application($app, $apache, $fields);
72