This commit is contained in:
garnier-quentin 2019-06-05 13:53:11 +02:00
parent 33ff112c4a
commit 4b98e536ac
21 changed files with 347 additions and 4695 deletions

View File

@ -1,242 +0,0 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::varnish::local::mode::backend;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use JSON;
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'backend', type => 0, skipped_code => { -10 => 1 } },
];
$self->{maps_counters}->{backend} = [
{ label => 'conn', set => {
key_values => [ { name => 'backend_conn', diff => 1 } ],
output_template => 'Backend con: %.2f/s', output_error_template => "Backend con: %s",
per_second => 1,
perfdatas => [
{ label => 'backend_conn', value => 'backend_conn_per_second', template => '%.2f',
min => 0 },
],
}
},
{ label => 'unhealthy', set => {
key_values => [ { name => 'backend_unhealthy', diff => 1 } ],
output_template => 'Backend unhealthy: %.2f/s', output_error_template => "Backend unhealthy: %s",
per_second => 1,
perfdatas => [
{ label => 'backend_unhealthy', value => 'backend_unhealthy_per_second', template => '%.2f',
min => 0 },
],
}
},
{ label => 'busy', set => {
key_values => [ { name => 'backend_busy', diff => 1 } ],
output_template => 'Backend busy: %.2f/s', output_error_template => "Backend busy: %s",
per_second => 1,
perfdatas => [
{ label => 'backend_busy', value => 'backend_busy_per_second', template => '%.2f',
min => 0 },
],
}
},
{ label => 'fail', set => {
key_values => [ { name => 'backend_fail', diff => 1 } ],
output_template => 'Backend fail: %.2f/s', output_error_template => "Backend fail: %s",
per_second => 1,
perfdatas => [
{ label => 'backend_fail', value => 'backend_fail_per_second', template => '%.2f',
min => 0 },
],
}
},
{ label => 'reuse', set => {
key_values => [ { name => 'backend_reuse', diff => 1 } ],
output_template => 'Backend reuse: %.2f/s', output_error_template => "Backend reuse: %s",
per_second => 1,
perfdatas => [
{ label => 'backend_reuse', value => 'backend_reuse_per_second', template => '%.2f',
min => 0 },
],
}
},
{ label => 'recycle', set => {
key_values => [ { name => 'backend_recycle', diff => 1 } ],
output_template => 'Backend recycle: %.2f/s', output_error_template => "Backend recycle: %s",
per_second => 1,
perfdatas => [
{ label => 'backend_recycle', value => 'backend_recycle_per_second', template => '%.2f',
min => 0 },
],
}
},
{ label => 'retry', set => {
key_values => [ { name => 'backend_retry', diff => 1 } ],
output_template => 'Backend retry: %.2f/s', output_error_template => "Backend retry: %s",
per_second => 1,
perfdatas => [
{ label => 'backend_retry', value => 'backend_retry_per_second', template => '%.2f',
min => 0 },
],
}
},
{ label => 'recycle', set => {
key_values => [ { name => 'backend_recycle', diff => 1 } ],
output_template => 'Backend recycle: %.2f/s', output_error_template => "Backend recycle: %s",
per_second => 1,
perfdatas => [
{ label => 'backend_recycle', value => 'backend_recycle_per_second', template => '%.2f',
min => 0 },
],
}
},
{ label => 'request', set => {
key_values => [ { name => 'backend_req', diff => 1 } ],
output_template => 'Backend requests: %.2f/s', output_error_template => "Backend requests: %s",
per_second => 1,
perfdatas => [
{ label => 'backend_req', value => 'backend_req_per_second', template => '%.2f',
min => 0 },
],
}
},
],
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"remote" => { name => 'remote' },
"ssh-option:s@" => { name => 'ssh_option' },
"ssh-path:s" => { name => 'ssh_path' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 30 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command', default => 'varnishstat' },
"command-path:s" => { name => 'command_path', default => '/usr/bin' },
"command-options:s" => { name => 'command_options', default => ' -1 -j 2>&1' },
});
return $self;
};
sub manage_selection {
my ($self, %options) = @_;
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options});
# "MAIN.backend_hit": {"type": "MAIN", "value": 18437, "flag": "a", "description": "Cache hits"},
# "MAIN.backend_hitpass": {"type": "MAIN", "value": 3488, "flag": "a", "description": "Cache hits for pass"},
# "MAIN.backend_miss": {"type": "MAIN", "value": 5782, "flag": "a", "description": "Cache misses"},
my $json_data = decode_json($stdout);
$self->{cache_name} = "cache_varnish_" . $self->{mode} . '_' .
(defined($self->{option_results}->{hostname}) ? md5_hex($self->{option_results}->{hostname}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
foreach my $counter (keys %{$json_data}) {
next if ($counter !~ /backend/);
my $value = $json_data->{$counter}->{value};
$counter =~ s/^([A-Z])+\.//;
$self->{backend}->{$counter} = $value;
}
};
1;
__END__
=head1 MODE
Check Varnish Cache with varnishstat Command
=over 8
=item B<--remote>
If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--command>
Varnishstat Binary Filename (Default: varnishstat)
=item B<--command-path>
Directory Path to Varnishstat Binary File (Default: /usr/bin)
=item B<--command-options>
Parameter for Binary File (Default: ' -1 ')
=item B<--warning-*>
Warning Threshold for:
conn => Backend conn. success,
unhealthy => Backend conn. not attempted,
busy => Backend conn. too many,
fail => Backend conn. failures,
reuse => Backend conn. reuses,
toolate => Backend conn. was closed,
recycle => Backend conn. recycles,
retry => Backend conn. retry,
request => Backend requests made
=item B<--critical-*>
Critical Threshold for:
conn => Backend conn. success,
unhealthy => Backend conn. not attempted,
busy => Backend conn. too many,
fail => Backend conn. failures,
reuse => Backend conn. reuses,
toolate => Backend conn. was closed,
recycle => Backend conn. recycles,
retry => Backend conn. retry,
request => Backend requests made
=back
=cut

View File

@ -1,269 +0,0 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::varnish::local::mode::bans;
use base qw(centreon::plugins::mode);
use centreon::plugins::misc;
use centreon::plugins::statefile;
use Digest::MD5 qw(md5_hex);
my $maps_counters = {
n_ban => { thresholds => {
warning_total => { label => 'warning-total', exit_value => 'warning' },
critical_total => { label => 'critical-total', exit_value => 'critical' },
},
output_msg => 'N total active bans: %.2f',
factor => 1, unit => '',
},
n_ban_add => { thresholds => {
warning_add => { label => 'warning-add', exit_value => 'warning' },
critical_add => { label => 'critical-add', exit_value => 'critical' },
},
output_msg => 'N new bans added: %.2f',
factor => 1, unit => '',
},
n_ban_retire => { thresholds => {
warning_retire => { label => 'warning-retire', exit_value => 'warning' },
critical_retire => { label => 'critical-retire', exit_value => 'critical' },
},
output_msg => 'N old bans deleted: %.2f',
factor => 1, unit => '',
},
n_ban_obj_test => { thresholds => {
warning_objtest => { label => 'warning-objtest', exit_value => 'warning' },
critical_objtest => { label => 'critical-objtest', exit_value => 'critical' },
},
output_msg => 'N objects tested: %.2f',
factor => 1, unit => '',
},
n_ban_re_test => { thresholds => {
warning_retest => { label => 'warning-retest', exit_value => 'warning' },
critical_retest => { label => 'critical-retest', exit_value => 'critical' },
},
output_msg => 'N regexps tested against: %.2f',
factor => 1, unit => '',
},
n_ban_dups => { thresholds => {
warning_dups => { label => 'warning-dups', exit_value => 'warning' },
critical_dups => { label => 'critical-dups', exit_value => 'critical' },
},
output_msg => 'N duplicate bans removed: %.2f',
factor => 1, unit => '',
},
};
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"remote" => { name => 'remote' },
"ssh-option:s@" => { name => 'ssh_option' },
"ssh-path:s" => { name => 'ssh_path' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 30 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command', default => 'varnishstat' },
"command-path:s" => { name => 'command_path', default => '/usr/bin' },
"command-options:s" => { name => 'command_options', default => ' -1 ' },
"command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
});
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
$options{options}->add_options(arguments => {
$maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s' => { name => $name },
});
};
};
$self->{instances_done} = {};
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
return $self;
};
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
$self->{output}->option_exit();
};
};
};
$self->{statefile_value}->check_options(%options);
};
sub getdata {
my ($self, %options) = @_;
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
#print $stdout;
foreach (split(/\n/, $stdout)) {
#client_conn 7390867 1.00 Client connections
# - Symbolic entry name
# - Value
# - Per-second average over process lifetime, or a period if the value can not be averaged
# - Descriptive text
if (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
#print "FOUND: " . $1 . "=" . $2 . "\n";
$self->{result}->{$1} = $2;
};
};
};
sub run {
my ($self, %options) = @_;
$self->getdata();
$self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
$self->{result}->{last_timestamp} = time();
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
# Calculate
my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
$delta_time = 1 if ($delta_time == 0); # One seconds ;)
foreach (keys %{$maps_counters}) {
#print $_ . "\n";
$self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_'); # Get Data from Cache
$self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
$self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
};
# Write Cache if not there
$self->{statefile_value}->write(data => $self->{result});
if (!defined($old_timestamp)) {
$self->{output}->output_add(severity => 'OK',
short_msg => "Buffer creation...");
$self->{output}->display();
$self->{output}->exit();
}
my @exits;
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
}
}
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
my $extra_label = '';
$extra_label = '_' . $instance_output if ($num > 1);
my $str_output = "";
my $str_append = '';
foreach (keys %{$maps_counters}) {
$str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
$str_append = ', ';
my ($warning, $critical);
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
$warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
$critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
}
$self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
warning => $warning,
critical => $critical);
}
$self->{output}->output_add(severity => $exit,
short_msg => $str_output);
$self->{output}->display();
$self->{output}->exit();
};
1;
__END__
=head1 MODE
Check Varnish Cache with varnishstat Command
=over 8
=item B<--remote>
If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--command>
Varnishstat Binary Filename (Default: varnishstat)
=item B<--command-path>
Directory Path to Varnishstat Binary File (Default: /usr/bin)
=item B<--command-options>
Parameter for Binary File (Default: ' -1 ')
=item B<--warning-*>
Warning Threshold for:
total => N total active bans,
add => N new bans added,
retire => N old bans deleted,
objtest => N objects tested,
retest => N regexps tested against,
dups => N duplicate bans removed
=item B<--critical-*>
Critical Threshold for:
total => N total active bans,
add => N new bans added,
retire => N old bans deleted,
objtest => N objects tested,
retest => N regexps tested against,
dups => N duplicate bans removed
=back
=cut

View File

