diff --git a/apps/varnish/local/mode/backend.pm b/apps/varnish/local/mode/backend.pm new file mode 100644 index 000000000..caf19690f --- /dev/null +++ b/apps/varnish/local/mode/backend.pm @@ -0,0 +1,438 @@ +############################################################################### +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an timeelapsedutable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting timeelapsedutable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Author : Florian Asche +# +#################################################################################### + +package apps::varnish::mode::client; + +use base qw(centreon::plugins::mode); +use centreon::plugins::misc; +use centreon::plugins::statefile; +use Digest::MD5 qw(md5_hex); + +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' }, + "warning-conn:s" => { name => 'warning_conn', default => '' }, + "critical-conn:s" => { name => 'critical_conn', default => '' }, + "warning-unhealthy:s" => { name => 'warning_unhealthy', default => '' }, + "critical-unhealthy:s" => { name => 'critical_unhealthy', default => '' }, + "warning-busy:s" => { name => 'warning_busy', default => '' }, + "critical-busy:s" => { name => 'critical_busy', default => '' }, + "warning-fail:s" => { name => 'warning_fail', default => '' }, + "critical-fail:s" => { name => 'critical_fail', default => '' }, + "warning-reuse:s" => { name => 'warning_reuse', default => '' }, + "critical-reuse:s" => { name => 'critical_reuse', default => '' }, + "warning-toolate:s" => { name => 'warning_toolate', default => '' }, + "critical-toolate:s" => { name => 'critical_toolate', default => '' }, + "warning-recycle:s" => { name => 'warning_recycle', default => '' }, + "critical-recycle:s" => { name => 'critical_recycle', default => '' }, + "warning-retry:s" => { name => 'warning_retry', default => '' }, + "critical-retry:s" => { name => 'critical_retry', default => '' }, + }); + + $self->{statefile_value} = centreon::plugins::statefile->new(%options); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (($self->{perfdata}->threshold_validate(label => 'warning-conn', value => $self->{option_results}->{warning_conn})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning-conn threshold '" . $self->{option_results}->{warning_conn} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical-conn', value => $self->{option_results}->{critical_conn})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical-conn threshold '" . $self->{option_results}->{critical_conn} . "'."); + $self->{output}->option_exit(); + } + + if (($self->{perfdata}->threshold_validate(label => 'warning-unhealthy', value => $self->{option_results}->{warning_unhealthy})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning-unhealthy threshold '" . $self->{option_results}->{warning_unhealthy} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical-unhealthy', value => $self->{option_results}->{critical_unhealthy})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical-unhealthy threshold '" . $self->{option_results}->{critical_unhealthy} . "'."); + $self->{output}->option_exit(); + } + + if (($self->{perfdata}->threshold_validate(label => 'warning-busy', value => $self->{option_results}->{warning_busy})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning-busy threshold '" . $self->{option_results}->{warning_busy} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical-busy', value => $self->{option_results}->{critical_busy})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical-busy threshold '" . $self->{option_results}->{critical_busy} . "'."); + $self->{output}->option_exit(); + } + + if (($self->{perfdata}->threshold_validate(label => 'warning-fail', value => $self->{option_results}->{warning_fail})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning-fail threshold '" . $self->{option_results}->{warning_fail} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical-fail', value => $self->{option_results}->{critical_fail})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical-fail threshold '" . $self->{option_results}->{critical_fail} . "'."); + $self->{output}->option_exit(); + } + + if (($self->{perfdata}->threshold_validate(label => 'warning-reuse', value => $self->{option_results}->{warning_reuse})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning-reuse threshold '" . $self->{option_results}->{warning_reuse} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical-reuse', value => $self->{option_results}->{critical_reuse})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical-reuse threshold '" . $self->{option_results}->{critical_reuse} . "'."); + $self->{output}->option_exit(); + } + + if (($self->{perfdata}->threshold_validate(label => 'warning-toolate', value => $self->{option_results}->{warning_toolate})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning-toolate threshold '" . $self->{option_results}->{warning_toolate} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical-toolate', value => $self->{option_results}->{critical_toolate})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical-toolate threshold '" . $self->{option_results}->{critical_toolate} . "'."); + $self->{output}->option_exit(); + } + + if (($self->{perfdata}->threshold_validate(label => 'warning-recycle', value => $self->{option_results}->{warning_recycle})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning-recycle threshold '" . $self->{option_results}->{warning_recycle} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical-recycle', value => $self->{option_results}->{critical_recycle})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical-recycle threshold '" . $self->{option_results}->{critical_recycle} . "'."); + $self->{output}->option_exit(); + } + + if (($self->{perfdata}->threshold_validate(label => 'warning-retry', value => $self->{option_results}->{warning_retry})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning-retry threshold '" . $self->{option_results}->{warning_retry} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical-retry', value => $self->{option_results}->{critical_retry})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical-retry threshold '" . $self->{option_results}->{critical_retry} . "'."); + $self->{output}->option_exit(); + } + + $self->{statefile_value}->check_options(%options); +} + +#my $stdout = ' +#backend_conn 13746 0.00 Backend conn. success +#backend_unhealthy 0 0.00 Backend conn. not attempted +#backend_busy 0 0.00 Backend conn. too many +#backend_fail 0 0.00 Backend conn. failures +#backend_reuse 0 0.00 Backend conn. reuses +#backend_toolate 0 0.00 Backend conn. was closed +#backend_recycle 0 0.00 Backend conn. recycles +#backend_retry 0 0.00 Backend conn. retry +#'; + +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'); + my $old_backend_conn = $self->{statefile_value}->get(name => 'backend_conn'); + my $old_backend_unhealthy = $self->{statefile_value}->get(name => 'backend_unhealthy'); + my $old_backend_busy = $self->{statefile_value}->get(name => 'backend_busy'); + my $old_backend_fail = $self->{statefile_value}->get(name => 'backend_fail'); + my $old_backend_reuse = $self->{statefile_value}->get(name => 'backend_reuse'); + my $old_backend_toolate = $self->{statefile_value}->get(name => 'backend_toolate'); + my $old_backend_recycle = $self->{statefile_value}->get(name => 'backend_recycle'); + my $old_backend_retry = $self->{statefile_value}->get(name => 'backend_retry'); + + $self->{statefile_value}->write(data => $self->{result}); + if (!defined($old_timestamp) || !defined($old_backend_conn)) { + $self->{output}->output_add(severity => 'OK', + short_msg => "Buffer creation..."); + $self->{output}->display(); + $self->{output}->exit(); + } + + # Set 0 if Cache > Result + $old_backend_conn = 0 if ($old_backend_conn > $self->{result}->{backend_conn} ); + $old_backend_unhealthy = 0 if ($old_hitpass > $self->{result}->{backend_unhealthy}); + $old_backend_busy = 0 if ($old_miss > $self->{result}->{backend_busy}); + $old_backend_fail = 0 if ($old_miss > $self->{result}->{backend_fail}); + $old_backend_reuse = 0 if ($old_miss > $self->{result}->{backend_reuse}); + $old_backend_toolate = 0 if ($old_miss > $self->{result}->{backend_toolate}); + $old_backend_recycle = 0 if ($old_miss > $self->{result}->{backend_recycle}); + $old_backend_retry = 0 if ($old_miss > $self->{result}->{backend_retry}); + + # Calculate + my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp; + $delta_time = 1 if ($delta_time == 0); # One seconds ;) + my $backend_conn = ($self->{result}->{backend_conn} - $old_backend_conn) / $delta_time; + my $backend_unhealthy = ($self->{result}->{backend_unhealthy} - $old_backend_unhealthy) / $delta_time; + my $backend_busy = ($self->{result}->{backend_busy} - $old_backend_busy) / $delta_time; + my $backend_fail = ($self->{result}->{backend_fail} - $old_backend_fail) / $delta_time; + my $backend_reuse = ($self->{result}->{backend_reuse} - $old_backend_reuse) / $delta_time; + my $backend_toolate = ($self->{result}->{backend_toolate} - $old_backend_toolate) / $delta_time; + my $backend_recycle = ($self->{result}->{backend_recycle} - $old_backend_recycle) / $delta_time; + my $backend_retry = ($self->{result}->{backend_retry} - $old_backend_retry) / $delta_time; + + my $exit1 = $self->{perfdata}->threshold_check(value => $backend_conn, threshold => [ { label => 'critical-conn', 'exit_litteral' => 'critical' }, { label => 'warning-conn', exit_litteral => 'warning' } ]); + my $exit2 = $self->{perfdata}->threshold_check(value => $backend_unhealthy, threshold => [ { label => 'critical-unhealthy', 'exit_litteral' => 'critical' }, { label => 'warning-unhealthy', exit_litteral => 'warning' } ]); + my $exit3 = $self->{perfdata}->threshold_check(value => $backend_busy, threshold => [ { label => 'critical-busy', 'exit_litteral' => 'critical' }, { label => 'warning-busy', exit_litteral => 'warning' } ]); + my $exit4 = $self->{perfdata}->threshold_check(value => $backend_fail, threshold => [ { label => 'critical-fail', 'exit_litteral' => 'critical' }, { label => 'warning-fail', exit_litteral => 'warning' } ]); + my $exit5 = $self->{perfdata}->threshold_check(value => $backend_reuse, threshold => [ { label => 'critical-reuse', 'exit_litteral' => 'critical' }, { label => 'warning-reuse', exit_litteral => 'warning' } ]); + my $exit6 = $self->{perfdata}->threshold_check(value => $backend_toolate, threshold => [ { label => 'critical-toolate', 'exit_litteral' => 'critical' }, { label => 'warning-toolate', exit_litteral => 'warning' } ]); + my $exit7 = $self->{perfdata}->threshold_check(value => $backend_recycle, threshold => [ { label => 'critical-recycle', 'exit_litteral' => 'critical' }, { label => 'warning-recycle', exit_litteral => 'warning' } ]); + my $exit8 = $self->{perfdata}->threshold_check(value => $backend_retry, threshold => [ { label => 'critical-retry', 'exit_litteral' => 'critical' }, { label => 'warning-retry', exit_litteral => 'warning' } ]); + + my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3, $exit4, $exit5, $exit6, $exit7, $exit8 ]); + + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Backend conn. success: %.2f + Backend conn. not attempted: %.2f + Backend conn. too many: %.2f + Backend conn. failures: %.2f + Backend conn. reuses: %.2f + Backend conn. was closed: %.2f + Backend conn. recycles: %.2f + Backend conn. retry: %.2f ", + $backend_conn, + $backend_unhealthy, + $backend_busy, + $backend_fail, + $backend_reuse, + $backend_toolate, + $backend_recycle, + $backend_retry, + )); + + $self->{output}->perfdata_add(label => "backend_conn", + value => $backend_conn, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-conn'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-conn'), + min => 0 + ); + $self->{output}->perfdata_add(label => "backend_unhealthy", + value => $backend_unhealthy, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-unhealthy'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-unhealthy'), + min => 0 + ); + $self->{output}->perfdata_add(label => "backend_busy", + value => $backend_busy, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-busy'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-busy'), + min => 0 + ); + $self->{output}->perfdata_add(label => "backend_fail", + value => $backend_fail, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-fail'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-fail'), + min => 0 + ); + $self->{output}->perfdata_add(label => "backend_reuse", + value => $backend_reuse, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-reuse'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-reuse'), + min => 0 + ); + $self->{output}->perfdata_add(label => "backend_toolate", + value => $backend_toolate, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-toolate'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-toolate'), + min => 0 + ); + $self->{output}->perfdata_add(label => "backend_recycle", + value => $backend_recycle, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-recycle'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-recycle'), + min => 0 + ); + $self->{output}->perfdata_add(label => "backend_retry", + value => $backend_retry, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-retry'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-retry'), + min => 0 + ); + $self->{output}->display(); + $self->{output}->exit(); +}; + + +1; + +__END__ + +=head1 MODE + +Check Varnish Cache with varnishstat Command +This Mode Checks: +- Backend conn. success +- Backend conn. not attempted +- Backend conn. too many +- Backend conn. failures +- Backend conn. reuses +- Backend conn. was closed +- Backend conn. recycles +- Backend conn. unused + +=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-conn> + +Warning Threshold for Backend conn. success + +=item B<--critical-conn> + +Critical Threshold for Backend conn. success + +=item B<--warning-unhealthy> + +Warning Threshold for Backend conn. not attempted + +=item B<--critical-unhealthy> + +Critical Threshold for Backend conn. not attempted + +=item B<--warning-busy> + +Warning Threshold for Backend conn. too many + +=item B<--critical-busy> + +Critical Threshold for Backend conn. too many + +=item B<--warning-fail> + +Warning Threshold for Backend conn. failures + +=item B<--critical-fail> + +Critical Threshold for Backend conn. failures + +=item B<--warning-reuse> + +Warning Threshold for Backend conn. reuses + +=item B<--critical-reuse> + +Critical Threshold for Backend conn. reuses + +=item B<--warning-toolate> + +Warning Threshold for Backend conn. was closed + +=item B<--critical-toolate> + +Critical Threshold for Backend conn. was closed + +=item B<--warning-recycle> + +Warning Threshold for Backend conn. recycles + +=item B<--critical-recycle> + +Critical Threshold for Backend conn. recycles + +=item B<--warning-retry> + +Warning Threshold for Backend conn. retry + +=item B<--critical-retry> + +Critical Threshold for Backend conn. retry + +=back + +=cut \ No newline at end of file diff --git a/apps/varnish/local/mode/cache.pm b/apps/varnish/local/mode/cache.pm index 84b2f6c56..2ec583a55 100644 --- a/apps/varnish/local/mode/cache.pm +++ b/apps/varnish/local/mode/cache.pm @@ -76,29 +76,29 @@ sub check_options { $self->SUPER::init(%options); if (($self->{perfdata}->threshold_validate(label => 'warning-hit', value => $self->{option_results}->{warning_hit})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning_hit} . "'."); + $self->{output}->add_option_msg(short_msg => "Wrong warning-hit threshold '" . $self->{option_results}->{warning_hit} . "'."); $self->{output}->option_exit(); } if (($self->{perfdata}->threshold_validate(label => 'critical-hit', value => $self->{option_results}->{critical_hit})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical_hit} . "'."); + $self->{output}->add_option_msg(short_msg => "Wrong critical-hit threshold '" . $self->{option_results}->{critical_hit} . "'."); $self->{output}->option_exit(); } if (($self->{perfdata}->threshold_validate(label => 'warning-hitpass', value => $self->{option_results}->{warning_hitpass})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning-bytes threshold '" . $self->{option_results}->{warning_hitpass} . "'."); + $self->{output}->add_option_msg(short_msg => "Wrong warning-hitpass threshold '" . $self->{option_results}->{warning_hitpass} . "'."); $self->{output}->option_exit(); } if (($self->{perfdata}->threshold_validate(label => 'critical-hitpass', value => $self->{option_results}->{critical_hitpass})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical-bytes threshold '" . $self->{option_results}->{critical_hitpass} . "'."); + $self->{output}->add_option_msg(short_msg => "Wrong critical-hitpass threshold '" . $self->{option_results}->{critical_hitpass} . "'."); $self->{output}->option_exit(); } if (($self->{perfdata}->threshold_validate(label => 'warning-miss', value => $self->{option_results}->{warning_miss})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning-access threshold '" . $self->{option_results}->{warning_miss} . "'."); + $self->{output}->add_option_msg(short_msg => "Wrong warning-miss threshold '" . $self->{option_results}->{warning_miss} . "'."); $self->{output}->option_exit(); } if (($self->{perfdata}->threshold_validate(label => 'critical-miss', value => $self->{option_results}->{critical_miss})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical-access threshold '" . $self->{option_results}->{critical_miss} . "'."); + $self->{output}->add_option_msg(short_msg => "Wrong critical-miss threshold '" . $self->{option_results}->{critical_miss} . "'."); $self->{output}->option_exit(); } @@ -106,14 +106,9 @@ sub check_options { } #my $stdout = ' -#client_conn 7287199 1.00 Client connections accepted -#client_drop 0 0.00 Connection dropped, no sess/wrk -#client_req 24187 0.00 Client requests received #cache_hit 69941 0.00 Cache hits #cache_hitpass 10 0.00 Cache hits for pass #cache_miss 16746 0.00 Cache misses -#backend_conn 13746 0.00 Backend conn. success -#backend_unhealthy 0 0.00 Backend conn. not attempted #'; sub getdata { @@ -217,6 +212,10 @@ __END__ =head1 MODE Check Varnish Cache with varnishstat Command +This Mode Checks: +- Cache hits +- Cache hits for pass +- Cache misses =over 8 @@ -248,10 +247,6 @@ Parameter for Binary File (Default: ' -1 ') Warning Threshold for Cache Hits -=item B<--warning-hit> - -Warning Threshold for Cache Hits - =item B<--critical-hit> Critical Threshold for Cache Hits diff --git a/apps/varnish/mode/cache.pm b/apps/varnish/local/mode/connections.pm similarity index 62% rename from apps/varnish/mode/cache.pm rename to apps/varnish/local/mode/connections.pm index 099df5b0d..2ab121020 100644 --- a/apps/varnish/mode/cache.pm +++ b/apps/varnish/local/mode/connections.pm @@ -33,7 +33,7 @@ # #################################################################################### -package apps::varnish::mode::cache; +package apps::varnish::mode::connections; use base qw(centreon::plugins::mode); use centreon::plugins::misc; @@ -59,12 +59,12 @@ sub new { "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' }, - "warning-hit:s" => { name => 'warning-hit', default => '' }, - "critical-hit:s" => { name => 'critical-hit', default => '' }, - "warning-hitpass:s" => { name => 'warning-hitpass', default => '' }, - "critical-hitpass:s" => { name => 'critical-hitpass', default => '' }, - "warning-miss:s" => { name => 'warning-miss', default => '' }, - "critical-miss:s" => { name => 'critical-miss', default => '' }, + "warning-hit:s" => { name => 'warning_hit', default => '' }, + "critical-hit:s" => { name => 'critical_hit', default => '' }, + "warning-hitpass:s" => { name => 'warning_hitpass', default => '' }, + "critical-hitpass:s" => { name => 'critical_hitpass', default => '' }, + "warning-miss:s" => { name => 'warning_miss', default => '' }, + "critical-miss:s" => { name => 'critical_miss', default => '' }, }); $self->{statefile_value} = centreon::plugins::statefile->new(%options); @@ -75,30 +75,30 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - if (($self->{perfdata}->threshold_validate(label => 'warning-hit', value => $self->{option_results}->{warning-hit})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning-hit} . "'."); + if (($self->{perfdata}->threshold_validate(label => 'warning-conn', value => $self->{option_results}->{warning_conn})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning-conn threshold '" . $self->{option_results}->{warning_conn} . "'."); $self->{output}->option_exit(); } - if (($self->{perfdata}->threshold_validate(label => 'critical-hit', value => $self->{option_results}->{critical-hit})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical-hit} . "'."); + if (($self->{perfdata}->threshold_validate(label => 'critical-conn', value => $self->{option_results}->{critical_conn})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical-conn threshold '" . $self->{option_results}->{critical_conn} . "'."); $self->{output}->option_exit(); } - if (($self->{perfdata}->threshold_validate(label => 'warning-hitpass', value => $self->{option_results}->{warning_hitpass})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning-bytes threshold '" . $self->{option_results}->{warning_hitpass} . "'."); + if (($self->{perfdata}->threshold_validate(label => 'warning-drop', value => $self->{option_results}->{warning_drop})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning-drop threshold '" . $self->{option_results}->{warning_drop} . "'."); $self->{output}->option_exit(); } - if (($self->{perfdata}->threshold_validate(label => 'critical-hitpass', value => $self->{option_results}->{critical_hitpass})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical-bytes threshold '" . $self->{option_results}->{critical_hitpass} . "'."); + if (($self->{perfdata}->threshold_validate(label => 'critical-drop', value => $self->{option_results}->{critical_drop})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical-drop threshold '" . $self->{option_results}->{critical_drop} . "'."); $self->{output}->option_exit(); } - if (($self->{perfdata}->threshold_validate(label => 'warning-miss', value => $self->{option_results}->{warning_miss})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning-access threshold '" . $self->{option_results}->{warning_miss} . "'."); + if (($self->{perfdata}->threshold_validate(label => 'warning-req', value => $self->{option_results}->{warning_req})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning-req threshold '" . $self->{option_results}->{warning_req} . "'."); $self->{output}->option_exit(); } - if (($self->{perfdata}->threshold_validate(label => 'critical-miss', value => $self->{option_results}->{critical_miss})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical-access threshold '" . $self->{option_results}->{critical_miss} . "'."); + if (($self->{perfdata}->threshold_validate(label => 'critical-req', value => $self->{option_results}->{critical_req})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical-req threshold '" . $self->{option_results}->{critical_req} . "'."); $self->{output}->option_exit(); } @@ -109,11 +109,6 @@ sub check_options { #client_conn 7287199 1.00 Client connections accepted #client_drop 0 0.00 Connection dropped, no sess/wrk #client_req 24187 0.00 Client requests received -#cache_hit 17941 0.00 Cache hits -#cache_hitpass 10 0.00 Cache hits for pass -#cache_miss 16746 0.00 Cache misses -#backend_conn 13746 0.00 Backend conn. success -#backend_unhealthy 0 0.00 Backend conn. not attempted #'; sub getdata { @@ -135,7 +130,7 @@ sub getdata { # - Descriptive text if (/^(.\S*)\s*([0-9]*)\s*([0-9.]*)\s(.*)$/i) { - #print "FOUND: " . $2 . "\n"; + #print "FOUND: " . $1 . "=" . $2 . "\n"; $self->{result}->{$1} = $2; }; }; @@ -149,12 +144,12 @@ sub run { $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'); - my $old_cache_hit = $self->{statefile_value}->get(name => 'cache_hit'); - my $old_hitpass = $self->{statefile_value}->get(name => 'cache_hitpass'); - my $old_miss = $self->{statefile_value}->get(name => 'cache_miss'); + my $old_client_conn = $self->{statefile_value}->get(name => 'client_conn'); + my $old_client_drop = $self->{statefile_value}->get(name => 'client_drop'); + my $old_client_req = $self->{statefile_value}->get(name => 'client_req'); $self->{statefile_value}->write(data => $self->{result}); - if (!defined($old_timestamp) || !defined($old_cache_hit)) { + if (!defined($old_timestamp) || !defined($old_client_conn)) { $self->{output}->output_add(severity => 'OK', short_msg => "Buffer creation..."); $self->{output}->display(); @@ -162,46 +157,50 @@ sub run { } # Set 0 if Cache > Result - $old_cache_hit = 0 if ($old_cache_hit > $self->{result}->{cache_hit}->{value} ); - $old_cache_hitpass = 0 if ($old_hitpass > $self->{result}->{cache_hitpass}->{value}); - $old_cache_miss = 0 if ($old_miss > $self->{result}->{cache_miss}->{value}); + $old_client_conn = 0 if ($old_client_conn > $self->{result}->{client_conn} ); + $old_client_drop = 0 if ($old_hitpass > $self->{result}->{client_drop}); + $old_client_req = 0 if ($old_miss > $self->{result}->{client_req}); # Calculate my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp; $delta_time = 1 if ($delta_time == 0); # One seconds ;) - my $cache_hit = ($self->{result}->{cache_hit}->{value} - $old_cache_hit) / $delta_time; - my $cache_hitpass = ($self->{result}->{cache_hitpass}->{value} - $old_cache_hitpass) / $delta_time; - my $cache_miss = ($self->{result}->{cache_}->{value} - $old_cache_miss) / $delta_time; + my $client_conn = ($self->{result}->{client_conn} - $old_client_conn) / $delta_time; + my $client_drop = ($self->{result}->{client_drop} - $old_client_drop) / $delta_time; + my $client_req = ($self->{result}->{client_req} - $old_client_req) / $delta_time; - my $exit1 = $self->{perfdata}->threshold_check(value => $cache_hit, threshold => [ { label => 'critical-hit', 'exit_litteral' => 'critical' }, { label => 'warning-hit', exit_litteral => 'warning' } ]); - my $exit2 = $self->{perfdata}->threshold_check(value => $cache_hitpass, threshold => [ { label => 'critical-hitpass', 'exit_litteral' => 'critical' }, { label => 'warning-hitpass', exit_litteral => 'warning' } ]); - my $exit3 = $self->{perfdata}->threshold_check(value => $cache_miss, threshold => [ { label => 'critical-miss', 'exit_litteral' => 'critical' }, { label => 'warning-miss', exit_litteral => 'warning' } ]); + #print $old_client_conn . "\n"; + #print $self->{result}->{client_conn} . "\n"; + #print $client_conn . "\n"; + + my $exit1 = $self->{perfdata}->threshold_check(value => $client_conn, threshold => [ { label => 'critical-conn', 'exit_litteral' => 'critical' }, { label => 'warning-conn', exit_litteral => 'warning' } ]); + my $exit2 = $self->{perfdata}->threshold_check(value => $client_drop, threshold => [ { label => 'critical-drop', 'exit_litteral' => 'critical' }, { label => 'warning-drop', exit_litteral => 'warning' } ]); + my $exit3 = $self->{perfdata}->threshold_check(value => $client_req, threshold => [ { label => 'critical-req', 'exit_litteral' => 'critical' }, { label => 'warning-req', exit_litteral => 'warning' } ]); my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3 ]); $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Cache Hits: %.2f Cache Hits for pass: %.2f Cache misses: %.2f ", - $cache_hit, - $cache_hitpass, - $cache_miss, + short_msg => sprintf("Client connections accepted: %.2f Connection dropped, no sess/wrk: %.2f Client requests received: %.2f ", + $client_conn, + $client_drop, + $client_req, )); - $self->{output}->perfdata_add(label => "cache_hit", - value => $cache_hit, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-hit'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-hit'), + $self->{output}->perfdata_add(label => "client_conn", + value => $client_conn, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-conn'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-conn'), min => 0 ); - $self->{output}->perfdata_add(label => "cache_hitpass", - value => $cache_hitpass, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-hitpass'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-hitpass'), + $self->{output}->perfdata_add(label => "client_drop", + value => $client_drop, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-drop'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-drop'), min => 0 ); - $self->{output}->perfdata_add(label => "cache_miss", - value => $cache_miss, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-miss'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-miss'), + $self->{output}->perfdata_add(label => "client_req", + value => $client_req, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-req'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-req'), min => 0 ); @@ -217,9 +216,25 @@ __END__ =head1 MODE Check Varnish Cache with varnishstat Command +This Mode Checks: +- Client connections accepted +- Connection dropped, no sess +- Client requests received =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) @@ -232,33 +247,29 @@ Directory Path to Varnishstat Binary File (Default: /usr/bin/) Parameter for Binary File (Default: ' -1 ') -=item B<--warning-hit> +=item B<--warning-conn> -Warning Threshold for Cache Hits +Warning Threshold for Client connections accepted -=item B<--warning-hit> +=item B<--critical-conn> -Warning Threshold for Cache Hits +Critical Threshold for Client connections accepted -=item B<--critical-hit> +=item B<--warning-drop> -Critical Threshold for Cache Hits +Warning Threshold for Connection dropped, no sess/wrk -=item B<--warning-hitpass> +=item B<--critical-drop> -Warning Threshold for Cache hits for Pass +Critical Threshold for Connection dropped, no sess/wrk -=item B<--critical-hitpass> +=item B<--warning-req> -Critical Threshold for Cache hits for Pass +Warning Threshold for Client requests received -=item B<--warning-miss> +=item B<--critical-req> -Warning Threshold for Cache Misses - -=item B<--critical-miss> - -Critical Threshold for Cache Misses +Critical Threshold for Client requests received =back diff --git a/apps/varnish/local/mode/fetch.pm b/apps/varnish/local/mode/fetch.pm new file mode 100644 index 000000000..5b7864dff --- /dev/null +++ b/apps/varnish/local/mode/fetch.pm @@ -0,0 +1,573 @@ +############################################################################### +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an timeelapsedutable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting timeelapsedutable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Author : Florian Asche +# +#################################################################################### + +package apps::varnish::mode::client; + +use base qw(centreon::plugins::mode); +use centreon::plugins::misc; +use centreon::plugins::statefile; +use Digest::MD5 qw(md5_hex); + +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' }, + "warning-head:s" => { name => 'warning_head', default => '' }, + "critical-head:s" => { name => 'critical_head', default => '' }, + "warning-length:s" => { name => 'warning_length', default => '' }, + "critical-length:s" => { name => 'critical_length', default => '' }, + "warning-chunked:s" => { name => 'warning_chunked', default => '' }, + "critical-chunked:s" => { name => 'critical_chunked', default => '' }, + "warning-eof:s" => { name => 'warning_eof', default => '' }, + "critical-eof:s" => { name => 'critical_eof', default => '' }, + "warning-bad:s" => { name => 'warning_bad', default => '' }, + "critical-bad:s" => { name => 'critical_bad', default => '' }, + "warning-close:s" => { name => 'warning_close', default => '' }, + "critical-close:s" => { name => 'critical_close', default => '' }, + "warning-oldhttp:s" => { name => 'warning_oldhttp', default => '' }, + "critical-oldhttp:s" => { name => 'critical_oldhttp', default => '' }, + "warning-zero:s" => { name => 'warning_zero', default => '' }, + "critical-zero:s" => { name => 'critical_zero', default => '' }, + "warning-failed:s" => { name => 'warning_failed', default => '' }, + "critical-failed:s" => { name => 'critical_failed', default => '' }, + "warning-1xx:s" => { name => 'warning_1xx', default => '' }, + "critical-1xx:s" => { name => 'critical_1xx', default => '' }, + "warning-204:s" => { name => 'warning_204', default => '' }, + "critical-204:s" => { name => 'critical_204', default => '' }, + "warning-304:s" => { name => 'warning_304', default => '' }, + "critical-304:s" => { name => 'critical_304', default => '' }, + }); + + $self->{statefile_value} = centreon::plugins::statefile->new(%options); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (($self->{perfdata}->threshold_validate(label => 'warning-head', value => $self->{option_results}->{warning_head})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning-head threshold '" . $self->{option_results}->{warning_head} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical-head', value => $self->{option_results}->{critical_head})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical-head threshold '" . $self->{option_results}->{critical_head} . "'."); + $self->{output}->option_exit(); + } + + if (($self->{perfdata}->threshold_validate(label => 'warning-length', value => $self->{option_results}->{warning_length})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning-length threshold '" . $self->{option_results}->{warning_length} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical-length', value => $self->{option_results}->{critical_length})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical-length threshold '" . $self->{option_results}->{critical_length} . "'."); + $self->{output}->option_exit(); + } + + if (($self->{perfdata}->threshold_validate(label => 'warning-chunked', value => $self->{option_results}->{warning_chunked})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning-chunked threshold '" . $self->{option_results}->{warning_chunked} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical-chunked', value => $self->{option_results}->{critical_chunked})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical-chunked threshold '" . $self->{option_results}->{critical_chunked} . "'."); + $self->{output}->option_exit(); + } + + if (($self->{perfdata}->threshold_validate(label => 'warning-eof', value => $self->{option_results}->{warning_eof})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning-eof threshold '" . $self->{option_results}->{warning_eof} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical-eof', value => $self->{option_results}->{critical_eof})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical-eof threshold '" . $self->{option_results}->{critical_eof} . "'."); + $self->{output}->option_exit(); + } + + if (($self->{perfdata}->threshold_validate(label => 'warning-bad', value => $self->{option_results}->{warning_bad})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning-bad threshold '" . $self->{option_results}->{warning_bad} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical-bad', value => $self->{option_results}->{critical_bad})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical-bad threshold '" . $self->{option_results}->{critical_bad} . "'."); + $self->{output}->option_exit(); + } + + if (($self->{perfdata}->threshold_validate(label => 'warning-close', value => $self->{option_results}->{warning_close})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning-close threshold '" . $self->{option_results}->{warning_close} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical-close', value => $self->{option_results}->{critical_close})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical-close threshold '" . $self->{option_results}->{critical_close} . "'."); + $self->{output}->option_exit(); + } + + if (($self->{perfdata}->threshold_validate(label => 'warning-oldhttp', value => $self->{option_results}->{warning_oldhttp})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning-oldhttp threshold '" . $self->{option_results}->{warning_oldhttp} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical-oldhttp', value => $self->{option_results}->{critical_oldhttp})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical-oldhttp threshold '" . $self->{option_results}->{critical_oldhttp} . "'."); + $self->{output}->option_exit(); + } + + if (($self->{perfdata}->threshold_validate(label => 'warning-zero', value => $self->{option_results}->{warning_zero})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning-zero threshold '" . $self->{option_results}->{warning_zero} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical-zero', value => $self->{option_results}->{critical_zero})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical-zero threshold '" . $self->{option_results}->{critical_zero} . "'."); + $self->{output}->option_exit(); + } + + if (($self->{perfdata}->threshold_validate(label => 'warning-failed', value => $self->{option_results}->{warning_failed})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning-failed threshold '" . $self->{option_results}->{warning_failed} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical-failed', value => $self->{option_results}->{critical_failed})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical-failed threshold '" . $self->{option_results}->{critical_failed} . "'."); + $self->{output}->option_exit(); + } + + if (($self->{perfdata}->threshold_validate(label => 'warning-1xx', value => $self->{option_results}->{warning_1xx})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning-1xx threshold '" . $self->{option_results}->{warning_1xx} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical-1xx', value => $self->{option_results}->{critical_1xx})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical-1xx threshold '" . $self->{option_results}->{critical_1xx} . "'."); + $self->{output}->option_exit(); + } + + if (($self->{perfdata}->threshold_validate(label => 'warning-204', value => $self->{option_results}->{warning_204})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning-204 threshold '" . $self->{option_results}->{warning_204} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical-204', value => $self->{option_results}->{critical_204})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical-204 threshold '" . $self->{option_results}->{critical_204} . "'."); + $self->{output}->option_exit(); + } + + if (($self->{perfdata}->threshold_validate(label => 'warning-304', value => $self->{option_results}->{warning_304})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning-304 threshold '" . $self->{option_results}->{warning_304} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical-304', value => $self->{option_results}->{critical_304})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical-304 threshold '" . $self->{option_results}->{critical_304} . "'."); + $self->{output}->option_exit(); + } + + $self->{statefile_value}->check_options(%options); +} + +#my $stdout = ' +#fetch_head 0 0.00 Fetch head +#fetch_length 13742 0.00 Fetch with Length +#fetch_chunked 0 0.00 Fetch chunked +#fetch_eof 0 0.00 Fetch EOF +#fetch_bad 0 0.00 Fetch had bad headers +#fetch_close 0 0.00 Fetch wanted close +#fetch_oldhttp 0 0.00 Fetch pre HTTP/1.1 closed +#fetch_zero 0 0.00 Fetch zero len +#fetch_failed 0 0.00 Fetch failed +#fetch_1xx 0 0.00 Fetch no body (1xx) +#fetch_204 0 0.00 Fetch no body (204) +#fetch_304 0 0.00 Fetch no body (304) +#'; + +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'); + my $old_fetch_head = $self->{statefile_value}->get(name => 'fetch_head'); + my $old_fetch_length = $self->{statefile_value}->get(name => 'fetch_length'); + my $old_fetch_chunked = $self->{statefile_value}->get(name => 'fetch_chunked'); + my $old_fetch_eof = $self->{statefile_value}->get(name => 'fetch_eof'); + my $old_fetch_bad = $self->{statefile_value}->get(name => 'fetch_bad'); + my $old_fetch_close = $self->{statefile_value}->get(name => 'fetch_close'); + my $old_fetch_oldhttp = $self->{statefile_value}->get(name => 'fetch_oldhttp'); + my $old_fetch_zero = $self->{statefile_value}->get(name => 'fetch_zero'); + my $old_fetch_failed = $self->{statefile_value}->get(name => 'fetch_failed'); + my $old_fetch_1xx = $self->{statefile_value}->get(name => 'fetch_1xx'); + my $old_fetch_204 = $self->{statefile_value}->get(name => 'fetch_204'); + my $old_fetch_304 = $self->{statefile_value}->get(name => 'fetch_304'); + + + $self->{statefile_value}->write(data => $self->{result}); + if (!defined($old_timestamp) || !defined($old_fetch_head)) { + $self->{output}->output_add(severity => 'OK', + short_msg => "Buffer creation..."); + $self->{output}->display(); + $self->{output}->exit(); + } + + # Set 0 if Cache > Result + $old_fetch_head = 0 if ($old_fetch_head > $self->{result}->{fetch_head} ); + $old_fetch_length = 0 if ($old_hitpass > $self->{result}->{fetch_length}); + $old_fetch_chunked = 0 if ($old_miss > $self->{result}->{fetch_chunked}); + $old_fetch_eof = 0 if ($old_miss > $self->{result}->{fetch_eof}); + $old_fetch_bad = 0 if ($old_miss > $self->{result}->{fetch_bad}); + $old_fetch_close = 0 if ($old_miss > $self->{result}->{fetch_close}); + $old_fetch_oldhttp = 0 if ($old_miss > $self->{result}->{fetch_oldhttp}); + $old_fetch_zero = 0 if ($old_miss > $self->{result}->{fetch_zero}); + $old_fetch_failed = 0 if ($old_miss > $self->{result}->{fetch_failed}); + $old_fetch_1xx = 0 if ($old_miss > $self->{result}->{fetch_1xx}); + $old_fetch_204 = 0 if ($old_miss > $self->{result}->{fetch_204}); + $old_fetch_304 = 0 if ($old_miss > $self->{result}->{fetch_304}); + + # Calculate + my $delta_time = $self->{result}->{last_timestamp} - $old_timestamp; + $delta_time = 1 if ($delta_time == 0); # One seconds ;) + my $fetch_head = ($self->{result}->{fetch_head} - $old_fetch_head) / $delta_time; + my $fetch_length = ($self->{result}->{fetch_length} - $old_fetch_length) / $delta_time; + my $fetch_chunked = ($self->{result}->{fetch_chunked} - $old_fetch_chunked) / $delta_time; + my $fetch_eof = ($self->{result}->{fetch_eof} - $old_fetch_eof) / $delta_time; + my $fetch_bad = ($self->{result}->{fetch_bad} - $old_fetch_bad) / $delta_time; + my $fetch_close = ($self->{result}->{fetch_close} - $old_fetch_close) / $delta_time; + my $fetch_oldhttp = ($self->{result}->{fetch_oldhttp} - $old_fetch_oldhttp) / $delta_time; + my $fetch_zero = ($self->{result}->{fetch_zero} - $old_fetch_zero) / $delta_time; + my $fetch_failed = ($self->{result}->{fetch_failed} - $old_fetch_failed) / $delta_time; + my $fetch_1xx = ($self->{result}->{fetch_1xx} - $old_fetch_1xx) / $delta_time; + my $fetch_204 = ($self->{result}->{fetch_204} - $old_fetch_204) / $delta_time; + my $fetch_304 = ($self->{result}->{fetch_304} - $old_fetch_304) / $delta_time; + + my $exit1 = $self->{perfdata}->threshold_check(value => $fetch_head, threshold => [ { label => 'critical-head', 'exit_litteral' => 'critical' }, { label => 'warning-head', exit_litteral => 'warning' } ]); + my $exit2 = $self->{perfdata}->threshold_check(value => $fetch_length, threshold => [ { label => 'critical-length', 'exit_litteral' => 'critical' }, { label => 'warning-length', exit_litteral => 'warning' } ]); + my $exit3 = $self->{perfdata}->threshold_check(value => $fetch_chunked, threshold => [ { label => 'critical-chunked', 'exit_litteral' => 'critical' }, { label => 'warning-chunked', exit_litteral => 'warning' } ]); + my $exit4 = $self->{perfdata}->threshold_check(value => $fetch_eof, threshold => [ { label => 'critical-eof', 'exit_litteral' => 'critical' }, { label => 'warning-eof', exit_litteral => 'warning' } ]); + my $exit5 = $self->{perfdata}->threshold_check(value => $fetch_eof, threshold => [ { label => 'critical-eof', 'exit_litteral' => 'critical' }, { label => 'warning-eof', exit_litteral => 'warning' } ]); + my $exit6 = $self->{perfdata}->threshold_check(value => $fetch_close, threshold => [ { label => 'critical-close', 'exit_litteral' => 'critical' }, { label => 'warning-close', exit_litteral => 'warning' } ]); + my $exit7 = $self->{perfdata}->threshold_check(value => $fetch_oldhttp, threshold => [ { label => 'critical-oldhttp', 'exit_litteral' => 'critical' }, { label => 'warning-oldhttp', exit_litteral => 'warning' } ]); + my $exit8 = $self->{perfdata}->threshold_check(value => $fetch_zero, threshold => [ { label => 'critical-zero', 'exit_litteral' => 'critical' }, { label => 'warning-zero', exit_litteral => 'warning' } ]); + my $exit9 = $self->{perfdata}->threshold_check(value => $fetch_failed, threshold => [ { label => 'critical-failed', 'exit_litteral' => 'critical' }, { label => 'warning-failed', exit_litteral => 'warning' } ]); + my $exit10 = $self->{perfdata}->threshold_check(value => $fetch_1xx, threshold => [ { label => 'critical-1xx', 'exit_litteral' => 'critical' }, { label => 'warning-1xx', exit_litteral => 'warning' } ]); + my $exit11 = $self->{perfdata}->threshold_check(value => $fetch_204, threshold => [ { label => 'critical-204', 'exit_litteral' => 'critical' }, { label => 'warning-204', exit_litteral => 'warning' } ]); + my $exit12 = $self->{perfdata}->threshold_check(value => $fetch_304, threshold => [ { label => 'critical-304', 'exit_litteral' => 'critical' }, { label => 'warning-304', exit_litteral => 'warning' } ]); + + my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3, $exit4, $exit5, $exit6, $exit7, $exit8, $exit9, $exit10, $exit11, $exit12 ]); + + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Fetch head: %.2f + Fetch with Length: %.2f + Fetch chunked: %.2f + Fetch EOF: %.2f + Fetch had bad headers: %.2f + Fetch wanted close: %.2f + Fetch pre HTTP/1.1 closed: %.2f + Fetch zero len: %.2f + Fetch failed: %.2f + Fetch no body (1xx): %.2f + Fetch no body (204): %.2f + Fetch no body (304): %.2f ", + $fetch_head, + $fetch_length, + $fetch_chunked, + $fetch_eof, + $fetch_bad, + $fetch_close, + $fetch_oldhttp, + $fetch_zero, + $fetch_failed, + $fetch_1xx, + $fetch_204, + $fetch_304, + )); + + $self->{output}->perfdata_add(label => "fetch_head", + value => $fetch_head, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-head'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-head'), + min => 0 + ); + $self->{output}->perfdata_add(label => "fetch_length", + value => $fetch_length, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-length'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-length'), + min => 0 + ); + $self->{output}->perfdata_add(label => "fetch_chunked", + value => $fetch_chunked, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-chunked'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-chunked'), + min => 0 + ); + $self->{output}->perfdata_add(label => "fetch_eof", + value => $fetch_eof, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-eof'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-eof'), + min => 0 + ); + $self->{output}->perfdata_add(label => "fetch_bad", + value => $fetch_bad, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-bad'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-bad'), + min => 0 + ); + $self->{output}->perfdata_add(label => "fetch_close", + value => $fetch_close, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-close'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-close'), + min => 0 + ); + $self->{output}->perfdata_add(label => "fetch_oldhttp", + value => $fetch_oldhttp, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-oldhttp'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-oldhttp'), + min => 0 + ); + $self->{output}->perfdata_add(label => "fetch_zero", + value => $fetch_zero, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-zero'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-zero'), + min => 0 + ); + $self->{output}->perfdata_add(label => "fetch_failed", + value => $fetch_failed, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-failed'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-failed'), + min => 0 + ); + + $self->{output}->perfdata_add(label => "fetch_1xx", + value => $fetch_1xx, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-1xx'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-1xx'), + min => 0 + ); + $self->{output}->perfdata_add(label => "fetch_204", + value => $fetch_204, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-204'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-204'), + min => 0 + ); + $self->{output}->perfdata_add(label => "fetch_304", + value => $fetch_304, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-304'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-304'), + min => 0 + ); + + $self->{output}->display(); + $self->{output}->exit(); +}; + + +1; + +__END__ + +=head1 MODE + +Check Varnish Cache with varnishstat Command +This Mode Checks: +- Fetch head +- Fetch with Length +- Fetch chunked +- Fetch EOF +- Fetch had bad headers +- Fetch wanted close +- Fetch pre HTTP/1.1 closed +- Fetch zero len +- Fetch failed +- Fetch no body (1xx) +- Fetch no body (204) +- Fetch no body (304) + +=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-head> + +Warning Threshold for Fetch head + +=item B<--critical-head> + +Critical Threshold for Fetch head + +=item B<--warning-length> + +Warning Threshold for Fetch with Length + +=item B<--critical-length> + +Critical Threshold for Fetch with Length + +=item B<--warning-chunked> + +Warning Threshold for Fetch chunked + +=item B<--critical-chunked> + +Critical Threshold for Fetch chunked + +=item B<--warning-eof> + +Warning Threshold for Fetch EOF + +=item B<--critical-eof> + +Critical Threshold for Fetch EOF + +=item B<--warning-bad> + +Warning Threshold for Fetch had bad headers + +=item B<--critical-bad> + +Critical Threshold for Fetch had bad headers + +=item B<--warning-close> + +Warning Threshold for Fetch wanted close + +=item B<--critical-close> + +Critical Threshold for Fetch wanted close + +=item B<--warning-oldhttp> + +Warning Threshold for Fetch pre HTTP/1.1 closed + +=item B<--critical-oldhttp> + +Critical Threshold for Fetch pre HTTP/1.1 closed + +=item B<--warning-zero> + +Warning Threshold for Fetch zero len + +=item B<--critical-zero> + +Critical Threshold for Fetch zero len + +=item B<--warning-failed> + +Warning Threshold for Fetch failed + +=item B<--critical-failed> + +Critical Threshold for Fetch failed + +=item B<--warning-1xx> + +Warning Threshold for Fetch no body (1xx) + +=item B<--critical-1xx> + +Critical Threshold for Fetch no body (1xx) + +=item B<--warning-204> + +Warning Threshold for Fetch no body (204) + +=item B<--critical-204> + +Critical Threshold for Fetch no body (204) + +=item B<--warning-304> + +Warning Threshold for Fetch no body (304) + +=item B<--critical-304> + +Critical Threshold for Fetch no body (304) + +=back + +=cut \ No newline at end of file diff --git a/apps/varnish/local/plugin.pm b/apps/varnish/local/plugin.pm index 66ba27183..60bb1bf62 100644 --- a/apps/varnish/local/plugin.pm +++ b/apps/varnish/local/plugin.pm @@ -47,9 +47,17 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'cache' => 'apps::varnish::mode::cache', - 'client' => 'apps::varnish::mode::client', - 'backend' => 'apps::varnish::mode::backend', + 'connections' => 'apps::varnish::mode::connections', + 'cache' => 'apps::varnish::mode::cache', + 'backend' => 'apps::varnish::mode::backend', + 'fetch' => 'apps::varnish::mode::fetch', + 'workers' => 'apps::varnish::mode::workers', + 'shm' => 'apps::varnish::mode::shm', + 'sm' => 'apps::varnish::mode::sm', + 'sma' => 'apps::varnish::mode::sma', + 'sms' => 'apps::varnish::mode::sms', + 'hcb' => 'apps::varnish::mode::hcb', + 'esi' => 'apps::varnish::mode::esi', ); return $self; diff --git a/apps/varnish/plugin.pm b/apps/varnish/plugin.pm deleted file mode 100644 index 66ba27183..000000000 --- a/apps/varnish/plugin.pm +++ /dev/null @@ -1,66 +0,0 @@ -############################################################################### -# Copyright 2005-2013 MERETHIS -# Centreon is developped by : Julien Mathis and Romain Le Merlus under -# GPL Licence 2.0. -# -# This program is free software; you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the Free Software -# Foundation ; either version 2 of the License. -# -# This program is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along with -# this program; if not, see . -# -# Linking this program statically or dynamically with other modules is making a -# combined work based on this program. Thus, the terms and conditions of the GNU -# General Public License cover the whole combination. -# -# As a special exception, the copyright holders of this program give MERETHIS -# permission to link this program with independent modules to produce an executable, -# regardless of the license terms of these independent modules, and to copy and -# distribute the resulting executable under terms of MERETHIS choice, provided that -# MERETHIS also meet, for each linked independent module, the terms and conditions -# of the license of that module. An independent module is a module which is not -# derived from this program. If you modify this program, you may extend this -# exception to your version of the program, but you are not obliged to do so. If you -# do not wish to do so, delete this exception statement from your version. -# -# For more information : contact@centreon.com -# Author : Florian Asche -# -#################################################################################### - -package apps::varnish::plugin; - -use strict; -use warnings; -use base qw(centreon::plugins::script_simple); - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; -# $options->{options} = options object - - $self->{version} = '0.1'; - %{$self->{modes}} = ( - 'cache' => 'apps::varnish::mode::cache', - 'client' => 'apps::varnish::mode::client', - 'backend' => 'apps::varnish::mode::backend', - ); - - return $self; -} - -1; - -__END__ - -=head1 PLUGIN DESCRIPTION - -Check Varnish with Local Command or with SSH - -=cut