update php apc and fpm plugin

This commit is contained in:
qgarnier 2017-08-07 13:26:24 +02:00
parent 5f6003ca1f
commit aff721200c
4 changed files with 205 additions and 409 deletions

View File

@ -20,122 +20,105 @@
package apps::php::apc::web::mode::filecache;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::http;
use centreon::plugins::statefile;
use centreon::plugins::values;
use Digest::MD5 qw(md5_hex);
my $maps_counters = {
'request-rate' => { class => 'centreon::plugins::values', obj => undef,
set => {
key_values => [
{ name => 'rr' },
],
output_template => 'Request Rate (global): %.2f',
perfdatas => [
{ value => 'rr_absolute', label => 'request_rate',template => '%.2f',
unit => 'r/s', min => 0 },
],
}
},
'request-rate-now' => { class => 'centreon::plugins::values', obj => undef,
set => {
key_values => [
{ name => 'hits', diff => 1 }, { name => 'misses', diff => 1 },
],
closure_custom_calc => \&custom_rr_calc, per_second => 1,
output_template => 'Request Rate : %.2f', output_error_template => 'Request Rate : %s',
output_use => 'rr_now', threshold_use => 'rr_now',
perfdatas => [
{ value => 'rr_now', label => 'request_rate_now', template => '%.2f',
unit => 'r/s', min => 0 },
],
}
},
'hit-rate' => { class => 'centreon::plugins::values', obj => undef,
set => {
key_values => [
{ name => 'hr' },
],
output_template => 'Hit Rate (global): %.2f',
perfdatas => [
{ value => 'hr_absolute', label => 'hit_rate',template => '%.2f',
unit => 'r/s', min => 0 },
],
}
},
'hit-rate-now' => { class => 'centreon::plugins::values', obj => undef,
set => {
key_values => [
{ name => 'hits', diff => 1 },
],
closure_custom_calc => \&custom_hr_calc, per_second => 1,
output_template => 'Hit Rate : %.2f', output_error_template => 'Hit Rate : %s',
output_use => 'hr_now', threshold_use => 'hr_now',
perfdatas => [
{ value => 'hr_now', label => 'hit_rate_now', template => '%.2f',
unit => 'r/s', min => 0 },
],
}
},
'miss-rate' => { class => 'centreon::plugins::values', obj => undef,
set => {
key_values => [
{ name => 'mr' },
],
output_template => 'Miss Rate (global): %.2f',
perfdatas => [
{ value => 'mr_absolute', label => 'miss_rate',template => '%.2f',
unit => 'r/s', min => 0 },
],
}
},
'miss-rate-now' => { class => 'centreon::plugins::values', obj => undef,
set => {
key_values => [
{ name => 'misses', diff => 1 },
],
closure_custom_calc => \&custom_mr_calc, per_second => 1,
output_template => 'Miss Rate : %.2f', output_error_template => 'Miss Rate : %s',
output_use => 'mr_now', threshold_use => 'mr_now',
perfdatas => [
{ value => 'mr_now', label => 'miss_rate_now', template => '%.2f',
unit => 'r/s', min => 0 },
],
}
},
'hit-percent' => { class => 'centreon::plugins::values', obj => undef,
set => {
key_values => [
{ name => 'hits' }, { name => 'misses' },
],
closure_custom_calc => \&custom_hit_percent_calc,
output_template => 'Hit Ratio (global) : %.2f %%', output_error_template => 'Hit Ratio (global): %s',
output_use => 'hit_ratio', threshold_use => 'hit_ratio',
perfdatas => [
{ value => 'hit_ratio', label => 'hit_ratio', template => '%.2f',
unit => '%', min => 0, max => 100 },
],
}
},
'hit-percent-now' => { class => 'centreon::plugins::values', obj => undef,
set => {
key_values => [
{ name => 'hits', diff => 1 }, { name => 'misses', diff => 1 },
],
closure_custom_calc => \&custom_hit_percent_now_calc,
output_template => 'Hit Ratio : %.2f %%', output_error_template => 'Hit Ratio : %s',
output_use => 'hit_ratio_now', threshold_use => 'hit_ratio_now',
perfdatas => [
{ value => 'hit_ratio_now', label => 'hit_ratio_now', template => '%.2f',
unit => '%', min => 0, max => 100 },
],
}
},
};
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'fcache', type => 0, cb_prefix_output => 'prefix_output' }
];
$self->{maps_counters}->{fcache} = [
{ label => 'request-rate', set => {
key_values => [ { name => 'rr' } ],
output_template => 'Request Rate (global): %.2f',
perfdatas => [
{ value => 'rr_absolute', label => 'request_rate',template => '%.2f',
unit => 'r/s', min => 0 },
],
}
},
{ label => 'request-rate-now', set => {
key_values => [ { name => 'hits', diff => 1 }, { name => 'misses', diff => 1 } ],
closure_custom_calc => $self->can('custom_rr_calc'), per_second => 1,
output_template => 'Request Rate : %.2f', output_error_template => 'Request Rate : %s',
output_use => 'rr_now', threshold_use => 'rr_now',
perfdatas => [
{ value => 'rr_now', label => 'request_rate_now', template => '%.2f',
unit => 'r/s', min => 0 },
],
}
},
{ label => 'hit-rate', set => {
key_values => [ { name => 'hr' } ],
output_template => 'Hit Rate (global): %.2f',
perfdatas => [
{ value => 'hr_absolute', label => 'hit_rate',template => '%.2f',
unit => 'r/s', min => 0 },
],
}
},
{ label => 'hit-rate-now', set => {
key_values => [ { name => 'hits', diff => 1 } ],
closure_custom_calc => $self->can('custom_hr_calc'), per_second => 1,
output_template => 'Hit Rate : %.2f', output_error_template => 'Hit Rate : %s',
output_use => 'hr_now', threshold_use => 'hr_now',
perfdatas => [
{ value => 'hr_now', label => 'hit_rate_now', template => '%.2f',
unit => 'r/s', min => 0 },
],
}
},
{ label => 'miss-rate', set => {
key_values => [ { name => 'mr' } ],
output_template => 'Miss Rate (global): %.2f',
perfdatas => [
{ value => 'mr_absolute', label => 'miss_rate',template => '%.2f',
unit => 'r/s', min => 0 },
],
}
},
{ label => 'miss-rate-now', set => {
key_values => [ { name => 'misses', diff => 1 } ],
closure_custom_calc => $self->can('custom_mr_calc'), per_second => 1,
output_template => 'Miss Rate : %.2f', output_error_template => 'Miss Rate : %s',
output_use => 'mr_now', threshold_use => 'mr_now',
perfdatas => [
{ value => 'mr_now', label => 'miss_rate_now', template => '%.2f',
unit => 'r/s', min => 0 },
],
}
},
{ label => 'hit-percent', set => {
key_values => [ { name => 'hits' }, { name => 'misses' } ],
closure_custom_calc => $self->can('custom_hit_percent_calc'),
output_template => 'Hit Ratio (global) : %.2f %%', output_error_template => 'Hit Ratio (global): %s',
output_use => 'hit_ratio', threshold_use => 'hit_ratio',
perfdatas => [
{ value => 'hit_ratio', label => 'hit_ratio', template => '%.2f',
unit => '%', min => 0, max => 100 },
],
}
},
{ label => 'hit-percent-now', set => {
key_values => [ { name => 'hits', diff => 1 }, { name => 'misses', diff => 1 } ],
closure_custom_calc => $self->can('custom_hit_percent_now_calc'),
output_template => 'Hit Ratio : %.2f %%', output_error_template => 'Hit Ratio : %s',
output_use => 'hit_ratio_now', threshold_use => 'hit_ratio_now',
perfdatas => [
{ value => 'hit_ratio_now', label => 'hit_ratio_now', template => '%.2f',
unit => '%', min => 0, max => 100 },
],
}
},
];
}
sub custom_rr_calc {
my ($self, %options) = @_;
@ -205,9 +188,15 @@ sub custom_hit_percent_calc {
return 0;
}
sub prefix_output {
my ($self, %options) = @_;
return "Apc File Cache Information ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class;
$self->{version} = '1.0';
@ -225,97 +214,33 @@ sub new {
});
$self->{http} = centreon::plugins::http->new(output => $self->{output});
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
foreach (keys %{$maps_counters}) {
$options{options}->add_options(arguments => {
'warning-' . $_ . ':s' => { name => 'warning-' . $_ },
'critical-' . $_ . ':s' => { name => 'critical-' . $_ },
});
my $class = $maps_counters->{$_}->{class};
$maps_counters->{$_}->{obj} = $class->new(statefile => $self->{statefile_value},
output => $self->{output}, perfdata => $self->{perfdata},
label => $_);
$maps_counters->{$_}->{obj}->set(%{$maps_counters->{$_}->{set}});
}
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach (keys %{$maps_counters}) {
$maps_counters->{$_}->{obj}->init(option_results => $self->{option_results});
}
$self->SUPER::check_options(%options);
$self->{http}->set_options(%{$self->{option_results}});
$self->{statefile_value}->check_options(%options);
}
sub run {
my ($self, %options) = @_;
$self->{webcontent} = $self->{http}->request();
$self->manage_selection();
$self->{new_datas} = {};
$self->{statefile_value}->read(statefile => "apc_" . $self->{option_results}->{hostname} . '_' . $self->{http}->get_port() . '_' . $self->{mode});
$self->{new_datas}->{last_timestamp} = time();
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits;
foreach (sort keys %{$maps_counters}) {
$maps_counters->{$_}->{obj}->set(instance => 'fcache');
my ($value_check) = $maps_counters->{$_}->{obj}->execute(values => $self->{fcache},
new_datas => $self->{new_datas});
if ($value_check != 0) {
$long_msg .= $long_msg_append . $maps_counters->{$_}->{obj}->output_error();
$long_msg_append = ', ';
next;
}
my $exit2 = $maps_counters->{$_}->{obj}->threshold_check();
push @exits, $exit2;
my $output = $maps_counters->{$_}->{obj}->output();
$long_msg .= $long_msg_append . $output;
$long_msg_append = ', ';
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
$short_msg .= $short_msg_append . $output;
$short_msg_append = ', ';
}
$maps_counters->{$_}->{obj}->perfdata();
}
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->{output}->output_add(severity => $exit,
short_msg => "Apc File Cache Information $short_msg"
);
} else {
$self->{output}->output_add(short_msg => "Apc File Cache Information $long_msg");
}
$self->{statefile_value}->write(data => $self->{new_datas});
$self->{output}->display();
$self->{output}->exit();
}
sub manage_selection {
my ($self, %options) = @_;
#my $webcontent = $self->{http}->request();
my $webcontent = 'plop';
$self->{fcache} = {};
$self->{fcache}->{hits} = $self->{webcontent} =~ /File Cache Information.*?Hits.*?(\d+)/msi ? $1 : undef;
$self->{fcache}->{misses} = $self->{webcontent} =~ /File Cache Information.*?Misses.*?(\d+)/msi ? $1 : undef;
$self->{fcache}->{rr} = $self->{webcontent} =~ /File Cache Information.*?Request Rate.*?([0-9\.]+)/msi ? $1 : undef;
$self->{fcache}->{hr} = $self->{webcontent} =~ /File Cache Information.*?Hit Rate.*?([0-9\.]+)/msi ? $1 : undef;
$self->{fcache}->{mr} = $self->{webcontent} =~ /File Cache Information.*?Miss Rate.*?([0-9\.]+)/msi ? $1 : undef;
$self->{fcache}->{ir} = $self->{webcontent} =~ /File Cache Information.*?Insert Rate.*?([0-9\.]+)/msi ? $1 : undef;
$self->{fcache}->{hits} = $webcontent =~ /File Cache Information.*?Hits.*?(\d+)/msi ? $1 : undef;
$self->{fcache}->{misses} = $webcontent =~ /File Cache Information.*?Misses.*?(\d+)/msi ? $1 : undef;
$self->{fcache}->{rr} = $webcontent =~ /File Cache Information.*?Request Rate.*?([0-9\.]+)/msi ? $1 : undef;
$self->{fcache}->{hr} = $webcontent =~ /File Cache Information.*?Hit Rate.*?([0-9\.]+)/msi ? $1 : undef;
$self->{fcache}->{mr} = $webcontent =~ /File Cache Information.*?Miss Rate.*?([0-9\.]+)/msi ? $1 : undef;
$self->{fcache}->{ir} = $webcontent =~ /File Cache Information.*?Insert Rate.*?([0-9\.]+)/msi ? $1 : undef;
$self->{cache_name} = "apc_" . $self->{mode} . '_' . $self->{option_results}->{hostname} . '_' . $self->{http}->get_port() . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
}
1;