@ -1,170 +0,0 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::varnish::local::mode::cache;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use JSON;
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'cache', type => 0, skipped_code => { -10 => 1 } },
];
$self->{maps_counters}->{cache} = [
{ label => 'hit', set => {
key_values => [ { name => 'cache_hit', diff => 1 } ],
output_template => 'Cache hit: %.2f/s', output_error_template => "Cache hit: %s",
per_second => 1,
perfdatas => [
{ label => 'cache_hit', value => 'cache_hit_per_second', template => '%.2f',
min => 0 },
],
}
},
{ label => 'hitpass', set => {
key_values => [ { name => 'cache_hitpass', diff => 1 } ],
output_template => 'Cache hitpass : %.2f/s', output_error_template => "Cache hitpass : %s",
per_second => 1,
perfdatas => [
{ label => 'cache_hitpass', value => 'cache_hitpass_per_second', template => '%.2f',
min => 0 },
],
}
},
{ label => 'miss', set => {
key_values => [ { name => 'cache_miss', diff => 1 } ],
output_template => 'Cache miss : %.2f/s', output_error_template => "Cache miss : %s",
per_second => 1,
perfdatas => [
{ label => 'cache_miss', value => 'cache_miss_per_second', template => '%.2f',
min => 0 },
],
}
},
],
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"remote" => { name => 'remote' },
"ssh-option:s@" => { name => 'ssh_option' },
"ssh-path:s" => { name => 'ssh_path' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 30 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command', default => 'varnishstat' },
"command-path:s" => { name => 'command_path', default => '/usr/bin' },
"command-options:s" => { name => 'command_options', default => ' -1 -j 2>&1' },
});
return $self;
};
sub manage_selection {
my ($self, %options) = @_;
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options});
# "MAIN.cache_hit": {"type": "MAIN", "value": 18437, "flag": "a", "description": "Cache hits"},
# "MAIN.cache_hitpass": {"type": "MAIN", "value": 3488, "flag": "a", "description": "Cache hits for pass"},
# "MAIN.cache_miss": {"type": "MAIN", "value": 5782, "flag": "a", "description": "Cache misses"},
my $json_data = decode_json($stdout);
$self->{cache_name} = "cache_varnish_" . $self->{mode} . '_' .
(defined($self->{option_results}->{hostname}) ? md5_hex($self->{option_results}->{hostname}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
foreach my $counter (keys %{$json_data}) {
next if ($counter !~ /cache/);
my $value = $json_data->{$counter}->{value};
$counter =~ s/^([A-Z])+\.//;
$self->{cache}->{$counter} = $value;
}
};
1;
__END__
=head1 MODE
Check Varnish Cache with varnishstat Command
=over 8
=item B<--remote>
If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--command>
Varnishstat Binary Filename (Default: varnishstat)
=item B<--command-path>
Directory Path to Varnishstat Binary File (Default: /usr/bin)
=item B<--command-options>
Parameter for Binary File (Default: ' -1 -j 2>&1')
=item B<--warning-*>
Warning Threshold for:
hit => Cache Hits,
hitpass => Cache hits for Pass,
miss => Cache Misses
=item B<--critical-*>
Critical Threshold for:
hit => Cache Hits,
hitpass => Cache hits for Pass,
miss => Cache Misses
=back
=cut

View File

@ -1,187 +0,0 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::varnish::local::mode::clients;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use JSON;
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'clients', type => 0, skipped_code => { -10 => 1 } },
];
$self->{maps_counters}->{clients} = [
{ label => 'request', set => {
key_values => [ { name => 'client_req' , diff => 1 } ],
output_template => 'Client request (Total): %.2f', output_error_template => "Client request: %s",
per_second => 1,
perfdatas => [
{ label => 'client_req', value => 'client_req_per_second', template => '%.2f',
min => 0 },
],
}
},
{ label => 'request-400', set => {
key_values => [ { name => 'client_req_400' , diff => 1 } ],
output_template => 'Client request (HTTP/400): %.2f', output_error_template => "Client request (HTTP/400): %s",
per_second => 1,
perfdatas => [
{ label => 'client_req_400', value => 'client_req_400_per_second', template => '%.2f',
min => 0 },
],
}
},
{ label => 'request-411', set => {
key_values => [ { name => 'client_req_411' , diff => 1 } ],
output_template => 'Client request (HTTP/411): %.2f', output_error_template => "Client request (HTTP/411): %s",
per_second => 1,
perfdatas => [
{ label => 'client_req_411', value => 'client_req_411_per_second', template => '%.2f',
min => 0 },
],
}
},
{ label => 'request-413', set => {
key_values => [ { name => 'client_req_413' , diff => 1 } ],
output_template => 'Client request (HTTP/413): %.2f', output_error_template => "Client request (HTTP/413): %s",
per_second => 1,
perfdatas => [
{ label => 'client_req_413', value => 'client_req_413_per_second', template => '%.2f',
min => 0 },
],
}
},
{ label => 'request-417', set => {
key_values => [ { name => 'client_req_417' , diff => 1 } ],
output_template => 'Client request (HTTP/417): %.2f', output_error_template => "Client request (HTTP/417): %s",
per_second => 1,
perfdatas => [
{ label => 'client_req_417', value => 'client_req_417_per_second', template => '%.2f',
min => 0 },
],
}
},
],
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"remote" => { name => 'remote' },
"ssh-option:s@" => { name => 'ssh_option' },
"ssh-path:s" => { name => 'ssh_path' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 30 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command', default => 'varnishstat' },
"command-path:s" => { name => 'command_path', default => '/usr/bin' },
"command-options:s" => { name => 'command_options', default => ' -1 -j 2>&1' },
});
return $self;
};
sub manage_selection {
my ($self, %options) = @_;
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options});
# "MAIN.client_req_400": {"type": "MAIN", "value": 0, "flag": "a", "description": "Client requests received, subject to 400 errors"},
# "MAIN.client_req_411": {"type": "MAIN", "value": 0, "flag": "a", "description": "Client requests received, subject to 411 errors"},
# "MAIN.client_req_413": {"type": "MAIN", "value": 0, "flag": "a", "description": "Client requests received, subject to 413 errors"},
# "MAIN.client_req_417": {"type": "MAIN", "value": 0, "flag": "a", "description": "Client requests received, subject to 417 errors"},
# "MAIN.client_req": {"type": "MAIN", "value": 13597, "flag": "a", "description": "Good client requests received"},
my $json_data = decode_json($stdout);
$self->{cache_name} = "cache_varnish_" . $self->{mode} . '_' .
(defined($self->{option_results}->{hostname}) ? md5_hex($self->{option_results}->{hostname}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
foreach my $counter (keys %{$json_data}) {
next if ($counter !~ /^([A-Z])+\.client_.*/);
my $value = $json_data->{$counter}->{value};
$counter =~ s/^([A-Z])+\.//;
$self->{clients}->{$counter} = $value;
}
};
1;
__END__
=head1 MODE
Check client requests with varnishstat command (Varnish v4 required)
=over 8
=item B<--remote>
If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--command>
Varnishstat Binary Filename (Default: varnishstat)
=item B<--command-path>
Directory Path to Varnishstat Binary File (Default: /usr/bin)
=item B<--command-options>
Parameter for Binary File (Default: ' -1 -j 2>&1')
=item B<--warning-*>
Warning threshold per second.
Can be: (request,request-400,request-411,request-413,request-417)
=item B<--critical-*>
Critical threshold per second :
Can be: (request,request-400,request-411,request-413,request-417)
=back
=cut

View File

@ -1,251 +0,0 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::varnish::local::mode::connections;
use base qw(centreon::plugins::mode);
use centreon::plugins::misc;
use centreon::plugins::statefile;
use Digest::MD5 qw(md5_hex);
my $maps_counters = {
client_conn => { thresholds => {
warning_conn => { label => 'warning-conn', exit_value => 'warning' },
critical_conn => { label => 'critical-conn', exit_value => 'critical' },
},
output_msg => 'Client connections accepted: %.2f',
factor => 1, unit => '',
},
client_drop => { thresholds => {
warning_drop => { label => 'warning-drop', exit_value => 'warning' },
critical_drop => { label => 'critical-drop', exit_value => 'critical' },
},
output_msg => 'Connection dropped, no sess/wrk: %.2f',
factor => 1, unit => '',
},
client_drop_late => { thresholds => {
warning_droplate => { label => 'warning-droplate', exit_value => 'warning' },
critical_droplate => { label => 'critical-droplate', exit_value => 'critical' },
},
output_msg => 'Connection dropped late: %.2f',
factor => 1, unit => '',
},
client_req => { thresholds => {
warning_req => { label => 'warning-req', exit_value => 'warning' },
critical_req => { label => 'critical-req', exit_value => 'critical' },
},
output_msg => 'Client requests received: %.2f',
factor => 1, unit => '',
},
};
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"remote" => { name => 'remote' },
"ssh-option:s@" => { name => 'ssh_option' },
"ssh-path:s" => { name => 'ssh_path' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 30 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command', default => 'varnishstat' },
"command-path:s" => { name => 'command_path', default => '/usr/bin' },
"command-options:s" => { name => 'command_options', default => ' -1 ' },
"command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
});
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
$options{options}->add_options(arguments => {
$maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s' => { name => $name },
});
};
};
$self->{instances_done} = {};
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
return $self;
};
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
$self->{output}->option_exit();
};
};
};
$self->{statefile_value}->check_options(%options);
};
sub getdata {
my ($self, %options) = @_;
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
#print $stdout;
foreach (split(/\n/, $stdout)) {
#client_conn 7390867 1.00 Client connections
# - Symbolic entry name
# - Value
# - Per-second average over process lifetime, or a period if the value can not be averaged
# - Descriptive text
if (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
#print "FOUND: " . $1 . "=" . $2 . "\n";
$self->{result}->{$1} = $2;
};
};
};
sub run {
my ($self, %options) = @_;
$self->getdata();
$self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
$self->{result}->{last_timestamp} = time();
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
# Calculate
my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
$delta_time = 1 if ($delta_time == 0); # One seconds ;)
foreach (keys %{$maps_counters}) {
#print $_ . "\n";
$self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_'); # Get Data from Cache
$self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
$self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
};
# Write Cache if not there
$self->{statefile_value}->write(data => $self->{result});
if (!defined($old_timestamp)) {
$self->{output}->output_add(severity => 'OK',
short_msg => "Buffer creation...");
$self->{output}->display();
$self->{output}->exit();
}
my @exits;
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
}
}
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
my $extra_label = '';
$extra_label = '_' . $instance_output if ($num > 1);
my $str_output = "";
my $str_append = '';
foreach (keys %{$maps_counters}) {
$str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
$str_append = ', ';
my ($warning, $critical);
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
$warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
$critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
}
$self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
warning => $warning,
critical => $critical);
}
$self->{output}->output_add(severity => $exit,
short_msg => $str_output);
$self->{output}->display();
$self->{output}->exit();
};
1;
__END__
=head1 MODE
Check Varnish Cache with varnishstat Command
=over 8
=item B<--remote>
If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--command>
Varnishstat Binary Filename (Default: varnishstat)
=item B<--command-path>
Directory Path to Varnishstat Binary File (Default: /usr/bin)
=item B<--command-options>
Parameter for Binary File (Default: ' -1 ')
=item B<--warning-*>
Warning Threshold for:
conn => Client connections accepted,
drop => Connection dropped, no sess/wrk,
droplate => Connection dropped late,
req => Client requests received
=item B<--critical-*>
Critical Threshold for:
conn => Client connections accepted,
drop => Connection dropped, no sess/wrk,
droplate => Connection dropped late,
req => Client requests received
=back
=cut

View File

@ -1,251 +0,0 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::varnish::local::mode::dns;
use base qw(centreon::plugins::mode);
use centreon::plugins::misc;
use centreon::plugins::statefile;
use Digest::MD5 qw(md5_hex);
my $maps_counters = {
dir_dns_lookups => { thresholds => {
warning_lookups => { label => 'warning-lookups', exit_value => 'warning' },
critical_lookups => { label => 'critical-lookups', exit_value => 'critical' },
},
output_msg => 'HCB Lookups without lock: %.2f',
factor => 1, unit => '',
},
dir_dns_failed => { thresholds => {
warning_failed => { label => 'warning-failed', exit_value => 'warning' },
critical_failed => { label => 'critical-failed', exit_value => 'critical' },
},
output_msg => 'HCB Lookups with lock: %.2f',
factor => 1, unit => '',
},
dir_dns_hit => { thresholds => {
warning_hit => { label => 'warning-hit', exit_value => 'warning' },
critical_hit => { label => 'critical-hit', exit_value => 'critical' },
},
output_msg => 'HCB Inserts: %.2f',
factor => 1, unit => '',
},
dir_dns_cache_full => { thresholds => {
warning_full => { label => 'warning-full', exit_value => 'warning' },
critical_full => { label => 'critical-full', exit_value => 'critical' },
},
output_msg => 'HCB Inserts: %.2f',
factor => 1, unit => '',
},
};
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"remote" => { name => 'remote' },
"ssh-option:s@" => { name => 'ssh_option' },
"ssh-path:s" => { name => 'ssh_path' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 30 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command', default => 'varnishstat' },
"command-path:s" => { name => 'command_path', default => '/usr/bin' },
"command-options:s" => { name => 'command_options', default => ' -1 ' },
"command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
});
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
$options{options}->add_options(arguments => {
$maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s' => { name => $name },
});
};
};
$self->{instances_done} = {};
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
return $self;
};
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
$self->{output}->option_exit();
};
};
};
$self->{statefile_value}->check_options(%options);
};
sub getdata {
my ($self, %options) = @_;
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
#print $stdout;
foreach (split(/\n/, $stdout)) {
#client_conn 7390867 1.00 Client connections
# - Symbolic entry name
# - Value
# - Per-second average over process lifetime, or a period if the value can not be averaged
# - Descriptive text
if (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
#print "FOUND: " . $1 . "=" . $2 . "\n";
$self->{result}->{$1} = $2;
};
};
};
sub run {
my ($self, %options) = @_;
$self->getdata();
$self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
$self->{result}->{last_timestamp} = time();
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
# Calculate
my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
$delta_time = 1 if ($delta_time == 0); # One seconds ;)
foreach (keys %{$maps_counters}) {
#print $_ . "\n";
$self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_'); # Get Data from Cache
$self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
$self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
};
# Write Cache if not there
$self->{statefile_value}->write(data => $self->{result});
if (!defined($old_timestamp)) {
$self->{output}->output_add(severity => 'OK',
short_msg => "Buffer creation...");
$self->{output}->display();
$self->{output}->exit();
}
my @exits;
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
}
}
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
my $extra_label = '';
$extra_label = '_' . $instance_output if ($num > 1);
my $str_output = "";
my $str_append = '';
foreach (keys %{$maps_counters}) {
$str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
$str_append = ', ';
my ($warning, $critical);
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
$warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
$critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
}
$self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
warning => $warning,
critical => $critical);
}
$self->{output}->output_add(severity => $exit,
short_msg => $str_output);
$self->{output}->display();
$self->{output}->exit();
};
1;
__END__
=head1 MODE
Check Varnish Cache with varnishstat Command
=over 8
=item B<--remote>
If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--command>
Varnishstat Binary Filename (Default: varnishstat)
=item B<--command-path>
Directory Path to Varnishstat Binary File (Default: /usr/bin)
=item B<--command-options>
Parameter for Binary File (Default: ' -1 ')
=item B<--warning-*>
Warning Threshold for:
lookups => DNS director lookups,
failed => DNS director failed lookups,
hit => DNS director cached lookups hit,
full => DNS director full dnscache
=item B<--critical-*>
Critical Threshold for:
lookups => DNS director lookups,
failed => DNS director failed lookups,
hit => DNS director cached lookups hit,
full => DNS director full dnscache
=back
=cut

View File

