| 1 |
# |
| 2 |
# Copyright 2024 Centreon (http://www.centreon.com/) |
| 3 |
# |
| 4 |
# Centreon is a full-fledged industry-strength solution that meets |
| 5 |
# the needs in IT infrastructure and application monitoring for |
| 6 |
# service performance. |
| 7 |
# |
| 8 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 |
# you may not use this file except in compliance with the License. |
| 10 |
# You may obtain a copy of the License at |
| 11 |
# |
| 12 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 13 |
# |
| 14 |
# Unless required by applicable law or agreed to in writing, software |
| 15 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 16 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 |
# See the License for the specific language governing permissions and |
| 18 |
# limitations under the License. |
| 19 |
# |
| 20 |
|
| 21 |
package database::warp10::sensision::mode::fetchstatistics; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use centreon::common::monitoring::openmetrics::scrape; |
| 28 |
use Digest::MD5 qw(md5_hex); |
| 29 |
|
| 30 |
sub set_counters { |
| 31 |
my ($self, %options) = @_; |
| 32 |
|
| 33 |
$self->{maps_counters_type} = [ |
| 34 |
{ name => 'fetchs', type => 1, cb_prefix_output => 'prefix_output', |
| 35 |
message_multiple => 'All fetchs statistics are ok' }, |
| 36 |
]; |
| 37 |
|
| 38 |
$self->{maps_counters}->{fetchs} = [ |
| 39 |
{ label => 'calls-count', nlabel => 'fetch.calls.count', set => { |
| 40 |
key_values => [ { name => 'calls', diff => 1 }, { name => 'display' } ], |
| 41 |
output_template => 'Calls: %d', |
| 42 |
perfdatas => [ |
| 43 |
{ template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display' }, |
| 44 |
], |
| 45 |
} |
| 46 |
}, |
| 47 |
{ label => 'calls-persecond', nlabel => 'fetch.calls.persecond', set => { |
| 48 |
key_values => [ { name => 'calls', per_second => 1 }, { name => 'display' } ], |
| 49 |
output_template => 'Calls (per second): %.2f', |
| 50 |
perfdatas => [ |
| 51 |
{ template => '%.2f', min => 0, label_extra_instance => 1, instance_use => 'display' }, |
| 52 |
], |
| 53 |
} |
| 54 |
}, |
| 55 |
{ label => 'bytes-values-count', nlabel => 'fetch.bytes.values.bytes', set => { |
| 56 |
key_values => [ { name => 'bytes_values', diff => 1 }, { name => 'display' } ], |
| 57 |
output_template => 'Bytes Values: %s%s', |
| 58 |
output_change_bytes => 1, |
| 59 |
perfdatas => [ |
| 60 |
{ template => '%s', min => 0, unit => 'B', label_extra_instance => 1, instance_use => 'display' }, |
| 61 |
], |
| 62 |
} |
| 63 |
}, |
| 64 |
{ label => 'bytes-values-persecond', nlabel => 'fetch.bytes.values.bytespersecond', set => { |
| 65 |
key_values => [ { name => 'bytes_values', per_second => 1 }, { name => 'display' } ], |
| 66 |
output_change_bytes => 1, |
| 67 |
output_template => 'Bytes Values (per second): %s%s/s', |
| 68 |
perfdatas => [ |
| 69 |
{ template => '%s', min => 0, unit => 'B/s', label_extra_instance => 1, instance_use => 'display' }, |
| 70 |
], |
| 71 |
} |
| 72 |
}, |
| 73 |
{ label => 'bytes-keys-count', nlabel => 'fetch.bytes.keys.bytes', set => { |
| 74 |
key_values => [ { name => 'bytes_keys', diff => 1 }, { name => 'display' } ], |
| 75 |
output_template => 'Bytes Keys: %s%s', |
| 76 |
output_change_bytes => 1, |
| 77 |
perfdatas => [ |
| 78 |
{ template => '%s', min => 0, unit => 'B', label_extra_instance => 1, instance_use => 'display' }, |
| 79 |
], |
| 80 |
} |
| 81 |
}, |
| 82 |
{ label => 'bytes-keys-persecond', nlabel => 'fetch.bytes.keys.bytespersecond', set => { |
| 83 |
key_values => [ { name => 'bytes_keys', per_second => 1 }, { name => 'display' } ], |
| 84 |
output_change_bytes => 1, |
| 85 |
output_template => 'Bytes Keys (per second): %s%s/s', |
| 86 |
perfdatas => [ |
| 87 |
{ template => '%s', min => 0, unit => 'B/s', label_extra_instance => 1, instance_use => 'display' }, |
| 88 |
], |
| 89 |
} |
| 90 |
}, |
| 91 |
{ label => 'datapoints-count', nlabel => 'fetch.datapoints.count', set => { |
| 92 |
key_values => [ { name => 'datapoints', diff => 1 }, { name => 'display' } ], |
| 93 |
output_template => 'Datapoints: %d', |
| 94 |
perfdatas => [ |
| 95 |
{ template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display' }, |
| 96 |
], |
| 97 |
} |
| 98 |
}, |
| 99 |
{ label => 'datapoints-persecond', nlabel => 'fetch.datapoints.persecond', set => { |
| 100 |
key_values => [ { name => 'datapoints', per_second => 1 }, { name => 'display' } ], |
| 101 |
output_template => 'Datapoints (per second): %.2f', |
| 102 |
perfdatas => [ |
| 103 |
{ template => '%.2f', min => 0, label_extra_instance => 1, instance_use => 'display' }, |
| 104 |
], |
| 105 |
} |
| 106 |
}, |
| 107 |
]; |
| 108 |
} |
| 109 |
|
| 110 |
sub prefix_output { |
| 111 |
my ($self, %options) = @_; |
| 112 |
|
| 113 |
return "Fetch '" . $options{instance_value}->{display} . "' "; |
| 114 |
} |
| 115 |
|
| 116 |
sub new { |
| 117 |
my ($class, %options) = @_; |
| 118 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); |
| 119 |
bless $self, $class; |
| 120 |
|
| 121 |
$options{options}->add_options(arguments => { |
| 122 |
'filter-name:s' => { name => 'filter_name' } |
| 123 |
}); |
| 124 |
|
| 125 |
return $self; |
| 126 |
} |
| 127 |
|
| 128 |
sub manage_selection { |
| 129 |
my ($self, %options) = @_; |
| 130 |
|
| 131 |
$self->{cache_name} = "warp10_" . $self->{mode} . '_' . |
| 132 |
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')) . '_' . |
| 133 |
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); |
| 134 |
|
| 135 |
$self->{metrics} = centreon::common::monitoring::openmetrics::scrape::parse(%options); |
| 136 |
|
| 137 |
foreach my $fetch (@{$self->{metrics}->{'warp.fetch.count'}->{data}}) { |
| 138 |
$self->{fetchs}->{$fetch->{dimensions}->{app}}->{calls} = $fetch->{value}; |
| 139 |
$self->{fetchs}->{$fetch->{dimensions}->{app}}->{display} = $fetch->{dimensions}->{app}; |
| 140 |
} |
| 141 |
foreach my $fetch (@{$self->{metrics}->{'warp.fetch.bytes.values'}->{data}}) { |
| 142 |
$self->{fetchs}->{$fetch->{dimensions}->{app}}->{bytes_values} = $fetch->{value}; |
| 143 |
$self->{fetchs}->{$fetch->{dimensions}->{app}}->{display} = $fetch->{dimensions}->{app}; |
| 144 |
} |
| 145 |
foreach my $fetch (@{$self->{metrics}->{'warp.fetch.bytes.keys'}->{data}}) { |
| 146 |
$self->{fetchs}->{$fetch->{dimensions}->{app}}->{bytes_keys} = $fetch->{value}; |
| 147 |
$self->{fetchs}->{$fetch->{dimensions}->{app}}->{display} = $fetch->{dimensions}->{app}; |
| 148 |
} |
| 149 |
foreach my $fetch (@{$self->{metrics}->{'warp.fetch.datapoints'}->{data}}) { |
| 150 |
$self->{fetchs}->{$fetch->{dimensions}->{app}}->{datapoints} = $fetch->{value}; |
| 151 |
$self->{fetchs}->{$fetch->{dimensions}->{app}}->{display} = $fetch->{dimensions}->{app}; |
| 152 |
} |
| 153 |
|
| 154 |
foreach (keys %{$self->{fetchs}}) { |
| 155 |
delete $self->{fetchs}->{$_} if (defined($self->{option_results}->{filter_name}) && |
| 156 |
$self->{option_results}->{filter_name} ne '' && |
| 157 |
$_ !~ /$self->{option_results}->{filter_name}/); |
| 158 |
} |
| 159 |
|
| 160 |
if (scalar(keys %{$self->{fetchs}}) <= 0) { |
| 161 |
$self->{output}->add_option_msg(short_msg => "No fetchs found."); |
| 162 |
$self->{output}->option_exit(); |
| 163 |
} |
| 164 |
} |
| 165 |
|
| 166 |
1; |
| 167 |
|
| 168 |
__END__ |
| 169 |
|
| 170 |
=head1 MODE |
| 171 |
|
| 172 |
Check fetchs statistics. |
| 173 |
|
| 174 |
=over 8 |
| 175 |
|
| 176 |
=item B<--filter-name> |
| 177 |
|
| 178 |
Filter app name (can be a regexp). |
| 179 |
|
| 180 |
=item B<--filter-counters> |
| 181 |
|
| 182 |
Only display some counters (regexp can be used). |
| 183 |
Example: --filter-counters='calls' |
| 184 |
|
| 185 |
=item B<--warning-*-count/persecond> |
| 186 |
|
| 187 |
Warning threshold. |
| 188 |
Can be: 'calls', 'bytes-values', 'bytes-keys'. |
| 189 |
|
| 190 |
=item B<--critical-*-count/persecond> |
| 191 |
|
| 192 |
Critical threshold. |
| 193 |
Can be: 'calls', 'bytes-values', 'bytes-keys'. |
| 194 |
|
| 195 |
=back |
| 196 |
|
| 197 |
=cut |