View File

@ -20,43 +20,45 @@
package apps::php::apc::web::mode::memory;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::http;
use centreon::plugins::values;
use centreon::plugins::misc;
my $maps_counters = {
'used' => { class => 'centreon::plugins::values', obj => undef,
set => {
key_values => [
{ name => 'free' }, { name => 'used' },
],
closure_custom_calc => \&custom_used_calc,
closure_custom_output => \&custom_used_output,
threshold_use => 'used_prct',
output_error_template => 'Memory Usage: %s',
perfdatas => [
{ value => 'used', label => 'used', template => '%d',
unit => 'B', min => 0, max => 'total', threshold_total => 'total' },
],
}
},
'fragmentation' => { class => 'centreon::plugins::values', obj => undef,
set => {
key_values => [
{ name => 'fragmentation' },
],
output_template => 'Memory Fragmentation: %.2f %%', output_error_template => 'Memory Fragmentation: %s',
output_use => 'fragmentation_absolute', threshold_use => 'fragmentation_absolute',
perfdatas => [
{ value => 'fragmentation_absolute', label => 'fragmentation', template => '%.2f',
unit => '%', min => 0, max => 100 },
],
}
},
};
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'mem', type => 0, cb_prefix_output => 'prefix_output' }
];
$self->{maps_counters}->{mem} = [
{ label => 'used', set => {
key_values => [ { name => 'free' }, { name => 'free' } ],
closure_custom_calc => $self->can('custom_used_calc'),
closure_custom_output => $self->can('custom_used_output'),
threshold_use => 'used_prct',
output_error_template => 'Memory Usage: %s',
perfdatas => [
{ value => 'used', label => 'used', template => '%d',
unit => 'B', min => 0, max => 'total', threshold_total => 'total' },
],
}
},
{ label => 'fragmentation', set => {
key_values => [ { name => 'fragmentation' } ],
output_template => 'Memory Fragmentation: %.2f %%', output_error_template => 'Memory Fragmentation: %s',
output_use => 'fragmentation_absolute', threshold_use => 'fragmentation_absolute',
perfdatas => [
{ value => 'fragmentation_absolute', label => 'fragmentation', template => '%.2f',
unit => '%', min => 0, max => 100 },
],
}
},
];
}
sub custom_used_calc {
my ($self, %options) = @_;
@ -82,6 +84,12 @@ sub custom_used_output {
$free_value . " " . $free_unit, $self->{result_values}->{free_prct});
}
sub prefix_output {
my ($self, %options) = @_;
return "Apc ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
@ -103,106 +111,32 @@ sub new {
$self->{http} = centreon::plugins::http->new(output => $self->{output});
foreach (keys %{$maps_counters}) {
$options{options}->add_options(arguments => {
'warning-' . $_ . ':s' => { name => 'warning-' . $_ },
'critical-' . $_ . ':s' => { name => 'critical-' . $_ },
});
my $class = $maps_counters->{$_}->{class};
$maps_counters->{$_}->{obj} = $class->new(output => $self->{output}, perfdata => $self->{perfdata},
label => $_);
$maps_counters->{$_}->{obj}->set(%{$maps_counters->{$_}->{set}});
}
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach (keys %{$maps_counters}) {
$maps_counters->{$_}->{obj}->init(option_results => $self->{option_results});
}
$self->SUPER::check_options(%options);
$self->{http}->set_options(%{$self->{option_results}});
}
sub run {
my ($self, %options) = @_;
$self->{webcontent} = $self->{http}->request();
$self->manage_selection();
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits;
foreach (sort keys %{$maps_counters}) {
$maps_counters->{$_}->{obj}->set(instance => 'mem');
my ($value_check) = $maps_counters->{$_}->{obj}->execute(values => $self->{mem});
if ($value_check != 0) {
$long_msg .= $long_msg_append . $maps_counters->{$_}->{obj}->output_error();
$long_msg_append = ', ';
next;
}
my $exit2 = $maps_counters->{$_}->{obj}->threshold_check();
push @exits, $exit2;
my $output = $maps_counters->{$_}->{obj}->output();
$long_msg .= $long_msg_append . $output;
$long_msg_append = ', ';
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
$short_msg .= $short_msg_append . $output;
$short_msg_append = ', ';
}
$maps_counters->{$_}->{obj}->perfdata();
}
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->{output}->output_add(severity => $exit,
short_msg => "Apc $short_msg"
);
} else {
$self->{output}->output_add(short_msg => "Apc $long_msg");
}
$self->{output}->display();
$self->{output}->exit();
}
sub in_bytes {
my ($self, %options) = @_;
my $value = $options{value};
if ($options{unit} =~ /^G/) {
$value *= 1024 * 1024 * 1024;
} elsif ($options{unit} =~ /^M/) {
$value *= 1024 * 1024;
} elsif ($options{unit} =~ /^K/) {
$value *= 1024;
}
return $value;
}
sub manage_selection {
my ($self, %options) = @_;
my $webcontent = $self->{http}->request();
my ($free, $used);
if ($self->{webcontent} =~ /Memory Usage.*?Free:.*?([0-9\.]+)\s*(\S*)/msi) {
$free = $self->in_bytes(value => $1, unit => $2);
if ($webcontent =~ /Memory Usage.*?Free:.*?([0-9\.]+)\s*(\S*)/msi) {
$free = centreon::plugins::misc::convert_bytes(value => $1, unit => $2);
}
if ($self->{webcontent} =~ /Memory Usage.*?Used:.*?([0-9\.]+)\s*(\S*)/msi) {
$used = $self->in_bytes(value => $1, unit => $2);
if ($webcontent =~ /Memory Usage.*?Used:.*?([0-9\.]+)\s*(\S*)/msi) {
$used = centreon::plugins::misc::convert_bytes(value => $1, unit => $2);
}
$self->{mem} = {};
$self->{mem}->{free} = $free;
$self->{mem}->{used} = $used;
$self->{mem}->{fragmentation} = $self->{webcontent} =~ /Fragmentation:.*?([0-9\.]+)/msi ? $1 : undef;
$self->{mem}->{fragmentation} = $webcontent =~ /Fragmentation:.*?([0-9\.]+)/msi ? $1 : undef;
}
1;

View File

@ -20,33 +20,38 @@
package apps::php::fpm::web::mode::usage;
use base qw(centreon::plugins::mode);
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::http;
use centreon::plugins::values;
use centreon::plugins::statefile;
use Digest::MD5 qw(md5_hex);
my $maps_counters = {
fpm => {
'000_active-processes' => { set => {
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'fpm', type => 0, cb_prefix_output => 'prefix_output' }
];
$self->{maps_counters}->{fpm} = [
{ label => 'active-processes', set => {
key_values => [ { name => 'active' }, { name => 'total' } ],
closure_custom_calc => \&custom_active_calc,
closure_custom_output => \&custom_active_output,
closure_custom_calc => $self->can('custom_active_calc'),
closure_custom_output => $self->can('custom_active_output'),
threshold_use => 'active_prct',
closure_custom_perfdata => => \&custom_active_perfdata,
closure_custom_perfdata => => $self->can('custom_active_perfdata'),
}
},
'001_idle-processes' => { set => {
{ label => 'idle-processes', set => {
key_values => [ { name => 'idle' }, { name => 'total' } ],
closure_custom_calc => \&custom_idle_calc,
closure_custom_output => \&custom_idle_output,
closure_custom_calc => $self->can('custom_idle_calc'),
closure_custom_output => $self->can('custom_idle_output'),
threshold_use => 'idle_prct',
closure_custom_perfdata => => \&custom_idle_perfdata,
closure_custom_perfdata => => $self->can('custom_idle_perfdata'),
}
},
'002_listen-queue' => { set => {
},
{ label => 'listen-queue', set => {
key_values => [ { name => 'listen_queue' }, { name => 'max_listen_queue' } ],
output_template => 'Listen queue : %s',
output_use => 'listen_queue_absolute', threshold_use => 'listen_queue_absolute',
@ -56,7 +61,7 @@ my $maps_counters = {
],
}
},
'003_requests' => { set => {
{ label => 'requests', set => {
key_values => [ { name => 'request', diff => 1 } ],
per_second => 1,
output_template => 'Requests : %.2f/s',
@ -66,8 +71,8 @@ my $maps_counters = {
],
}
},
},
};
];
}
sub custom_active_calc {
my ($self, %options) = @_;
@ -123,9 +128,15 @@ sub custom_idle_perfdata {
min => 0, max => $self->{result_values}->{total});
}
sub prefix_output {
my ($self, %options) = @_;
return "php-fpm ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class;
$self->{version} = '1.0';
@ -141,108 +152,34 @@ sub new {
"proxyurl:s" => { name => 'proxyurl' },
"timeout:s" => { name => 'timeout', default => 5 },
});
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
$self->{http} = centreon::plugins::http->new(output => $self->{output});
foreach my $key (('fpm')) {
foreach (keys %{$maps_counters->{$key}}) {
my ($id, $name) = split /_/;
if (!defined($maps_counters->{$key}->{$_}->{threshold}) || $maps_counters->{$key}->{$_}->{threshold} != 0) {
$options{options}->add_options(arguments => {
'warning-' . $name . ':s' => { name => 'warning-' . $name },
'critical-' . $name . ':s' => { name => 'critical-' . $name },
});
}
$maps_counters->{$key}->{$_}->{obj} = centreon::plugins::values->new(statefile => $self->{statefile_value},
output => $self->{output}, perfdata => $self->{perfdata},
label => $name);
$maps_counters->{$key}->{$_}->{obj}->set(%{$maps_counters->{$key}->{$_}->{set}});
}
}
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
$self->SUPER::check_options(%options);
foreach my $key (('fpm')) {
foreach (keys %{$maps_counters->{$key}}) {
$maps_counters->{$key}->{$_}->{obj}->init(option_results => $self->{option_results});
}
}
$self->{statefile_value}->check_options(%options);
$self->{http}->set_options(%{$self->{option_results}});
}
sub run {
my ($self, %options) = @_;
$self->{webcontent} = $self->{http}->request();
$self->manage_selection();
$self->{new_datas} = {};
$self->{statefile_value}->read(statefile => "php_fpm_" . $self->{option_results}->{hostname} . '_' . $self->{http}->get_port() . '_' . $self->{mode});
$self->{new_datas}->{last_timestamp} = time();
my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', '');
my @exits;
foreach (sort keys %{$maps_counters->{fpm}}) {
my $obj = $maps_counters->{fpm}->{$_}->{obj};
$obj->set(instance => 'fpm');
my ($value_check) = $obj->execute(values => $self->{fpm},
new_datas => $self->{new_datas});
if ($value_check != 0) {
$long_msg .= $long_msg_append . $obj->output_error();
$long_msg_append = ', ';
next;
}
my $exit2 = $obj->threshold_check();
push @exits, $exit2;
my $output = $obj->output();
$long_msg .= $long_msg_append . $output;
$long_msg_append = ', ';
if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) {
$short_msg .= $short_msg_append . $output;
$short_msg_append = ', ';
}
$obj->perfdata();
}
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) {
$self->{output}->output_add(severity => $exit,
short_msg => "php-fpm $short_msg"
);
} else {
$self->{output}->output_add(short_msg => "php-fpm $long_msg");
}
$self->{statefile_value}->write(data => $self->{new_datas});
$self->{output}->display();
$self->{output}->exit();
}
sub manage_selection {
my ($self, %options) = @_;
my $webcontent = $self->{http}->request();
$self->{fpm} = { request => undef, listen_queue => undef, max_listen_queue => undef,
idle => undef, active => undef, total => undef };
$self->{fpm}->{request} = $1 if ($self->{webcontent} =~ /accepted\s+conn:\s+(\d+)/msi);
$self->{fpm}->{listen_queue} = $1 if ($self->{webcontent} =~ /listen\s+queue:\s+(\d+)/msi);
$self->{fpm}->{max_listen_queue} = $1 if ($self->{webcontent} =~ /max\s+listen\s+queue:\s+(\d+)/msi);
$self->{fpm}->{idle} = $1 if ($self->{webcontent} =~ /idle\s+processes:\s+(\d+)/msi);
$self->{fpm}->{active} = $1 if ($self->{webcontent} =~ /active\s+processes:\s+(\d+)/msi);
$self->{fpm}->{total} = $1 if ($self->{webcontent} =~ /total\s+processes:\s+(\d+)/msi);
$self->{fpm}->{request} = $1 if ($webcontent =~ /accepted\s+conn:\s+(\d+)/msi);
$self->{fpm}->{listen_queue} = $1 if ($webcontent =~ /listen\s+queue:\s+(\d+)/msi);
$self->{fpm}->{max_listen_queue} = $1 if ($webcontent =~ /max\s+listen\s+queue:\s+(\d+)/msi);
$self->{fpm}->{idle} = $1 if ($webcontent =~ /idle\s+processes:\s+(\d+)/msi);
$self->{fpm}->{active} = $1 if ($webcontent =~ /active\s+processes:\s+(\d+)/msi);
$self->{fpm}->{total} = $1 if ($webcontent =~ /total\s+processes:\s+(\d+)/msi);
$self->{cache_name} = "php_fpm_" . $self->{mode} . '_' . $self->{option_results}->{hostname} . '_' . $self->{http}->get_port() . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
}
1;

View File

@ -393,7 +393,7 @@ sub convert_bytes {
my (%options) = @_;
my %expo = (k => 1, m => 2, g => 3, t => 4);
my $value = $options{value};
my $base = defined($options{network}) ? 1000 : 1020;
my $base = defined($options{network}) ? 1000 : 1024;
if ($options{unit} =~ /([kmgt])b/i) {
$value = $value * ($base ** $expo{lc($1)});