@ -1,233 +0,0 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::varnish::local::mode::esi;
use base qw(centreon::plugins::mode);
use centreon::plugins::misc;
use centreon::plugins::statefile;
use Digest::MD5 qw(md5_hex);
my $maps_counters = {
esi_errors => { thresholds => {
warning_errors => { label => 'warning-errors', exit_value => 'warning' },
critical_errors => { label => 'critical-errors', exit_value => 'critical' },
},
output_msg => 'ESI parse errors (unlock): %.2f',
factor => 1, unit => '',
},
esi_warnings => { thresholds => {
warning_warnings => { label => 'warning-warnings', exit_value => 'warning' },
critical_warnings => { label => 'critical-warnings', exit_value => 'critical' },
},
output_msg => 'ESI parse warnings (unlock): %.2f',
factor => 1, unit => '',
},
};
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"remote" => { name => 'remote' },
"ssh-option:s@" => { name => 'ssh_option' },
"ssh-path:s" => { name => 'ssh_path' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 30 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command', default => 'varnishstat' },
"command-path:s" => { name => 'command_path', default => '/usr/bin' },
"command-options:s" => { name => 'command_options', default => ' -1 ' },
"command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
});
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
$options{options}->add_options(arguments => {
$maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s' => { name => $name },
});
};
};
$self->{instances_done} = {};
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
return $self;
};
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
$self->{output}->option_exit();
};
};
};
$self->{statefile_value}->check_options(%options);
};
sub getdata {
my ($self, %options) = @_;
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
#print $stdout;
foreach (split(/\n/, $stdout)) {
#client_conn 7390867 1.00 Client connections
# - Symbolic entry name
# - Value
# - Per-second average over process lifetime, or a period if the value can not be averaged
# - Descriptive text
if (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
#print "FOUND: " . $1 . "=" . $2 . "\n";
$self->{result}->{$1} = $2;
};
};
};
sub run {
my ($self, %options) = @_;
$self->getdata();
$self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
$self->{result}->{last_timestamp} = time();
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
# Calculate
my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
$delta_time = 1 if ($delta_time == 0); # One seconds ;)
foreach (keys %{$maps_counters}) {
#print $_ . "\n";
$self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_'); # Get Data from Cache
$self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
$self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
};
# Write Cache if not there
$self->{statefile_value}->write(data => $self->{result});
if (!defined($old_timestamp)) {
$self->{output}->output_add(severity => 'OK',
short_msg => "Buffer creation...");
$self->{output}->display();
$self->{output}->exit();
}
my @exits;
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
}
}
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
my $extra_label = '';
$extra_label = '_' . $instance_output if ($num > 1);
my $str_output = "";
my $str_append = '';
foreach (keys %{$maps_counters}) {
$str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
$str_append = ', ';
my ($warning, $critical);
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
$warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
$critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
}
$self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
warning => $warning,
critical => $critical);
}
$self->{output}->output_add(severity => $exit,
short_msg => $str_output);
$self->{output}->display();
$self->{output}->exit();
};
1;
__END__
=head1 MODE
Check Varnish Cache with varnishstat Command
=over 8
=item B<--remote>
If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--command>
Varnishstat Binary Filename (Default: varnishstat)
=item B<--command-path>
Directory Path to Varnishstat Binary File (Default: /usr/bin)
=item B<--command-options>
Parameter for Binary File (Default: ' -1 ')
=item B<--warning-*>
Warning Threshold for:
errors => ESI parse errors (unlock),
warnings => ESI parse warnings (unlock)
=item B<--critical-*>
Critical Threshold for:
errors => ESI parse errors (unlock),
warnings => ESI parse warnings (unlock)
=back
=cut

View File

@ -1,323 +0,0 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::varnish::local::mode::fetch;
use base qw(centreon::plugins::mode);
use centreon::plugins::misc;
use centreon::plugins::statefile;
use Digest::MD5 qw(md5_hex);
my $maps_counters = {
fetch_head => { thresholds => {
warning_head => { label => 'warning-head', exit_value => 'warning' },
critical_head => { label => 'critical-head', exit_value => 'critical' },
},
output_msg => 'Fetch head: %.2f',
factor => 1, unit => '',
},
fetch_length => { thresholds => {
warning_length => { label => 'warning-length', exit_value => 'warning' },
critical_length => { label => 'critical-length', exit_value => 'critical' },
},
output_msg => 'Fetch with Length: %.2f',
factor => 1, unit => '',
},
fetch_chunked => { thresholds => {
warning_chunked => { label => 'warning-chunked', exit_value => 'warning' },
critical_chunked => { label => 'critical-chunked', exit_value => 'critical' },
},
output_msg => 'Fetch chunked: %.2f',
factor => 1, unit => '',
},
fetch_eof => { thresholds => {
warning_eof => { label => 'warning-eof', exit_value => 'warning' },
critical_eof => { label => 'critical-eof', exit_value => 'critical' },
},
output_msg => 'Fetch EOF: %.2f',
factor => 1, unit => '',
},
fetch_bad => { thresholds => {
warning_bad => { label => 'warning-bad', exit_value => 'warning' },
critical_bad => { label => 'critical-bad', exit_value => 'critical' },
},
output_msg => 'Fetch had bad headers: %.2f',
factor => 1, unit => '',
},
fetch_close => { thresholds => {
warning_close => { label => 'warning-close', exit_value => 'warning' },
critical_close => { label => 'critical-close', exit_value => 'critical' },
},
output_msg => 'Fetch wanted close: %.2f',
factor => 1, unit => '',
},
fetch_oldhttp => { thresholds => {
warning_oldhttp => { label => 'warning-oldhttp', exit_value => 'warning' },
critical_oldhttp => { label => 'critical-oldhttp', exit_value => 'critical' },
},
output_msg => 'Fetch pre HTTP/1.1 closed: %.2f',
factor => 1, unit => '',
},
fetch_zero => { thresholds => {
warning_zero => { label => 'warning-zero', exit_value => 'warning' },
critical_zero => { label => 'critical-zero', exit_value => 'critical' },
},
output_msg => 'Fetch zero len: %.2f',
factor => 1, unit => '',
},
fetch_failed => { thresholds => {
warning_failed => { label => 'warning-failed', exit_value => 'warning' },
critical_failed => { label => 'critical-failed', exit_value => 'critical' },
},
output_msg => 'Fetch failed: %.2f',
factor => 1, unit => '',
},
fetch_1xx => { thresholds => {
warning_1xx => { label => 'warning-1xx', exit_value => 'warning' },
critical_1xx => { label => 'critical-1xx', exit_value => 'critical' },
},
output_msg => 'Fetch no body (1xx): %.2f',
factor => 1, unit => '',
},
fetch_204 => { thresholds => {
warning_204 => { label => 'warning-204', exit_value => 'warning' },
critical_204 => { label => 'critical-204', exit_value => 'critical' },
},
output_msg => 'Fetch no body (204): %.2f',
factor => 1, unit => '',
},
fetch_304 => { thresholds => {
warning_304 => { label => 'warning-304', exit_value => 'warning' },
critical_304 => { label => 'critical-304', exit_value => 'critical' },
},
output_msg => 'Fetch no body (304): %.2f',
factor => 1, unit => '',
},
};
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"remote" => { name => 'remote' },
"ssh-option:s@" => { name => 'ssh_option' },
"ssh-path:s" => { name => 'ssh_path' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 30 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command', default => 'varnishstat' },
"command-path:s" => { name => 'command_path', default => '/usr/bin' },
"command-options:s" => { name => 'command_options', default => ' -1 ' },
"command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
});
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
$options{options}->add_options(arguments => {
$maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s' => { name => $name },
});
};
};
$self->{instances_done} = {};
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
return $self;
};
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
$self->{output}->option_exit();
};
};
};
$self->{statefile_value}->check_options(%options);
};
sub getdata {
my ($self, %options) = @_;
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
#print $stdout;
foreach (split(/\n/, $stdout)) {
#client_conn 7390867 1.00 Client connections
# - Symbolic entry name
# - Value
# - Per-second average over process lifetime, or a period if the value can not be averaged
# - Descriptive text
if (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
#print "FOUND: " . $1 . "=" . $2 . "\n";
$self->{result}->{$1} = $2;
};
};
};
sub run {
my ($self, %options) = @_;
$self->getdata();
$self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
$self->{result}->{last_timestamp} = time();
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
# Calculate
my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
$delta_time = 1 if ($delta_time == 0); # One seconds ;)
foreach (keys %{$maps_counters}) {
#print $_ . "\n";
$self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_'); # Get Data from Cache
$self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
$self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
};
# Write Cache if not there
$self->{statefile_value}->write(data => $self->{result});
if (!defined($old_timestamp)) {
$self->{output}->output_add(severity => 'OK',
short_msg => "Buffer creation...");
$self->{output}->display();
$self->{output}->exit();
}
my @exits;
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
}
}
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
my $extra_label = '';
$extra_label = '_' . $instance_output if ($num > 1);
my $str_output = "";
my $str_append = '';
foreach (keys %{$maps_counters}) {
$str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
$str_append = ', ';
my ($warning, $critical);
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
$warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
$critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
}
$self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
warning => $warning,
critical => $critical);
}
$self->{output}->output_add(severity => $exit,
short_msg => $str_output);
$self->{output}->display();
$self->{output}->exit();
};
1;
__END__
=head1 MODE
Check Varnish Cache with varnishstat Command
=over 8
=item B<--remote>
If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--command>
Varnishstat Binary Filename (Default: varnishstat)
=item B<--command-path>
Directory Path to Varnishstat Binary File (Default: /usr/bin)
=item B<--command-options>
Parameter for Binary File (Default: ' -1 ')
=item B<--warning-*>
Warning Threshold for:
head => Fetch head,
length => Fetch with Length,
chunked => Fetch chunked,
eof => Fetch EOF,
bad => Fetch had bad headers,
close => Fetch wanted close,
oldhttp => Fetch pre HTTP/1.1 closed,
zero => Fetch zero len,
failed => Fetch failed,
1xx => Fetch no body (1xx),
204 => Fetch no body (204),
304 => Fetch no body (304)
=item B<--critical-*>
Critical Threshold for:
head => Fetch head,
length => Fetch with Length,
chunked => Fetch chunked,
eof => Fetch EOF,
bad => Fetch had bad headers,
close => Fetch wanted close,
oldhttp => Fetch pre HTTP/1.1 closed,
zero => Fetch zero len,
failed => Fetch failed,
1xx => Fetch no body (1xx),
204 => Fetch no body (204),
304 => Fetch no body (304)
=back
=cut

View File

@ -1,242 +0,0 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::varnish::local::mode::hcb;
use base qw(centreon::plugins::mode);
use centreon::plugins::misc;
use centreon::plugins::statefile;
use Digest::MD5 qw(md5_hex);
my $maps_counters = {
hcb_nolock => { thresholds => {
warning_nolock => { label => 'warning-nolock', exit_value => 'warning' },
critical_nolock => { label => 'critical-nolock', exit_value => 'critical' },
},
output_msg => 'HCB Lookups without lock: %.2f',
factor => 1, unit => '',
},
hcb_lock => { thresholds => {
warning_lock => { label => 'warning-lock', exit_value => 'warning' },
critical_lock => { label => 'critical-lock', exit_value => 'critical' },
},
output_msg => 'HCB Lookups with lock: %.2f',
factor => 1, unit => '',
},
hcb_insert => { thresholds => {
warning_insert => { label => 'warning-insert', exit_value => 'warning' },
critical_insert => { label => 'critical-insert', exit_value => 'critical' },
},
output_msg => 'HCB Inserts: %.2f',
factor => 1, unit => '',
},
};
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"remote" => { name => 'remote' },
"ssh-option:s@" => { name => 'ssh_option' },
"ssh-path:s" => { name => 'ssh_path' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 30 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command', default => 'varnishstat' },
"command-path:s" => { name => 'command_path', default => '/usr/bin' },
"command-options:s" => { name => 'command_options', default => ' -1 ' },
"command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
});
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
$options{options}->add_options(arguments => {
$maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s' => { name => $name },
});
};
};
$self->{instances_done} = {};
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
return $self;
};
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
$self->{output}->option_exit();
};
};
};
$self->{statefile_value}->check_options(%options);
};
sub getdata {
my ($self, %options) = @_;
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
#print $stdout;
foreach (split(/\n/, $stdout)) {
#client_conn 7390867 1.00 Client connections
# - Symbolic entry name
# - Value
# - Per-second average over process lifetime, or a period if the value can not be averaged
# - Descriptive text
if (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
#print "FOUND: " . $1 . "=" . $2 . "\n";
$self->{result}->{$1} = $2;
};
};
};
sub run {
my ($self, %options) = @_;
$self->getdata();
$self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
$self->{result}->{last_timestamp} = time();
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
# Calculate
my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
$delta_time = 1 if ($delta_time == 0); # One seconds ;)
foreach (keys %{$maps_counters}) {
#print $_ . "\n";
$self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_'); # Get Data from Cache
$self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
$self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
};
# Write Cache if not there
$self->{statefile_value}->write(data => $self->{result});
if (!defined($old_timestamp)) {
$self->{output}->output_add(severity => 'OK',
short_msg => "Buffer creation...");
$self->{output}->display();
$self->{output}->exit();
}
my @exits;
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
}
}
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
my $extra_label = '';
$extra_label = '_' . $instance_output if ($num > 1);
my $str_output = "";
my $str_append = '';
foreach (keys %{$maps_counters}) {
$str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
$str_append = ', ';
my ($warning, $critical);
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
$warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
$critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
}
$self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
warning => $warning,
critical => $critical);
}
$self->{output}->output_add(severity => $exit,
short_msg => $str_output);
$self->{output}->display();
$self->{output}->exit();
};
1;
__END__
=head1 MODE
Check Varnish Cache with varnishstat Command
=over 8
=item B<--remote>
If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--command>
Varnishstat Binary Filename (Default: varnishstat)
=item B<--command-path>
Directory Path to Varnishstat Binary File (Default: /usr/bin)
=item B<--command-options>
Parameter for Binary File (Default: ' -1 ')
=item B<--warning-*>
Warning Threshold for:
nolock => HCB Lookups without lock,
lock => HCB Lookups with lock,
insert => HCB Inserts
=item B<--critical-*>
Critical Threshold for:
nolock => HCB Lookups without lock,
lock => HCB Lookups with lock,
insert => HCB Inserts
=back
=cut

