Skip to content

Commit

Permalink
PHP-FPM app update to handle multiple pools (librenms#16122)
Browse files Browse the repository at this point in the history
* checkpoint work for now

* polling should be good now

* re-work php-fpm some more

* re-work the php-fpm app page

* add php-fpm_v1_combined.inc.php

* add more graphs

* more work

* add last request cpu

* fix stats for pools

* more graph work

* update the docs for php-fpm

* more graph work

* more graph stuff

* graph stuff now done

* some style fixes

* another style fix

* remove a unneeded use line

* add new tests

* add some missing items to the test

* json fix

* remove start time and add data
  • Loading branch information
VVelox authored Jul 4, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent ba8d733 commit 1b5f5ce
Showing 23 changed files with 731 additions and 44 deletions.
33 changes: 24 additions & 9 deletions doc/Extensions/Applications.md
Original file line number Diff line number Diff line change
@@ -1905,26 +1905,41 @@ using it as a agent.

1. Copy the shell script, phpfpmsp, to the desired host
```
wget https://github.com/librenms/librenms-agent/raw/master/snmp/phpfpmsp -O /etc/snmp/phpfpmsp
wget https://github.com/librenms/librenms-agent/raw/master/snmp/php-fpm -O /etc/snmp/php-fpm
```

2. Make the script executable
```
chmod +x /etc/snmp/phpfpmsp
chmod +x /etc/snmp/php-fpm
```

3. Install the depends.
```shell
# FreeBSD
pkg install p5-File-Slurp p5-JSON p5-String-ShellQuote p5-MIME-Base64
# Debian
apt-get install libfile-slurp-perl libjson-perl libstring-shellquote-perl libmime-base64-perl
```

3. Edit your snmpd.conf file (usually /etc/snmp/snmpd.conf) and add:
```
extend phpfpmsp /etc/snmp/phpfpmsp
extend phpfpmsp /etc/snmp/php-fpm
```

4. Edit /etc/snmp/phpfpmsp to include the status URL for the PHP-FPM
pool you are monitoring.

5. Restart snmpd on your host
5. Create the config file
`/usr/local/etc/php-fpm_extend.json`. Alternate locations may be
specified using the the `-f` switch. Akin to like below. For more
information, see `/etc/snmp/php-fpm --help`.
```json
{
"pools":{
"thefrog": "https://thefrog/fpm-status",
"foobar": "https://foo.bar/fpm-status"
}
}
```

It is worth noting that this only monitors a single pool. If you want
to monitor multiple pools, this won't do it.
6. Restart snmpd on the host

The application should be auto-discovered as described at the top of
the page. If it is not, please follow the steps set out under `SNMP
10 changes: 10 additions & 0 deletions includes/html/graphs/application/php-fpm-include.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

$name = 'php-fpm';
$ds = 'data';

if (isset($vars['phpfpm_pool'])) {
$filename = Rrd::name($device['hostname'], ['app', $name, $app->app_id, 'pools___' . $vars['phpfpm_pool'] . '___' . $stat]);
} else {
$filename = Rrd::name($device['hostname'], ['app', $name, $app->app_id, 'totals___' . $stat]);
}
87 changes: 87 additions & 0 deletions includes/html/graphs/application/php-fpm_overview_combined.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

$name = 'php-fpm';
$unit_text = 'Totals';
$colours = 'psychedelic';
$dostack = 0;
$printtotal = 0;
$descr_len = 20;
$addarea = 1;
$transparency = 15;

$filename = Rrd::name($device['hostname'], ['app', $name, $app->app_id, 'totals___max_active_processes']);

if (Rrd::checkRrdExists($filename)) {
$rrd_list = [];

$proc_stats = [
'max_active_processes' => 'Max Active Processes',
'active_processes' => 'Active Processes',
'idle_processes' => 'Idle Processes',
'max_listen_queue' => 'Max Listen Queue',
'listen_queue' => 'Listen Queue',
'listen_queue_len' => 'Listen Queue Len',
'listen_queue' => 'Listen Queue',
];

foreach ($proc_stats as $stat => $descr) {
$filename = Rrd::name($device['hostname'], ['app', $name, $app->app_id, 'totals___' . $stat]);
if (Rrd::checkRrdExists($filename)) {
$rrd_list[] = [
'filename' => $filename,
'descr' => $descr,
'ds' => 'data',
];
}
}
} else {
$filename = Rrd::name($device['hostname'], ['app', $name, $app->app_id]);
if (Rrd::checkRrdExists($filename)) {
$rrd_list = [
[
'filename' => $filename,
'descr' => 'Listen Queue',
'ds' => 'lq',
],
[
'filename' => $filename,
'descr' => 'Max Listen Queue',
'ds' => 'mlq',
],
[
'filename' => $filename,
'descr' => 'Idle Procs',
'ds' => 'ip',
],
[
'filename' => $filename,
'descr' => 'Active Procs',
'ds' => 'ap',
],
[
'filename' => $filename,
'descr' => 'Total Procs',
'ds' => 'tp',
],
[
'filename' => $filename,
'descr' => 'Max Active Procs',
'ds' => 'map',
],
[
'filename' => $filename,
'descr' => 'Max Children Reached',
'ds' => 'mcr',
],
[
'filename' => $filename,
'descr' => 'Slow Reqs',
'ds' => 'sr',
],
];
} else {
echo 'file missing: ' . $filename;
}
}

require 'includes/html/graphs/generic_multi_line.inc.php';
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

$name = 'php-fpm';

$descr = 'Max Chldrn Reached';
$unit_text = 'Per Second';
$ds = 'data';

$filename = Rrd::name($device['hostname'], ['app', $name, $app->app_id, 'totals___max_children_reached']);

if (! Rrd::checkRrdExists($filename)) {
$filename = Rrd::name($device['hostname'], ['app', $name, $app->app_id]);
$ds = 'mcr';
if (! Rrd::checkRrdExists($filename)) {
echo 'file missing: ' . $filename;
}
}

require 'includes/html/graphs/generic_stats.inc.php';
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

$name = 'php-fpm';

$descr = 'Slow Requests';
$stat = 'slow_requests';
$unit_text = 'Requests/S';
$ds = 'data';

$filename = Rrd::name($device['hostname'], ['app', $name, $app->app_id, 'totals___slow_requests']);

if (! Rrd::checkRrdExists($filename)) {
$filename = Rrd::name($device['hostname'], ['app', $name, $app->app_id]);
$ds = 'sr';
if (! Rrd::checkRrdExists($filename)) {
echo 'file missing: ' . $filename;
}
}

require 'includes/html/graphs/generic_stats.inc.php';
13 changes: 13 additions & 0 deletions includes/html/graphs/application/php-fpm_v1_accepted_conn.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

$descr = 'Accepted Conns';
$stat = 'accepted_conn';
$unit_text = 'Conns/S';

require 'php-fpm-include.php';

if (Rrd::checkRrdExists($filename)) {
d_echo('RRD "' . $filename . '" not found');
}

require 'includes/html/graphs/generic_stats.inc.php';
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

$descr = 'Active Procs';
$stat = 'active_processes';

require 'php-fpm-include.php';

if (Rrd::checkRrdExists($filename)) {
d_echo('RRD "' . $filename . '" not found');
}

require 'includes/html/graphs/generic_stats.inc.php';
39 changes: 39 additions & 0 deletions includes/html/graphs/application/php-fpm_v1_combined.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

$name = 'php-fpm';
$unit_text = 'Totals';
$colours = 'psychedelic';
$dostack = 0;
$printtotal = 0;
$descr_len = 20;
$addarea = 1;
$transparency = 15;

$rrd_list = [];

$proc_stats = [
'max_active_processes' => 'Max Active Processes',
'active_processes' => 'Active Processes',
'idle_processes' => 'Idle Processes',
'max_listen_queue' => 'Max Listen Queue',
'listen_queue' => 'Listen Queue',
'listen_queue_len' => 'Listen Queue Len',
'listen_queue' => 'Listen Queue',
];

foreach ($proc_stats as $stat => $descr) {
if (isset($vars['phpfpm_pool'])) {
$filename = Rrd::name($device['hostname'], ['app', $name, $app->app_id, 'pools___' . $vars['phpfpm_pool'] . '___' . $stat]);
} else {
$filename = Rrd::name($device['hostname'], ['app', $name, $app->app_id, 'totals___' . $stat]);
}
if (Rrd::checkRrdExists($filename)) {
$rrd_list[] = [
'filename' => $filename,
'descr' => $descr,
'ds' => 'data',
];
}
}

require 'includes/html/graphs/generic_multi_line.inc.php';
12 changes: 12 additions & 0 deletions includes/html/graphs/application/php-fpm_v1_idle_processes.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

$descr = 'Idle Procs';
$stat = 'idle_processes';

require 'php-fpm-include.php';

if (Rrd::checkRrdExists($filename)) {
d_echo('RRD "' . $filename . '" not found');
}

require 'includes/html/graphs/generic_stats.inc.php';
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

$descr = 'CPU Time %';
$stat = 'last_request_cpu';

require 'php-fpm-include.php';

if (Rrd::checkRrdExists($filename)) {
d_echo('RRD "' . $filename . '" not found');
}

require 'includes/html/graphs/generic_stats.inc.php';
12 changes: 12 additions & 0 deletions includes/html/graphs/application/php-fpm_v1_listen_queue.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

$descr = 'Listen Queue';
$stat = 'listen_queue';

require 'php-fpm-include.php';

if (Rrd::checkRrdExists($filename)) {
d_echo('RRD "' . $filename . '" not found');
}

require 'includes/html/graphs/generic_stats.inc.php';
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

$descr = 'Listen Queue Len';
$stat = 'listen_queue_len';

require 'php-fpm-include.php';

if (Rrd::checkRrdExists($filename)) {
d_echo('RRD "' . $filename . '" not found');
}

require 'includes/html/graphs/generic_stats.inc.php';
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

$descr = 'Max Act Procs';
$stat = 'max_active_processes';

require 'php-fpm-include.php';

if (Rrd::checkRrdExists($filename)) {
d_echo('RRD "' . $filename . '" not found');
}

require 'includes/html/graphs/generic_stats.inc.php';
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

$descr = 'Max Children Reached';
$stat = 'max_children_reached';
$unit_text = 'Per Second';

require 'php-fpm-include.php';

if (Rrd::checkRrdExists($filename)) {
d_echo('RRD "' . $filename . '" not found');
}

require 'includes/html/graphs/generic_stats.inc.php';
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

$descr = 'Max Listen Queue';
$stat = 'max_listen_queue';

require 'php-fpm-include.php';

if (Rrd::checkRrdExists($filename)) {
d_echo('RRD "' . $filename . '" not found');
}

require 'includes/html/graphs/generic_stats.inc.php';
13 changes: 13 additions & 0 deletions includes/html/graphs/application/php-fpm_v1_slow_requests.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

$descr = 'Slow Requests';
$stat = 'slow_requests';
$unit_text = 'Requests/S';

require 'php-fpm-include.php';

if (Rrd::checkRrdExists($filename)) {
d_echo('RRD "' . $filename . '" not found');
}

require 'includes/html/graphs/generic_stats.inc.php';
15 changes: 15 additions & 0 deletions includes/html/graphs/application/php-fpm_v1_start_since.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

$descr = 'Uptime';
$stat = 'start_since';

$munge = true;
$unit_text = 'days';

require 'php-fpm-include.php';

if (Rrd::checkRrdExists($filename)) {
d_echo('RRD "' . $filename . '" not found');
}

require 'includes/html/graphs/generic_stats.inc.php';
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

$descr = 'Total Procs';
$stat = 'total_processes';

require 'php-fpm-include.php';

if (Rrd::checkRrdExists($filename)) {
d_echo('RRD "' . $filename . '" not found');
}

require 'includes/html/graphs/generic_stats.inc.php';
Loading

0 comments on commit 1b5f5ce

Please sign in to comment.