Skip to content

Commit

Permalink
php-fpm: add last request cpu (#529)
Browse files Browse the repository at this point in the history
  • Loading branch information
VVelox authored Jun 15, 2024
1 parent e447b92 commit 317e93e
Showing 1 changed file with 42 additions and 28 deletions.
70 changes: 42 additions & 28 deletions snmp/php-fpm
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ A use_exec example...
{
"pools": {
"thefrog": "curl 'https://thefrog/fpm-status?json' 2> /dev/null",
"foobar": "curl 'https://foo.bar/fpm-status?json' 2> /dev/null",
"thefrog": "curl 'https://thefrog/fpm-status?json&full' 2> /dev/null",
"foobar": "curl 'https://foo.bar/fpm-status?json&full' 2> /dev/null",
},
"use_exec": 1
}
Expand Down Expand Up @@ -118,16 +118,17 @@ if ($help) {
}

my @to_total = (
"accepted conn",
"active processes",
"idle processes",
"listen queue",
"listen queue len",
"max active processes",
"max children reached",
"max listen queue",
"slow requests",
"total processes",
'accepted conn',
'active processes',
'idle processes',
'listen queue',
'listen queue len',
'max active processes',
'max children reached',
'max listen queue',
'slow requests',
'total processes',
'last request cpu',
);

my @to_migrate = @to_total;
Expand All @@ -139,17 +140,18 @@ my $to_return = {
pool_errors => {},
errored => 0,
totals => {
"accepted conn" => 0,
"active processes" => 0,
"idle processes" => 0,
"listen queue" => 0,
"listen queue len" => 0,
"max active processes" => 0,
"max children reached" => 0,
"max listen queue" => 0,
"slow requests" => 0,
"total processes" => 0,
'start since min' => undef,
'accepted conn' => 0,
'active processes' => 0,
'idle processes' => 0,
'listen queue' => 0,
'listen queue len' => 0,
'max active processes' => 0,
'max children reached' => 0,
'max listen queue' => 0,
'slow requests' => 0,
'total processes' => 0,
'start since' => undef,
'last request cpu' => 0,
},
},
version => 1,
Expand Down Expand Up @@ -204,7 +206,7 @@ foreach my $item (@pools) {
if ( ref( $config->{pools}{$item} ) eq '' ) {
my $command;
if ( !$config->{use_exec} ) {
$command = 'curl ' . shell_quote( $config->{pools}{$item} . '?json' ) . ' 2> /dev/null';
$command = 'curl ' . shell_quote( $config->{pools}{$item} . '?json&full' ) . ' 2> /dev/null';
} else {
$command = $config->{pools}{$item};
}
Expand All @@ -222,6 +224,18 @@ foreach my $item (@pools) {
$to_return->{data}{pools}{$item}{$migrate_item} = $pool_data->{$migrate_item};
}
}

if (defined($pool_data->{'processes'}) && ref($pool_data->{'processes'}) eq 'ARRAY') {
$to_return->{data}{pools}{$item}{'last request cpu'} = 0;
foreach my $proc_item (@{ $pool_data->{'processes'} }) {
if (defined( $proc_item->{'last request cpu'}) &&
ref($proc_item->{'last request cpu'}) eq '' &&
$proc_item->{'last request cpu'} =~ /\d+\.\d+/
) {
$to_return->{data}{pools}{$item}{'last request cpu'} += $proc_item->{'last request cpu'};
}
}
}
};
# if
if ($@) {
Expand All @@ -232,7 +246,7 @@ foreach my $item (@pools) {
# add the the pool to the totals
foreach my $total_item (@to_total) {
if ( defined( $to_return->{data}{pools}{$item}{$total_item} )
&& $to_return->{data}{pools}{$item}{$total_item} =~ /^\d+$/ )
&& $to_return->{data}{pools}{$item}{$total_item} =~ /^(\d+|\d+\.\d+)$/ )
{
$to_return->{data}{totals}{$total_item} += $to_return->{data}{pools}{$item}{$total_item};
}
Expand All @@ -242,10 +256,10 @@ foreach my $item (@pools) {
if ( defined( $to_return->{data}{pools}{$item}{'start since'} )
&& $to_return->{data}{pools}{$item}{'start since'} =~ /^\d+$/ )
{
if ( !defined( $to_return->{data}{totals}{'start since min'} )
|| $to_return->{data}{pools}{$item}{'start since'} < $to_return->{data}{totals}{'start since min'} )
if ( !defined( $to_return->{data}{totals}{'start since'} )
|| $to_return->{data}{pools}{$item}{'start since'} < $to_return->{data}{totals}{'start since'} )
{
$to_return->{data}{totals}{'start since min'} = $to_return->{data}{pools}{$item}{'start since'};
$to_return->{data}{totals}{'start since'} = $to_return->{data}{pools}{$item}{'start since'};
}
}
} ## end else [ if ($@) ]
Expand Down

0 comments on commit 317e93e

Please sign in to comment.