View File

@ -1,323 +0,0 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::varnish::local::mode::n;
use base qw(centreon::plugins::mode);
use centreon::plugins::misc;
use centreon::plugins::statefile;
use Digest::MD5 qw(md5_hex);
my $maps_counters = {
n_sess_mem => { thresholds => {
warning_mem => { label => 'warning-mem', exit_value => 'warning' },
critical_mem => { label => 'critical-mem', exit_value => 'critical' },
},
output_msg => 'N struct sess_mem: %.2f',
factor => 1, unit => '',
},
n_sess => { thresholds => {
warning_sess => { label => 'warning-sess', exit_value => 'warning' },
critical_sess => { label => 'critical-sess', exit_value => 'critical' },
},
output_msg => 'N struct sess: %.2f',
factor => 1, unit => '',
},
n_object => { thresholds => {
warning_object => { label => 'warning-object', exit_value => 'warning' },
critical_object => { label => 'critical-object', exit_value => 'critical' },
},
output_msg => 'N struct object: %.2f',
factor => 1, unit => '',
},
n_vampireobject => { thresholds => {
warning_vampireobject => { label => 'warning-vampireobject', exit_value => 'warning' },
critical_vampireobject => { label => 'critical-vampireobject', exit_value => 'critical' },
},
output_msg => 'N unresurrected objects: %.2f',
factor => 1, unit => '',
},
n_objectcore => { thresholds => {
warning_objectcore => { label => 'warning-objectcore', exit_value => 'warning' },
critical_objectcore => { label => 'critical-objectcore', exit_value => 'critical' },
},
output_msg => 'N struct objectcore: %.2f',
factor => 1, unit => '',
},
n_objecthead => { thresholds => {
warning_objecthead => { label => 'warning-objecthead', exit_value => 'warning' },
critical_objecthead => { label => 'critical-objecthead', exit_value => 'critical' },
},
output_msg => 'N struct objecthead: %.2f',
factor => 1, unit => '',
},
n_waitinglist => { thresholds => {
warning_waitinglist => { label => 'warning-waitinglist', exit_value => 'warning' },
critical_waitinglist => { label => 'critical-waitinglist', exit_value => 'critical' },
},
output_msg => 'N struct waitinglist: %.2f',
factor => 1, unit => '',
},
n_vbc => { thresholds => {
warning_vbc => { label => 'warning-vbc', exit_value => 'warning' },
critical_vbc => { label => 'critical-vbc', exit_value => 'critical' },
},
output_msg => 'N struct vbc: %.2f',
factor => 1, unit => '',
},
n_backend => { thresholds => {
warning_backend => { label => 'warning-backend', exit_value => 'warning' },
critical_backend => { label => 'critical-backend', exit_value => 'critical' },
},
output_msg => 'N backends: %.2f',
factor => 1, unit => '',
},
n_expired => { thresholds => {
warning_expired => { label => 'warning-expired', exit_value => 'warning' },
critical_expired => { label => 'critical-expired', exit_value => 'critical' },
},
output_msg => 'N expired objects: %.2f',
factor => 1, unit => '',
},
n_lru_nuked => { thresholds => {
warning_nuked => { label => 'warning-nuked', exit_value => 'warning' },
critical_nuked => { label => 'critical-nuked', exit_value => 'critical' },
},
output_msg => 'N LRU nuked objects: %.2f',
factor => 1, unit => '',
},
n_lru_moved => { thresholds => {
warning_moved => { label => 'warning-moved', exit_value => 'warning' },
critical_moved => { label => 'critical-moved', exit_value => 'critical' },
},
output_msg => 'N LRU moved objects: %.2f',
factor => 1, unit => '',
},
};
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"remote" => { name => 'remote' },
"ssh-option:s@" => { name => 'ssh_option' },
"ssh-path:s" => { name => 'ssh_path' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 30 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command', default => 'varnishstat' },
"command-path:s" => { name => 'command_path', default => '/usr/bin' },
"command-options:s" => { name => 'command_options', default => ' -1 ' },
"command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
});
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
$options{options}->add_options(arguments => {
$maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s' => { name => $name },
});
};
};
$self->{instances_done} = {};
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
return $self;
};
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
$self->{output}->option_exit();
};
};
};
$self->{statefile_value}->check_options(%options);
};
sub getdata {
my ($self, %options) = @_;
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
#print $stdout;
foreach (split(/\n/, $stdout)) {
#client_conn 7390867 1.00 Client connections
# - Symbolic entry name
# - Value
# - Per-second average over process lifetime, or a period if the value can not be averaged
# - Descriptive text
if (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
#print "FOUND: " . $1 . "=" . $2 . "\n";
$self->{result}->{$1} = $2;
};
};
};
sub run {
my ($self, %options) = @_;
$self->getdata();
$self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
$self->{result}->{last_timestamp} = time();
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
# Calculate
my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
$delta_time = 1 if ($delta_time == 0); # One seconds ;)
foreach (keys %{$maps_counters}) {
#print $_ . "\n";
$self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_'); # Get Data from Cache
$self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
$self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
};
# Write Cache if not there
$self->{statefile_value}->write(data => $self->{result});
if (!defined($old_timestamp)) {
$self->{output}->output_add(severity => 'OK',
short_msg => "Buffer creation...");
$self->{output}->display();
$self->{output}->exit();
}
my @exits;
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
}
}
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
my $extra_label = '';
$extra_label = '_' . $instance_output if ($num > 1);
my $str_output = "";
my $str_append = '';
foreach (keys %{$maps_counters}) {
$str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
$str_append = ', ';
my ($warning, $critical);
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
$warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
$critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
}
$self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
warning => $warning,
critical => $critical);
}
$self->{output}->output_add(severity => $exit,
short_msg => $str_output);
$self->{output}->display();
$self->{output}->exit();
};
1;
__END__
=head1 MODE
Check Varnish Cache with varnishstat Command
=over 8
=item B<--remote>
If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--command>
Varnishstat Binary Filename (Default: varnishstat)
=item B<--command-path>
Directory Path to Varnishstat Binary File (Default: /usr/bin)
=item B<--command-options>
Parameter for Binary File (Default: ' -1 ')
=item B<--warning-*>
Warning Threshold for:
n_sess_mem => N struct sess_mem,
n_sess => N struct sess,
n_object => N struct object,
n_vampireobject => N unresurrected objects,
n_objectcore => N struct objectcore,
n_objecthead => N struct objecthead,
n_waitinglist => N struct waitinglist,
n_vbc => N struct vbc,
n_backend => N backends,
n_expired => N expired objects,
n_lru_nuked => N LRU nuked objects,
n_lru_moved => N LRU moved objects
=item B<--critical-*>
Critical Threshold for:
n_sess_mem => N struct sess_mem,
n_sess => N struct sess,
n_object => N struct object,
n_vampireobject => N unresurrected objects,
n_objectcore => N struct objectcore,
n_objecthead => N struct objecthead,
n_waitinglist => N struct waitinglist,
n_vbc => N struct vbc,
n_backend => N backends,
n_expired => N expired objects,
n_lru_nuked => N LRU nuked objects,
n_lru_moved => N LRU moved objects
=back
=cut

View File

@ -1,242 +0,0 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::varnish::local::mode::objects;
use base qw(centreon::plugins::mode);
use centreon::plugins::misc;
use centreon::plugins::statefile;
use Digest::MD5 qw(md5_hex);
my $maps_counters = {
n_objsendfile => { thresholds => {
warning_objsendfile => { label => 'warning-objsendfile', exit_value => 'warning' },
critical_objsendfile => { label => 'critical-objsendfile', exit_value => 'critical' },
},
output_msg => 'Objects sent with sendfile: %.2f',
factor => 1, unit => '',
},
n_objwrite => { thresholds => {
warning_objwrite => { label => 'warning-objwrite', exit_value => 'warning' },
critical_objwrite => { label => 'critical-objwrite', exit_value => 'critical' },
},
output_msg => 'Objects sent with write: %.2f',
factor => 1, unit => '',
},
n_objoverflow => { thresholds => {
warning_objoverflow => { label => 'warning-objoverflow', exit_value => 'warning' },
critical_objoverflow => { label => 'critical-objoverflow', exit_value => 'critical' },
},
output_msg => 'Objects overflowing workspace: %.2f',
factor => 1, unit => '',
},
};
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"remote" => { name => 'remote' },
"ssh-option:s@" => { name => 'ssh_option' },
"ssh-path:s" => { name => 'ssh_path' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 30 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command', default => 'varnishstat' },
"command-path:s" => { name => 'command_path', default => '/usr/bin' },
"command-options:s" => { name => 'command_options', default => ' -1 ' },
"command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
});
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
$options{options}->add_options(arguments => {
$maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s' => { name => $name },
});
};
};
$self->{instances_done} = {};
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
return $self;
};
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
$self->{output}->option_exit();
};
};
};
$self->{statefile_value}->check_options(%options);
};
sub getdata {
my ($self, %options) = @_;
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
#print $stdout;
foreach (split(/\n/, $stdout)) {
#client_conn 7390867 1.00 Client connections
# - Symbolic entry name
# - Value
# - Per-second average over process lifetime, or a period if the value can not be averaged
# - Descriptive text
if (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
#print "FOUND: " . $1 . "=" . $2 . "\n";
$self->{result}->{$1} = $2;
};
};
};
sub run {
my ($self, %options) = @_;
$self->getdata();
$self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
$self->{result}->{last_timestamp} = time();
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
# Calculate
my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
$delta_time = 1 if ($delta_time == 0); # One seconds ;)
foreach (keys %{$maps_counters}) {
#print $_ . "\n";
$self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_'); # Get Data from Cache
$self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
$self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
};
# Write Cache if not there
$self->{statefile_value}->write(data => $self->{result});
if (!defined($old_timestamp)) {
$self->{output}->output_add(severity => 'OK',
short_msg => "Buffer creation...");
$self->{output}->display();
$self->{output}->exit();
}
my @exits;
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
}
}
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
my $extra_label = '';
$extra_label = '_' . $instance_output if ($num > 1);
my $str_output = "";
my $str_append = '';
foreach (keys %{$maps_counters}) {
$str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
$str_append = ', ';
my ($warning, $critical);
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
$warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
$critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
}
$self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
warning => $warning,
critical => $critical);
}
$self->{output}->output_add(severity => $exit,
short_msg => $str_output);
$self->{output}->display();
$self->{output}->exit();
};
1;
__END__
=head1 MODE
Check Varnish Cache with varnishstat Command
=over 8
=item B<--remote>
If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--command>
Varnishstat Binary Filename (Default: varnishstat)
=item B<--command-path>
Directory Path to Varnishstat Binary File (Default: /usr/bin)
=item B<--command-options>
Parameter for Binary File (Default: ' -1 ')
=item B<--warning-*>
Warning Threshold for:
objsendfile => Objects sent with sendfile,
objwrite => Objects sent with write,
objoverflow => Objects overflowing workspace
=item B<--critical-*>
Critical Threshold for:
objsendfile => Objects sent with sendfile,
objwrite => Objects sent with write,
objoverflow => Objects overflowing workspace
=back
=cut

View File

@ -1,252 +0,0 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::varnish::local::mode::sessions;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use JSON;
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'sessions', type => 0, skipped_code => { -10 => 1 } },
];
$self->{maps_counters}->{sessions} = [
{ label => 'accepted', set => {
key_values => [ { name => 'sess_conn', diff => 1 } ],
output_template => 'Session accepted: %.2f/s', output_error_template => "Session accepted: %s",
per_second => 1,
perfdatas => [
{ label => 'sess_conn', value => 'sess_conn_per_second', template => '%.2f',
min => 0 },
],
}
},
{ label => 'dropped', set => {
key_values => [ { name => 'sess_drop', diff => 1 } ],
output_template => 'Session dropped: %.2f/s', output_error_template => "Session dropped: %s",
per_second => 1,
perfdatas => [
{ label => 'sess_drop', value => 'sess_drop_per_second', template => '%.2f',
min => 0 },
],
}
},
{ label => 'failed', set => {
key_values => [ { name => 'sess_fail', diff => 1 } ],
output_template => 'Session fail: %.2f/s', output_error_template => "Session fail: %s",
per_second => 1,
perfdatas => [
{ label => 'sess_fail', value => 'sess_fail_per_second', template => '%.2f',
min => 0 },
],
}
},
{ label => 'pipeoverflow', set => {
key_values => [ { name => 'sess_pipe_overflow', diff => 1 } ],
output_template => 'Sessions pipe overflow: %.2f/s', output_error_template => "Sessions pipe overflow: %s",
per_second => 1,
perfdatas => [
{ label => 'sess_pipe_overflow', value => 'sess_pipe_overflow_per_second', template => '%.2f',
min => 0 },
],
}
},
{ label => 'queued', set => {
key_values => [ { name => 'sess_queued' , diff => 1 } ],
output_template => 'Session queued: %.2f/s', output_error_template => "Session queued: %s",
per_second => 1,
perfdatas => [
{ label => 'sess_queued', value => 'sess_queued_per_second', template => '%.2f',
min => 0 },
],
}
},
{ label => 'dropped', set => {
key_values => [ { name => 'sess_dropped' , diff => 1 } ],
output_template => 'Session dropped: %.2f/s', output_error_template => "Session dropped: %s",
per_second => 1,
perfdatas => [
{ label => 'sess_dropped', value => 'sess_dropped_per_second', template => '%.2f',
min => 0 },
],
}
},
{ label => 'readahead', set => {
key_values => [ { name => 'sess_readahead' , diff => 1 } ],
output_template => 'Session readahead: %.2f/s', output_error_template => "Session readahead: %s",
per_second => 1,
perfdatas => [
{ label => 'sess_readahead', value => 'sess_readahead_per_second', template => '%.2f',
min => 0 },
],
}
},
{ label => 'closed', set => {
key_values => [ { name => 'sess_closed' , diff => 1 } ],
output_template => 'Session closed: %.2f/s', output_error_template => "Session closed: %s",
per_second => 1,
perfdatas => [
{ label => 'sess_closed', value => 'sess_closed_per_second', template => '%.2f',
min => 0 },
],
}
},
{ label => 'herd', set => {
key_values => [ { name => 'sess_herd' , diff => 1 } ],
output_template => 'Session herd: %.2f/s', output_error_template => "Session herd: %s",
per_second => 1,
perfdatas => [
{ label => 'sess_herd', value => 'sess_herd_per_second', template => '%.2f',
min => 0 },
],
}
},
{ label => 'linger', set => {
key_values => [ { name => 'sess_linger' , diff => 1 } ],
output_template => 'Session linger: %.2f/s', output_error_template => "Session linger: %s",
per_second => 1,
perfdatas => [
{ label => 'sess_linger', value => 'sess_linger_per_second', template => '%.2f',
min => 0 },
],
}
},
{ label => 'pipeline', set => {
key_values => [ { name => 'sess_pipeline' , diff => 1 } ],
output_template => 'Session pipeline: %.2f/s', output_error_template => "Session pipeline: %s",
per_second => 1,
perfdatas => [
{ label => 'sess_pipeline', value => 'sess_pipeline_per_second', template => '%.2f',
min => 0 },
],
}
},
],
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"remote" => { name => 'remote' },
"ssh-option:s@" => { name => 'ssh_option' },
"ssh-path:s" => { name => 'ssh_path' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 30 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command', default => 'varnishstat' },
"command-path:s" => { name => 'command_path', default => '/usr/bin' },
"command-options:s" => { name => 'command_options', default => ' -1 -j 2>&1' },
});
return $self;
};
sub manage_selection {
my ($self, %options) = @_;
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options});
# "MAIN.sess_conn": {"type": "MAIN", "value": 13598, "flag": "c", "description": "Sessions accepted"},
# "MAIN.sess_drop": {"type": "MAIN", "value": 0, "flag": "c", "description": "Sessions dropped"},
# "MAIN.sess_fail": {"type": "MAIN", "value": 0, "flag": "c", "description": "Session accept failures"},
# "MAIN.sess_pipe_overflow": {"type": "MAIN", "value": 0, "flag": "c", "description": "Session pipe overflow"},
# "MAIN.sess_queued": {"type": "MAIN", "value": 0, "flag": "c", "description": "Sessions queued for thread"},
# "MAIN.sess_dropped": {"type": "MAIN", "value": 0, "flag": "c", "description": "Sessions dropped for thread"},
# "MAIN.sess_closed": {"type": "MAIN", "value": 13211, "flag": "a", "description": "Session Closed"},
# "MAIN.sess_pipeline": {"type": "MAIN", "value": 0, "flag": "a", "description": "Session Pipeline"},
# "MAIN.sess_readahead": {"type": "MAIN", "value": 0, "flag": "a", "description": "Session Read Ahead"},
# "MAIN.sess_herd": {"type": "MAIN", "value": 26, "flag": "a", "description": "Session herd"},
my $json_data = decode_json($stdout);
$self->{cache_name} = "cache_varnish_" . $self->{mode} . '_' .
(defined($self->{option_results}->{hostname}) ? md5_hex($self->{option_results}->{hostname}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
foreach my $counter (keys %{$json_data}) {
next if ($counter !~ /^([A-Z])+\.sess_.*/);
my $value = $json_data->{$counter}->{value};
$counter =~ s/^([A-Z])+\.//;
$self->{sessions}->{$counter} = $value;
}
};
1;
__END__
=head1 MODE
Check Varnish Cache with varnishstat Command
=over 8
=item B<--remote>
If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--command>
Varnishstat Binary Filename (Default: varnishstat)
=item B<--command-path>
Directory Path to Varnishstat Binary File (Default: /usr/bin)
=item B<--command-options>
Parameter for Binary File (Default: ' -1 -j 2>&1')
=item B<--warning-*>
Warning Threshold per second.
Can be (accepted,closed,queued,failed,pipeline,readahead,linger,herd,dropped,pipeoverflow)
=item B<--critical-*>
Critical Threshold per second for:
Can be (accepted,closed,queued,failed,pipeline,readahead,linger,herd,dropped,pipeoverflow)
=back
=cut

View File

@ -1,196 +0,0 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::varnish::local::mode::shm;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use JSON;
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'shm', type => 0, skipped_code => { -10 => 1 } },
];
$self->{maps_counters}->{shm} = [
{ label => 'records', set => {
key_values => [ { name => 'shm_records', diff => 1 } ],
output_template => 'SHM Records: %.2f/s', output_error_template => "SHM Records: %s",
per_second => 1,
perfdatas => [
{ label => 'shm_records', value => 'shm_records_per_second', template => '%.2f',
min => 0 },
],
}
},
{ label => 'writes', set => {
key_values => [ { name => 'shm_writes', diff => 1 } ],
output_template => 'SHM Writes: %.2f/s', output_error_template => "SHM Writes: %s",
per_second => 1,
perfdatas => [
{ label => 'shm_writes', value => 'shm_writes_per_second', template => '%.2f',
min => 0 },
],
}
},
{ label => 'flushes', set => {
key_values => [ { name => 'shm_flushes', diff => 1 } ],
output_template => 'SHM Flushes: %.2f/s', output_error_template => "SHM Flushes: %s",
per_second => 1,
perfdatas => [
{ label => 'shm_flushes', value => 'shm_flushes_per_second', template => '%.2f',
min => 0 },
],
}
},
{ label => 'cont', set => {
key_values => [ { name => 'shm_cont', diff => 1 } ],
output_template => 'SHM Contention: %.2f/s', output_error_template => "SHM Contention: %s",
per_second => 1,
perfdatas => [
{ label => 'shm_cont', value => 'shm_cont_per_second', template => '%.2f',
min => 0 },
],
}
},
{ label => 'cycles', set => {
key_values => [ { name => 'shm_cycles', diff => 1 } ],
output_template => 'SHM Cycles: %.2f/s', output_error_template => "SHM Cycles: %s",
per_second => 1,
perfdatas => [
{ label => 'shm_cycles', value => 'shm_cycles_per_second', template => '%.2f',
min => 0 },
],
}
},
],
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"remote" => { name => 'remote' },
"ssh-option:s@" => { name => 'ssh_option' },
"ssh-path:s" => { name => 'ssh_path' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 30 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command', default => 'varnishstat' },
"command-path:s" => { name => 'command_path', default => '/usr/bin' },
"command-options:s" => { name => 'command_options', default => ' -1 -j 2>&1' },
});
return $self;
};
sub manage_selection {
my ($self, %options) = @_;
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options});
# "MAIN.shm_records": {"type": "MAIN", "value": 6992776, "flag": "a", "description": "SHM records"},
# "MAIN.shm_writes": {"type": "MAIN", "value": 3947244, "flag": "a", "description": "SHM writes"},
# "MAIN.shm_flushes": {"type": "MAIN", "value": 12354, "flag": "a", "description": "SHM flushes due to overflow"},
# "MAIN.shm_cont": {"type": "MAIN", "value": 564, "flag": "a", "description": "SHM MTX contention"},
# "MAIN.shm_cycles": {"type": "MAIN", "value": 3, "flag": "a", "description": "SHM cycles through buffer"},
my $json_data = decode_json($stdout);
$self->{cache_name} = "cache_varnish_" . $self->{mode} . '_' .
(defined($self->{option_results}->{hostname}) ? md5_hex($self->{option_results}->{hostname}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
foreach my $counter (keys %{$json_data}) {
next if ($counter !~ /shm/);
my $value = $json_data->{$counter}->{value};
$counter =~ s/^([A-Z])+\.//;
$self->{shm}->{$counter} = $value;
}
};
1;
__END__
=head1 MODE
Check Varnish Cache with varnishstat Command
=over 8
=item B<--remote>
If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--command>
Varnishstat Binary Filename (Default: varnishstat)
=item B<--command-path>
Directory Path to Varnishstat Binary File (Default: /usr/bin)
=item B<--command-options>
Parameter for Binary File (Default: ' -1 -j 2>&1')
=item B<--warning-*>
Warning Threshold for:
records => SHM records,
writes => SHM writes,
flushes => SHM flushes due to overflow,
cont => SHM MTX contention,
cycles => SHM cycles through buffer
=item B<--critical-*>
Critical Threshold for:
records => SHM records,
writes => SHM writes,
flushes => SHM flushes due to overflow,
cont => SHM MTX contention,
cycles => SHM cycles through buffer
=back
=cut

View File

@ -1,260 +0,0 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::varnish::local::mode::sms;
use base qw(centreon::plugins::mode);
use centreon::plugins::misc;
use centreon::plugins::statefile;
use Digest::MD5 qw(md5_hex);
my $maps_counters = {
sms_nreq => { thresholds => {
warning_nreq => { label => 'warning-nreq', exit_value => 'warning' },
critical_nreq => { label => 'critical-nreq', exit_value => 'critical' },
},
output_msg => 'SMS allocator requests: %.2f',
factor => 1, unit => '',
},
sms_nobj => { thresholds => {
warning_nobj => { label => 'warning-nobj', exit_value => 'warning' },
critical_nobj => { label => 'critical-nobj', exit_value => 'critical' },
},
output_msg => 'SMS outstanding allocations: %.2f',
factor => 1, unit => '',
},
sms_nbytes => { thresholds => {
warning_nbytes => { label => 'warning-nbytes', exit_value => 'warning' },
critical_nbytes => { label => 'critical-nbytes', exit_value => 'critical' },
},
output_msg => 'SMS outstanding bytes: %.2f',
factor => 1, unit => '',
},
sms_balloc => { thresholds => {
warning_balloc => { label => 'warning-balloc', exit_value => 'warning' },
critical_balloc => { label => 'critical-balloc', exit_value => 'critical' },
},
output_msg => 'SMS bytes allocated: %.2f',
factor => 1, unit => '',
},
sms_bfree => { thresholds => {
warning_bfree => { label => 'warning-bfree', exit_value => 'warning' },
critical_bfree => { label => 'critical-bfree', exit_value => 'critical' },
},
output_msg => 'SMS bytes freed: %.2f',
factor => 1, unit => '',
},
};
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"remote" => { name => 'remote' },
"ssh-option:s@" => { name => 'ssh_option' },
"ssh-path:s" => { name => 'ssh_path' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 30 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command', default => 'varnishstat' },
"command-path:s" => { name => 'command_path', default => '/usr/bin' },
"command-options:s" => { name => 'command_options', default => ' -1 ' },
"command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
});
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
$options{options}->add_options(arguments => {
$maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s' => { name => $name },
});
};
};
$self->{instances_done} = {};
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
return $self;
};
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
$self->{output}->option_exit();
};
};
};
$self->{statefile_value}->check_options(%options);
};
sub getdata {
my ($self, %options) = @_;
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
#print $stdout;
foreach (split(/\n/, $stdout)) {
#client_conn 7390867 1.00 Client connections
# - Symbolic entry name
# - Value
# - Per-second average over process lifetime, or a period if the value can not be averaged
# - Descriptive text
if (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
#print "FOUND: " . $1 . "=" . $2 . "\n";
$self->{result}->{$1} = $2;
};
};
};
sub run {
my ($self, %options) = @_;
$self->getdata();
$self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
$self->{result}->{last_timestamp} = time();
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
# Calculate
my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
$delta_time = 1 if ($delta_time == 0); # One seconds ;)
foreach (keys %{$maps_counters}) {
#print $_ . "\n";
$self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_'); # Get Data from Cache
$self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
$self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
};
# Write Cache if not there
$self->{statefile_value}->write(data => $self->{result});
if (!defined($old_timestamp)) {
$self->{output}->output_add(severity => 'OK',
short_msg => "Buffer creation...");
$self->{output}->display();
$self->{output}->exit();
}
my @exits;
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
}
}
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
my $extra_label = '';
$extra_label = '_' . $instance_output if ($num > 1);
my $str_output = "";
my $str_append = '';
foreach (keys %{$maps_counters}) {
$str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
$str_append = ', ';
my ($warning, $critical);
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
$warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
$critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
}
$self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
warning => $warning,
critical => $critical);
}
$self->{output}->output_add(severity => $exit,
short_msg => $str_output);
$self->{output}->display();
$self->{output}->exit();
};
1;
__END__
=head1 MODE
Check Varnish Cache with varnishstat Command
=over 8
=item B<--remote>
If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--command>
Varnishstat Binary Filename (Default: varnishstat)
=item B<--command-path>
Directory Path to Varnishstat Binary File (Default: /usr/bin)
=item B<--command-options>
Parameter for Binary File (Default: ' -1 ')
=item B<--warning-*>
Warning Threshold for:
nreq => SMS allocator requests,
nobj => SMS outstanding allocations,
nbytes => SMS outstanding bytes,
balloc => SMS bytes allocated,
bfree => SMS bytes freed
=item B<--critical-*>
Critical Threshold for:
nreq => SMS allocator requests,
nobj => SMS outstanding allocations,
nbytes => SMS outstanding bytes,
balloc => SMS bytes allocated,
bfree => SMS bytes freed
=back
=cut

View File

@ -0,0 +1,344 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::varnish::local::mode::stats;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use JSON::XS;
sub configure_varnish_stats {
my ($self, %options) = @_;
$self->{varnish_stats} = [
{ entry => 'client_conn', nlabel => 'connections.client.accepted.persecond', display_ok => 1, diff => 1, per_second => 1 },
{ entry => 'client_drop', nlabel => 'connections.client.dropped.persecond', display_ok => 1, diff => 1, per_second => 1 },
{ entry => 'client_req', nlabel => 'connections.client.request.received.persecond', display_ok => 1, diff => 1, per_second => 1 },
{ entry => 'client_drop_late', nlabel => 'connections.client.dropped.late.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'client_req_400', nlabel => 'connections.client.request400.received.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'client_req_411', nlabel => 'connections.client.request411.received.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'client_req_413', nlabel => 'connections.client.request413.received.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'client_req_417', nlabel => 'connections.client.request417.received.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'backend_conn', nlabel => 'backends.connections.success.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'backend_unhealthy', nlabel => 'backends.connections.unhealthy.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'backend_busy', nlabel => 'backends.connections.busy.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'backend_fail', nlabel => 'backends.connections.fail.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'backend_reuse', nlabel => 'backends.connections.reuse.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'backend_recycle', nlabel => 'backends.connections.recycle.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'backend_retry', nlabel => 'backends.connections.retry.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'backend_req', nlabel => 'backends.requests.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'cache_hit', nlabel => 'cache.hit.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'cache_hitpass', nlabel => 'cache.hitpass.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'cache_miss', nlabel => 'cache.miss.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'n_sess_mem', nlabel => 'structure.session.memory.count', display_ok => 0 },
{ entry => 'n_sess', nlabel => 'structure.session.count', display_ok => 0 },
{ entry => 'n_sess', nlabel => 'structure.session.count', display_ok => 0 },
{ entry => 'n_object', nlabel => 'structure.object.count', display_ok => 0 },
{ entry => 'n_vampireobject', nlabel => 'object.unresurrected.count', display_ok => 0 },
{ entry => 'n_objectcore', nlabel => 'structure.objectcore.count', display_ok => 0 },
{ entry => 'n_objecthead', nlabel => 'structure.objecthead.count', display_ok => 0 },
{ entry => 'n_waitinglist', nlabel => 'structure.waitinglist.count', display_ok => 0 },
{ entry => 'n_vbc', nlabel => 'structure.vbc.count', display_ok => 0 },
{ entry => 'n_backend', nlabel => 'backend.count', display_ok => 0 },
{ entry => 'n_expired', nlabel => 'object.expired.count', display_ok => 0 },
{ entry => 'n_lru_nuked', nlabel => 'object.lru.nuked.count', display_ok => 0 },
{ entry => 'n_lru_moved', nlabel => 'object.lru.moved.count', display_ok => 0 },
{ entry => 'n_objsendfile', nlabel => 'object.sent.file.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'n_objwrite', nlabel => 'object.sent.write.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'n_objoverflow', nlabel => 'object.overflow.workspace.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'shm_records', nlabel => 'shm.records.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'shm_writes', nlabel => 'shm.writes.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'shm_flushes', nlabel => 'shm.flushes.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'shm_cont', nlabel => 'shm.contentions.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'shm_cycles', nlabel => 'shm.cycles.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'sms_nreq', nlabel => 'sms.allocator.requests.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'sms_nobj', nlabel => 'sms.outstanding.allocations.count', display_ok => 0 },
{ entry => 'sms_nbytes', nlabel => 'sms.outstanding.bytes', display_ok => 0, custom_output => $self->can('custom_output_scale_bytes') },
{ entry => 'sms_balloc', nlabel => 'sms.outstanding.allocated.bytes', display_ok => 0, custom_output => $self->can('custom_output_scale_bytes') },
{ entry => 'sms_bfree', nlabel => 'sms.outstanding.freed.bytes', display_ok => 0, custom_output => $self->can('custom_output_scale_bytes') },
{ entry => 'fetch_head', nlabel => 'fetch.head.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'fetch_length', nlabel => 'fetch.length.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'fetch_chunked', nlabel => 'fetch.chunked.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'fetch_eof', nlabel => 'fetch.eof.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'fetch_bad', nlabel => 'fetch.badheaders.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'fetch_close', nlabel => 'fetch.close.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'fetch_oldhttp', nlabel => 'fetch.oldhttp.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'fetch_zero', nlabel => 'fetch.zero.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'fetch_failed', nlabel => 'fetch.failed.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'fetch_1xx', nlabel => 'fetch.1xx.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'fetch_204', nlabel => 'fetch.204.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'fetch_304', nlabel => 'fetch.304.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'n_ban', nlabel => 'ban.total.active.count', display_ok => 0 },
{ entry => 'n_ban_add', nlabel => 'ban.new.added.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'n_ban_retire', nlabel => 'ban.old.deleted.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'n_ban_obj_test', nlabel => 'ban.object.tested.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'n_ban_re_test', nlabel => 'ban.object.tested.regexp.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'n_ban_dups', nlabel => 'ban.duplicate.removed.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'dir_dns_lookups', nlabel => 'dns.director.lookups.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'dir_dns_failed', nlabel => 'dns.director.lookups.failed.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'dir_dns_hit', nlabel => 'dns.director.lookups.cachehit.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'dir_dns_cache_full', nlabel => 'dns.director.cache.full.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'esi_errors', nlabel => 'esi.parse.errors.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'esi_warnings', nlabel => 'esi.parse.warnings.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'hcb_nolock', nlabel => 'hck.lookups.nolock.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'hcb_lock', nlabel => 'hck.lookups.lock.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'hcb_insert', nlabel => 'hck.inserts.persecond', display_ok => 0, diff => 1, per_second => 1 },
{ entry => 'n_vcl', nlabel => 'vlc.total.count', display_ok => 0, diff => 1 },
{ entry => 'n_vcl_avail', nlabel => 'vlc.available.count', display_ok => 0, diff => 1 },
{ entry => 'n_vcl_discard', nlabel => 'vlc.discarded.count', display_ok => 0, diff => 1 },
{ entry => 'sess_conn', nlabel => 'sessions.accepted.count', display_ok => 0, diff => 1 },
{ entry => 'sess_drop', nlabel => 'sessions.dropped.count', display_ok => 0, diff => 1 },
{ entry => 'sess_fail', nlabel => 'sessions.failed.count', display_ok => 0, diff => 1 },
{ entry => 'sess_pipe_overflow', nlabel => 'sessions.pipe.overflow.count', display_ok => 0, diff => 1 },
{ entry => 'sess_queued', nlabel => 'sessions.queued.count', display_ok => 0, diff => 1 },
{ entry => 'sess_readahead', nlabel => 'sessions.readahead.count', display_ok => 0, diff => 1 },
{ entry => 'sess_closed', nlabel => 'sessions.closed.count', display_ok => 0, diff => 1 },
{ entry => 'sess_herd', nlabel => 'sessions.herd.count', display_ok => 0, diff => 1 },
{ entry => 'sess_linger', nlabel => 'sessions.linger.count', display_ok => 0, diff => 1 },
{ entry => 'sess_closed', nlabel => 'sessions.closed.count', display_ok => 0, diff => 1 },
{ entry => 'sess_pipeline', nlabel => 'sessions.pipeline.count', display_ok => 0, diff => 1 },
{ entry => 'threads', nlabel => 'threads.total.count', display_ok => 0 },
{ entry => 'threads_created', nlabel => 'threads.created.count', display_ok => 0, diff => 1 },
{ entry => 'threads_limited', nlabel => 'threads.limited.count', display_ok => 0, diff => 1 },
{ entry => 'threads_destroyed', nlabel => 'threads.destroyed.count', display_ok => 0, diff => 1 },
{ entry => 'threads_failed', nlabel => 'threads.failed.count', display_ok => 0, diff => 1 },
{ entry => 'thread_queue_len', nlabel => 'threads.queue.length.count', display_ok => 0 },
{ entry => 's_sess', nlabel => 'total.sessions.seen.count', display_ok => 0, diff => 1 },
{ entry => 's_req', nlabel => 'total.requests.count', display_ok => 0, diff => 1 },
{ entry => 's_fetch', nlabel => 'total.backends.fetch.count', display_ok => 0, diff => 1 },
{ entry => 'n_wrk', nlabel => 'workers.threads.count', display_ok => 0 },
{ entry => 'n_wrk_create', nlabel => 'workers.threads.created.count', display_ok => 0, diff => 1 },
{ entry => 'n_wrk_failed', nlabel => 'workers.threads.failed.count', display_ok => 0, diff => 1 },
{ entry => 'n_wrk_max', nlabel => 'workers.threads.limited.count', display_ok => 0, diff => 1 },
{ entry => 'n_wrk_lqueue', nlabel => 'workers.requests.queue.length.count', display_ok => 0, diff => 1 },
{ entry => 'n_wrk_queued', nlabel => 'workers.requests.queued.count', display_ok => 0, diff => 1 },
{ entry => 'n_wrk_drop', nlabel => 'workers.requests.dropped.count', display_ok => 0, diff => 1 },
];
}
sub custom_output_scale_bytes {
my ($self, %options) = @_;
my $label = $self->{label};
$label =~ s/-/_/g;
my ($value, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{$label . '_absolute'});
my $msg = sprintf('%s: %.2f %s', $self->{result_values}->{$label . '_description_absolute'}, $value, $unit);
return $msg;
}
sub custom_output_second {
my ($self, %options) = @_;
my $label = $self->{label};
$label =~ s/-/_/g;
my $msg = sprintf('%s: %.2f/s', $self->{result_values}->{$label . '_description_absolute'}, $self->{result_values}->{$label . '_per_second'});
return $msg;
}
sub custom_output {
my ($self, %options) = @_;
my $label = $self->{label};
$label =~ s/-/_/g;
my $msg = sprintf('%s: %s', $self->{result_values}->{$label . '_description_absolute'}, $self->{result_values}->{$label . '_absolute'});
return $msg;
}
sub set_counters {
my ($self, %options) = @_;
$self->configure_varnish_stats();
$self->{maps_counters_type} = [
{ name => 'global', type => 0, skipped_code => { -10 => 1 } },
];
$self->{maps_counters}->{global} = [];
foreach (@{$self->{varnish_stats}}) {
my $label = $_->{entry};
$label =~ s/_/-/g;
push @{$self->{maps_counters}->{global}},
{ label => $label, nlabel => $_->{nlabel}, display_ok => $_->{display_ok}, set => {
key_values => [ { name => $_->{entry}, diff => $_->{diff} }, { name => $_->{entry}. '_description' } ],
closure_custom_output => defined($_->{custom_output}) ? $_->{custom_output} :
(defined($_->{per_second}) ? $self->can('custom_output_second') : $self->can('custom_output')),
per_second => $_->{per_second},
perfdatas => [
{ label => $_->{entry}, value => $_->{entry} . (defined($_->{per_second}) ? '_per_second' : '_absolute'),
template => defined($_->{per_second}) ? '%.2f' : '%s',
min => 0 },
],
}
}
;
}
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments => {
'hostname:s' => { name => 'hostname' },
'remote' => { name => 'remote' },
'ssh-option:s@' => { name => 'ssh_option' },
'ssh-path:s' => { name => 'ssh_path' },
'ssh-command:s' => { name => 'ssh_command', default => 'ssh' },
'timeout:s' => { name => 'timeout', default => 30 },
'sudo' => { name => 'sudo' },
'command:s' => { name => 'command', default => 'varnishstat' },
'command-path:s' => { name => 'command_path', default => '/usr/bin' },
'command-options:s' => { name => 'command_options', default => ' -1 -j 2>&1' },
});
return $self;
}
sub check_varnish_old {
my ($self, %options) = @_;
return if (!defined($options{json}->{uptime}));
# "cache_hit": {"value": 56320, "flag": "a", "description": "Cache hits"},
# "cache_hitpass": {"value": 0, "flag": "a", "description": "Cache hits for pass"},
foreach (@{$self->{varnish_stats}}) {
next if (!defined($options{json}->{$_->{entry}}));
$self->{global}->{$_->{entry}} = $options{json}->{$_->{entry}}->{value};
$self->{global}->{$_->{entry} . '_description'} = $options{json}->{$_->{entry}}->{description};
}
}
sub check_varnish_new {
my ($self, %options) = @_;
return if (!defined($options{json}->{'MAIN.uptime'}));
# "MAIN.cache_hit": {"type": "MAIN", "value": 18437, "flag": "a", "description": "Cache hits"},
# "MAIN.cache_hitpass": {"type": "MAIN", "value": 3488, "flag": "a", "description": "Cache hits for pass"},
# "MAIN.cache_miss": {"type": "MAIN", "value": 5782, "flag": "a", "description": "Cache misses"},
foreach (@{$self->{varnish_stats}}) {
next if (!defined($options{json}->{'MAIN.' . $_->{entry}}));
$self->{global}->{$_->{entry}} = $options{json}->{'MAIN.' . $_->{entry}}->{value};
$self->{global}->{$_->{entry} . '_description'} = $options{json}->{'MAIN.' . $_->{entry}}->{description};
}
}
sub manage_selection {
my ($self, %options) = @_;
my ($stdout) = centreon::plugins::misc::execute(
output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options}
);
$self->{global} = {};
my $content;
eval {
$content = JSON::XS->new->utf8->decode($stdout);
};
if ($@) {
$self->{output}->add_option_msg(short_msg => "Cannot decode json response: $@");
$self->{output}->option_exit();
}
$self->check_varnish_old(json => $content);
$self->check_varnish_new(json => $content);
$self->{cache_name} = "cache_varnish_" . $self->{mode} . '_' .
(defined($self->{option_results}->{hostname}) ? md5_hex($self->{option_results}->{hostname}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
};
1;
__END__
=head1 MODE
Check statistics with varnishstat command
=over 8
=item B<--remote>
If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--command>
Varnishstat Binary Filename (Default: varnishstat)
=item B<--command-path>
Directory Path to Varnishstat Binary File (Default: /usr/bin)
=item B<--command-options>
Parameter for Binary File (Default: ' -1 -j 2>&1')
=item B<--warning-*>
Warning Threshold for:
hit => Cache Hits,
hitpass => Cache hits for Pass,
miss => Cache Misses
=item B<--critical-*>
Critical Threshold for:
hit => Cache Hits,
hitpass => Cache hits for Pass,
miss => Cache Misses
=back
=cut

View File

@ -1,203 +0,0 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::varnish::local::mode::threads;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use JSON;
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'threads', type => 0, skipped_code => { -10 => 1 } },
];
$self->{maps_counters}->{threads} = [
{ label => 'total', set => {
key_values => [ { name => 'threads' } ],
output_template => 'Total Threads: %d', output_error_template => "Total Threads: %s",
perfdatas => [
{ label => 'total', value => 'threads_absolute', template => '%d',
min => 0 },
],
}
},
{ label => 'created', set => {
key_values => [ { name => 'threads_created', diff => 1 } ],
output_template => 'Thread created: %.2f/s', output_error_template => "Thread created: %s",
per_second => 1,
perfdatas => [
{ label => 'created', value => 'threads_created_per_second', template => '%.2f',
min => 0 },
],
}
},
{ label => 'limited', set => {
key_values => [ { name => 'threads_limited', diff => 1 } ],
output_template => 'Thread limited: %.2f/s', output_error_template => "Thread limited: %s",
per_second => 1,
perfdatas => [
{ label => 'limited', value => 'threads_limited_per_second', template => '%.2f',
min => 0 },
],
}
},
{ label => 'destroyed', set => {
key_values => [ { name => 'threads_destroyed', diff => 1 } ],
output_template => 'Thread destroyed: %.2f/s', output_error_template => "Thread destroyed: %s",
per_second => 1,
perfdatas => [
{ label => 'destroyed', value => 'threads_destroyed_per_second', template => '%.2f',
min => 0 },
],
}
},
{ label => 'failed', set => {
key_values => [ { name => 'threads_failed', diff => 1 } ],
output_template => 'Threads fail: %.2f/s', output_error_template => "Threads fail: %s",
per_second => 1,
perfdatas => [
{ label => 'failed', value => 'threads_failed_per_second', template => '%.2f',
min => 0 },
],
}
},
{ label => 'queue', set => {
key_values => [ { name => 'thread_queue_len' } ],
output_template => 'Thread queue lenght: %d', output_error_template => "Thread queue lenght: %d",
perfdatas => [
{ label => 'queue_lenght', value => 'thread_queue_len_absolute', template => '%d',
min => 0 },
],
}
},
],
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"remote" => { name => 'remote' },
"ssh-option:s@" => { name => 'ssh_option' },
"ssh-path:s" => { name => 'ssh_path' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 30 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command', default => 'varnishstat' },
"command-path:s" => { name => 'command_path', default => '/usr/bin' },
"command-options:s" => { name => 'command_options', default => ' -1 -j 2>&1' },
});
return $self;
};
sub manage_selection {
my ($self, %options) = @_;
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options});
# "MAIN.threads_limited": {"type": "MAIN", "value": 0, "flag": "c", "description": "Threads hit max"},
# "MAIN.threads_created": {"type": "MAIN", "value": 100, "flag": "c", "description": "Threads created"},
# "MAIN.threads_destroyed": {"type": "MAIN", "value": 0, "flag": "c", "description": "Threads destroyed"},
# "MAIN.threads_failed": {"type": "MAIN", "value": 0, "flag": "c", "description": "Thread creation failed"},
# "MAIN.thread_queue_len": {"type": "MAIN", "value": 0, "flag": "g", "description": "Length of session queue"},
my $json_data = decode_json($stdout);
$self->{cache_name} = "cache_varnish_" . $self->{mode} . '_' .
(defined($self->{option_results}->{hostname}) ? md5_hex($self->{option_results}->{hostname}) : md5_hex('all')) . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
foreach my $counter (keys %{$json_data}) {
next if ($counter !~ /^([A-Z])+\.thread.*/);
my $value = $json_data->{$counter}->{value};
$counter =~ s/^([A-Z])+\.//;
print "$counter ===> $value \n";
$self->{threads}->{$counter} = $value;
}
};
1;
__END__
=head1 MODE
Check Varnish 4 Cache with varnishstat Command
=over 8
=item B<--remote>
If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--command>
Varnishstat Binary Filename (Default: varnishstat)
=item B<--command-path>
Directory Path to Varnishstat Binary File (Default: /usr/bin)
=item B<--command-options>
Parameter for Binary File (Default: ' -1 -j 2>&1')
=item B<--warning-*>
Warning Threshold for threads.
Can be:
(created, destroyed, limited, failed) [per sec]
(total, queue lenght) [absolute]
=item B<--critical-*>
Warning Threshold for threads.
Can be:
(created, destroyed, limited, failed) [per sec]
(total, queue lenght) [absolute]
=back
=cut

View File

@ -1,287 +0,0 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::varnish::local::mode::totals;
use base qw(centreon::plugins::mode);
use centreon::plugins::misc;
use centreon::plugins::statefile;
use Digest::MD5 qw(md5_hex);
my $maps_counters = {
s_sess => { thresholds => {
warning_sess => { label => 'warning-sess', exit_value => 'warning' },
critical_sess => { label => 'critical-sess', exit_value => 'critical' },
},
output_msg => 'Total Sessions: %.2f',
factor => 1, unit => '',
},
s_req => { thresholds => {
warning_req => { label => 'warning-req', exit_value => 'warning' },
critical_req => { label => 'critical-req', exit_value => 'critical' },
},
output_msg => 'Total Requests: %.2f',
factor => 1, unit => '',
},
s_pipe => { thresholds => {
warning_pipe => { label => 'warning-pipe', exit_value => 'warning' },
critical_pipe => { label => 'critical-pipe', exit_value => 'critical' },
},
output_msg => 'Total pipe: %.2f',
factor => 1, unit => '',
},
s_pass => { thresholds => {
warning_pass => { label => 'warning-pass', exit_value => 'warning' },
critical_pass => { label => 'critical-pass', exit_value => 'critical' },
},
output_msg => 'Total pass: %.2f',
factor => 1, unit => '',
},
s_fetch => { thresholds => {
warning_fetch => { label => 'warning-fetch', exit_value => 'warning' },
critical_fetch => { label => 'critical-fetch', exit_value => 'critical' },
},
output_msg => 'Total fetch: %.2f',
factor => 1, unit => '',
},
s_hdrbytes => { thresholds => {
warning_hdrbytes => { label => 'warning-hdrbytes', exit_value => 'warning' },
critical_hdrbytes => { label => 'critical-hdrbytes', exit_value => 'critical' },
},
output_msg => 'Total header bytes: %.2f',
factor => 1, unit => '',
},
s_bodybytes => { thresholds => {
warning_bodybytes => { label => 'warning-bodybytes', exit_value => 'warning' },
critical_bodybytes => { label => 'critical-bodybytes', exit_value => 'critical' },
},
output_msg => 'Total body bytes: %.2f',
factor => 1, unit => '',
},
accept_fail => { thresholds => {
warning_fail => { label => 'warning-fail', exit_value => 'warning' },
critical_fail => { label => 'critical-fail', exit_value => 'critical' },
},
output_msg => 'Accept failures: %.2f',
factor => 1, unit => '',
},
};
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"remote" => { name => 'remote' },
"ssh-option:s@" => { name => 'ssh_option' },
"ssh-path:s" => { name => 'ssh_path' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 30 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command', default => 'varnishstat' },
"command-path:s" => { name => 'command_path', default => '/usr/bin' },
"command-options:s" => { name => 'command_options', default => ' -1 ' },
"command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
});
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
$options{options}->add_options(arguments => {
$maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s' => { name => $name },
});
};
};
$self->{instances_done} = {};
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
return $self;
};
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
$self->{output}->option_exit();
};
};
};
$self->{statefile_value}->check_options(%options);
};
sub getdata {
my ($self, %options) = @_;
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
#print $stdout;
foreach (split(/\n/, $stdout)) {
#client_conn 7390867 1.00 Client connections
# - Symbolic entry name
# - Value
# - Per-second average over process lifetime, or a period if the value can not be averaged
# - Descriptive text
if (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
#print "FOUND: " . $1 . "=" . $2 . "\n";
$self->{result}->{$1} = $2;
};
};
};
sub run {
my ($self, %options) = @_;
$self->getdata();
$self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
$self->{result}->{last_timestamp} = time();
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
# Calculate
my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
$delta_time = 1 if ($delta_time == 0); # One seconds ;)
foreach (keys %{$maps_counters}) {
#print $_ . "\n";
$self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_'); # Get Data from Cache
$self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
$self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
};
# Write Cache if not there
$self->{statefile_value}->write(data => $self->{result});
if (!defined($old_timestamp)) {
$self->{output}->output_add(severity => 'OK',
short_msg => "Buffer creation...");
$self->{output}->display();
$self->{output}->exit();
}
my @exits;
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
}
}
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
my $extra_label = '';
$extra_label = '_' . $instance_output if ($num > 1);
my $str_output = "";
my $str_append = '';
foreach (keys %{$maps_counters}) {
$str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
$str_append = ', ';
my ($warning, $critical);
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
$warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
$critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
}
$self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
warning => $warning,
critical => $critical);
}
$self->{output}->output_add(severity => $exit,
short_msg => $str_output);
$self->{output}->display();
$self->{output}->exit();
};
1;
__END__
=head1 MODE
Check Varnish Cache with varnishstat Command
=over 8
=item B<--remote>
If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--command>
Varnishstat Binary Filename (Default: varnishstat)
=item B<--command-path>
Directory Path to Varnishstat Binary File (Default: /usr/bin)
=item B<--command-options>
Parameter for Binary File (Default: ' -1 ')
=item B<--warning-*>
Warning Threshold for:
sess => Total Sessions,
req => Total Requests,
pipe => Total pipe,
pass => Total pass,
fetch => Total fetch,
hdrbytes => Total header bytes,
bodybytes => Total body bytes,
fail => Accept failures
=item B<--critical-*>
Critical Threshold for:
sess => Total Sessions,
req => Total Requests,
pipe => Total pipe,
pass => Total pass,
fetch => Total fetch,
hdrbytes => Total header bytes,
bodybytes => Total body bytes,
fail => Accept failures
=back
=cut

View File

@ -1,222 +0,0 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::varnish::local::mode::uptime;
use base qw(centreon::plugins::mode);
use centreon::plugins::misc;
use centreon::plugins::statefile;
use Digest::MD5 qw(md5_hex);
my $maps_counters = {
uptime => { thresholds => {
warning => { label => 'warning', exit_value => 'warning' },
critical => { label => 'critical', exit_value => 'critical' },
},
output_msg => 'Uptime in sec: %.2f',
factor => 1, unit => '',
},
};
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"remote" => { name => 'remote' },
"ssh-option:s@" => { name => 'ssh_option' },
"ssh-path:s" => { name => 'ssh_path' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 30 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command', default => 'varnishstat' },
"command-path:s" => { name => 'command_path', default => '/usr/bin' },
"command-options:s" => { name => 'command_options', default => ' -1 ' },
"command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
});
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
$options{options}->add_options(arguments => {
$maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s' => { name => $name },
});
};
};
$self->{instances_done} = {};
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
return $self;
};
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
$self->{output}->option_exit();
};
};
};
$self->{statefile_value}->check_options(%options);
};
sub getdata {
my ($self, %options) = @_;
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
#print $stdout;
foreach (split(/\n/, $stdout)) {
#client_conn 7390867 1.00 Client connections
# - Symbolic entry name
# - Value
# - Per-second average over process lifetime, or a period if the value can not be averaged
# - Descriptive text
if (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
#print "FOUND: " . $1 . "=" . $2 . "\n";
$self->{result}->{$1} = $2;
};
};
};
sub run {
my ($self, %options) = @_;
$self->getdata();
$self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
$self->{result}->{last_timestamp} = time();
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
# Calculate
my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
$delta_time = 1 if ($delta_time == 0); # One seconds ;)
foreach (keys %{$maps_counters}) {
#print $_ . "\n";
$self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_'); # Get Data from Cache
$self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
$self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
};
# Write Cache if not there
$self->{statefile_value}->write(data => $self->{result});
if (!defined($old_timestamp)) {
$self->{output}->output_add(severity => 'OK',
short_msg => "Buffer creation...");
$self->{output}->display();
$self->{output}->exit();
}
my @exits;
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
}
}
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
my $extra_label = '';
$extra_label = '_' . $instance_output if ($num > 1);
my $str_output = "";
my $str_append = '';
foreach (keys %{$maps_counters}) {
$str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
$str_append = ', ';
my ($warning, $critical);
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
$warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
$critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
}
$self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
warning => $warning,
critical => $critical);
}
$self->{output}->output_add(severity => $exit,
short_msg => $str_output);
$self->{output}->display();
$self->{output}->exit();
};
1;
__END__
=head1 MODE
Check Varnish Cache with varnishstat Command
=over 8
=item B<--remote>
If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--command>
Varnishstat Binary Filename (Default: varnishstat)
=item B<--command-path>
Directory Path to Varnishstat Binary File (Default: /usr/bin)
=item B<--command-options>
Parameter for Binary File (Default: ' -1 ')
=item B<--warning>
Warning Threshold for Uptime
=item B<--critical>
Critical Threshold for Uptime
=back
=cut

View File

@ -1,243 +0,0 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::varnish::local::mode::vcl;
use base qw(centreon::plugins::mode);
use centreon::plugins::misc;
use centreon::plugins::statefile;
use Digest::MD5 qw(md5_hex);
#n_vcl_avail could be max from n_vcl
my $maps_counters = {
n_vcl => { thresholds => {
warning_total => { label => 'warning-total', exit_value => 'warning' },
critical_total => { label => 'critical-total', exit_value => 'critical' },
},
output_msg => 'N vcl total: %.2f',
factor => 1, unit => '',
},
n_vcl_avail => { thresholds => {
warning_avail => { label => 'warning-avail', exit_value => 'warning' },
critical_avail => { label => 'critical-avail', exit_value => 'critical' },
},
output_msg => 'N vcl available: %.2f',
factor => 1, unit => '',
},
n_vcl_discard => { thresholds => {
warning_discard => { label => 'warning-discard', exit_value => 'warning' },
critical_discard => { label => 'critical-discard', exit_value => 'critical' },
},
output_msg => 'N vcl discarded: %.2f',
factor => 1, unit => '',
},
};
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"remote" => { name => 'remote' },
"ssh-option:s@" => { name => 'ssh_option' },
"ssh-path:s" => { name => 'ssh_path' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 30 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command', default => 'varnishstat' },
"command-path:s" => { name => 'command_path', default => '/usr/bin' },
"command-options:s" => { name => 'command_options', default => ' -1 ' },
"command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
});
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
$options{options}->add_options(arguments => {
$maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s' => { name => $name },
});
};
};
$self->{instances_done} = {};
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
return $self;
};
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
$self->{output}->option_exit();
};
};
};
$self->{statefile_value}->check_options(%options);
};
sub getdata {
my ($self, %options) = @_;
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
#print $stdout;
foreach (split(/\n/, $stdout)) {
#client_conn 7390867 1.00 Client connections
# - Symbolic entry name
# - Value
# - Per-second average over process lifetime, or a period if the value can not be averaged
# - Descriptive text
if (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
#print "FOUND: " . $1 . "=" . $2 . "\n";
$self->{result}->{$1} = $2;
};
};
};
sub run {
my ($self, %options) = @_;
$self->getdata();
$self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
$self->{result}->{last_timestamp} = time();
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
# Calculate
my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
$delta_time = 1 if ($delta_time == 0); # One seconds ;)
foreach (keys %{$maps_counters}) {
#print $_ . "\n";
$self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_'); # Get Data from Cache
$self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
$self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
};
# Write Cache if not there
$self->{statefile_value}->write(data => $self->{result});
if (!defined($old_timestamp)) {
$self->{output}->output_add(severity => 'OK',
short_msg => "Buffer creation...");
$self->{output}->display();
$self->{output}->exit();
}
my @exits;
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
}
}
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
my $extra_label = '';
$extra_label = '_' . $instance_output if ($num > 1);
my $str_output = "";
my $str_append = '';
foreach (keys %{$maps_counters}) {
$str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
$str_append = ', ';
my ($warning, $critical);
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
$warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
$critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
}
$self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
warning => $warning,
critical => $critical);
}
$self->{output}->output_add(severity => $exit,
short_msg => $str_output);
$self->{output}->display();
$self->{output}->exit();
};
1;
__END__
=head1 MODE
Check Varnish Cache with varnishstat Command
=over 8
=item B<--remote>
If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--command>
Varnishstat Binary Filename (Default: varnishstat)
=item B<--command-path>
Directory Path to Varnishstat Binary File (Default: /usr/bin)
=item B<--command-options>
Parameter for Binary File (Default: ' -1 ')
=item B<--warning-*>
Warning Threshold for:
total => N vcl total,
avail => N vcl available,
discard => N vcl discarded
=item B<--critical-*>
Critical Threshold for:
total => N vcl total,
avail => N vcl available,
discard => N vcl discarded
=back
=cut

View File

@ -1,278 +0,0 @@
#
# Copyright 2019 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::varnish::local::mode::workers;
use base qw(centreon::plugins::mode);
use centreon::plugins::misc;
use centreon::plugins::statefile;
use Digest::MD5 qw(md5_hex);
my $maps_counters = {
n_wrk => { thresholds => {
warning_workers => { label => 'warning-workers', exit_value => 'warning' },
critical_workers => { label => 'critical-workers', exit_value => 'critical' },
},
output_msg => 'Backend conn. success: %.2f',
factor => 1, unit => '',
},
n_wrk_create => { thresholds => {
warning_create => { label => 'warning-create', exit_value => 'warning' },
critical_create => { label => 'critical-create', exit_value => 'critical' },
},
output_msg => 'Backend conn. not attempted: %.2f',
factor => 1, unit => '',
},
n_wrk_failed => { thresholds => {
warning_failed => { label => 'warning-failed', exit_value => 'warning' },
critical_failed => { label => 'critical-failed', exit_value => 'critical' },
},
output_msg => 'Backend conn. too many: %.2f',
factor => 1, unit => '',
},
n_wrk_max => { thresholds => {
warning_max => { label => 'warning-max', exit_value => 'warning' },
critical_max => { label => 'critical-max', exit_value => 'critical' },
},
output_msg => 'Backend conn. failures: %.2f',
factor => 1, unit => '',
},
n_wrk_lqueue => { thresholds => {
warning_lqueue => { label => 'warning-lqueue', exit_value => 'warning' },
critical_lqueue => { label => 'critical-lqueue', exit_value => 'critical' },
},
output_msg => 'Backend conn. reuses: %.2f',
factor => 1, unit => '',
},
n_wrk_queued => { thresholds => {
warning_queued => { label => 'warning-queued', exit_value => 'warning' },
critical_queued => { label => 'critical-queued', exit_value => 'critical' },
},
output_msg => 'Backend conn. was closed: %.2f',
factor => 1, unit => '',
},
n_wrk_drop => { thresholds => {
warning_drop => { label => 'warning-drop', exit_value => 'warning' },
critical_drop => { label => 'critical-drop', exit_value => 'critical' },
},
output_msg => 'Backend conn. recycles: %.2f',
factor => 1, unit => '',
},
};
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"remote" => { name => 'remote' },
"ssh-option:s@" => { name => 'ssh_option' },
"ssh-path:s" => { name => 'ssh_path' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 30 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command', default => 'varnishstat' },
"command-path:s" => { name => 'command_path', default => '/usr/bin' },
"command-options:s" => { name => 'command_options', default => ' -1 ' },
"command-options2:s" => { name => 'command_options2', default => ' 2>&1' },
});
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
$options{options}->add_options(arguments => {
$maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s' => { name => $name },
});
};
};
$self->{instances_done} = {};
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
return $self;
};
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'.");
$self->{output}->option_exit();
};
};
};
$self->{statefile_value}->check_options(%options);
};
sub getdata {
my ($self, %options) = @_;
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options} . $self->{option_results}->{command_options2});
#print $stdout;
foreach (split(/\n/, $stdout)) {
#client_conn 7390867 1.00 Client connections
# - Symbolic entry name
# - Value
# - Per-second average over process lifetime, or a period if the value can not be averaged
# - Descriptive text
if (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) {
#print "FOUND: " . $1 . "=" . $2 . "\n";
$self->{result}->{$1} = $2;
};
};
};
sub run {
my ($self, %options) = @_;
$self->getdata();
$self->{statefile_value}->read(statefile => 'cache_apps_varnish' . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')));
$self->{result}->{last_timestamp} = time();
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
# Calculate
my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp;
$delta_time = 1 if ($delta_time == 0); # One seconds ;)
foreach (keys %{$maps_counters}) {
#print $_ . "\n";
$self->{old_cache}->{$_} = $self->{statefile_value}->get(name => '$_'); # Get Data from Cache
$self->{old_cache}->{$_} = 0 if ( $self->{old_cache}->{$_} > $self->{result}->{$_} );
$self->{outputdata}->{$_} = ($self->{result}->{$_} - $self->{old_cache}->{$_}) / $delta_time;
};
# Write Cache if not there
$self->{statefile_value}->write(data => $self->{result});
if (!defined($old_timestamp)) {
$self->{output}->output_add(severity => 'OK',
short_msg => "Buffer creation...");
$self->{output}->display();
$self->{output}->exit();
}
my @exits;
foreach (keys %{$maps_counters}) {
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
push @exits, $self->{perfdata}->threshold_check(value => $self->{outputdata}->{$_}, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]);
}
}
my $exit = $self->{output}->get_most_critical(status => [ @exits ]);
my $extra_label = '';
$extra_label = '_' . $instance_output if ($num > 1);
my $str_output = "";
my $str_append = '';
foreach (keys %{$maps_counters}) {
$str_output .= $str_append . sprintf($maps_counters->{$_}->{output_msg}, $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor});
$str_append = ', ';
my ($warning, $critical);
foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) {
$warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning');
$critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical');
}
$self->{output}->perfdata_add(label => $_ . $extra_label, unit => $maps_counters->{$_}->{unit},
value => sprintf("%.2f", $self->{outputdata}->{$_} * $maps_counters->{$_}->{factor}),
warning => $warning,
critical => $critical);
}
$self->{output}->output_add(severity => $exit,
short_msg => $str_output);
$self->{output}->display();
$self->{output}->exit();
};
1;
__END__
=head1 MODE
Check Varnish Cache with varnishstat Command
=over 8
=item B<--remote>
If you dont run this script locally, if you wanna use it remote, you can run it remotely with 'ssh'.
=item B<--hostname>
Hostname to query (need --remote).
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--command>
Varnishstat Binary Filename (Default: varnishstat)
=item B<--command-path>
Directory Path to Varnishstat Binary File (Default: /usr/bin)
=item B<--command-options>
Parameter for Binary File (Default: ' -1 ')
=item B<--warning-*>
Warning Threshold for:
workers => N worker threads,
create => N worker threads created,
failed => N worker threads not created,
max => N worker threads limited,
lqueue => work request queue length,
queued => N queued work requests,
drop => N dropped work requests
=item B<--critical-*>
Critical Threshold for:
workers => N worker threads,
create => N worker threads created,
failed => N worker threads not created,
max => N worker threads limited,
lqueue => work request queue length,
queued => N queued work requests,
drop => N dropped work requests
=back
=cut

View File

@ -30,27 +30,9 @@ sub new {
bless $self, $class;
$self->{version} = '0.1';
%{$self->{modes}} = (
'connections' => 'apps::varnish::local::mode::connections',
'clients' => 'apps::varnish::local::mode::clients',
'cache' => 'apps::varnish::local::mode::cache',
'backend' => 'apps::varnish::local::mode::backend',
'sessions' => 'apps::varnish::local::mode::sessions',
'fetch' => 'apps::varnish::local::mode::fetch',
'workers' => 'apps::varnish::local::mode::workers',
'totals' => 'apps::varnish::local::mode::totals',
'objects' => 'apps::varnish::local::mode::objects',
'uptime' => 'apps::varnish::local::mode::uptime',
'bans' => 'apps::varnish::local::mode::bans',
'dns' => 'apps::varnish::local::mode::dns',
'shm' => 'apps::varnish::local::mode::shm',
'vcl' => 'apps::varnish::local::mode::vcl',
'n' => 'apps::varnish::local::mode::n',
'sms' => 'apps::varnish::local::mode::sms',
'hcb' => 'apps::varnish::local::mode::hcb',
'esi' => 'apps::varnish::local::mode::esi',
'threads' => 'apps::varnish::local::mode::threads',
);
%{$self->{modes}} = (
'stats' => 'apps::varnish::local::mode::stats',
);
return $self;
}