diff --git a/centreon-plugins/blockchain/parity/ethpoller/mode/prct.pm b/centreon-plugins/blockchain/parity/ethpoller/mode/prct.pm index 205feff6a..86939435a 100644 --- a/centreon-plugins/blockchain/parity/ethpoller/mode/prct.pm +++ b/centreon-plugins/blockchain/parity/ethpoller/mode/prct.pm @@ -40,18 +40,19 @@ sub set_counters { manual_keys => 1, closure_custom_calc => $self->can('custom_prct_calc'), closure_custom_output => $self->can('custom_prct_output'), - threshold_use => 'balance_fluctuation', + threshold_use => 'balance_fluctuation_prct', perfdatas => [ - { value => 'balance_fluctuation', template => '%.2f', - min => 0, label_extra_instance => 1, instance_use => 'display' }, + { value => 'balance_fluctuation_prct', template => '%.2f', unit => '%', + min => 0, label_extra_instance => 1, instance_use => 'display' } ], } }, { label => 'balance', nlabel => 'parity.tracking.balance', set => { key_values => [ { name => 'balance' } ], - output_template => "%d (wei)", + output_template => "%s (wei)", perfdatas => [ - { label => 'balance', template => '%d', value => 'balance_absolute' } + { label => 'balance', template => '%d', value => 'balance', + min => 0, label_extra_instance => 1, instance_use => 'display' } ], } } @@ -62,42 +63,24 @@ sub set_counters { sub custom_prct_output { my ($self, %options) = @_; - # use Data::Dumper; - # print Dumper('$total_balance'); return sprintf( "balance variation: %.2f ", - $self->{result_values}->{balance_fluctuation} + $self->{result_values}->{balance_fluctuation_prct} ); } + sub custom_prct_calc { - use Data::Dumper; - my ($self, %options) = @_; - my ($old_balance, $new_balance) = (0, 0); - foreach (keys %{$options{new_datas}}) { - # print Dumper($self->{instance}); - # print Dumper($options{new_datas}); - # print Dumper($options{new_datas}->{$_}); - if (/\Q$self->{instance}\E_.*_balance/) { - # print Dumper($self->{instance}); - $new_balance = $options{new_datas}->{$_}; - $old_balance = $options{old_datas}->{$_}; - # print Dumper($old_balance); - # print Dumper($new_balance); - } - } - - - $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; - $self->{result_values}->{balance_fluctuation} = 0; - if ($old_balance > 0) { - $self->{result_values}->{balance_fluctuation} = ($new_balance - $old_balance) / $old_balance; - } - + $self->{result_values}->{balance} = $options{new_datas}->{$self->{instance} . '_balance'}; + $self->{result_values}->{balance_old} = $options{old_datas}->{$self->{instance} . '_balance'}; + $self->{result_values}->{balance_fluctuation_prct} = (defined($self->{result_values}->{balance_old}) && $self->{result_values}->{balance_old} != 0) ? + ($self->{result_values}->{balance} - $self->{result_values}->{balance_old}) / + $self->{result_values}->{balance_old} : 0; + return 0; } sub prefix_output_balances { @@ -125,13 +108,11 @@ sub manage_selection { (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); my $result = $options{custom}->request_api(url_path => '/tracking'); - use Data::Dumper; - # print Dumper($result); foreach my $balance (@{$result->{balances}}) { - # print Dumper($balance); - $self->{balances}->{$balance->{label}} = { display => $balance->{label} }; - $self->{balances}->{$balance->{label}}->{'balance'} = $balance->{balance}; + $self->{balances}->{lc($balance->{label})} = { display => lc($balance->{label}), + balance => $balance->{balance} + }; } } diff --git a/centreon-plugins/blockchain/parity/ethpoller/mode/stats.pm b/centreon-plugins/blockchain/parity/ethpoller/mode/stats.pm index dab08346b..600b30c63 100644 --- a/centreon-plugins/blockchain/parity/ethpoller/mode/stats.pm +++ b/centreon-plugins/blockchain/parity/ethpoller/mode/stats.pm @@ -1,133 +1,148 @@ -# -# Copyright 2020 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 blockchain::parity::ethpoller::mode::stats; - -use base qw(centreon::plugins::templates::counter); - -use strict; -use warnings; -use bigint; -use Digest::MD5 qw(md5_hex); - -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'block', cb_prefix_output => 'prefix_output_block', type => 0 }, - { name => 'transaction', cb_prefix_output => 'prefix_output_transaction', type => 0 } - ]; - - $self->{maps_counters}->{block} = [ - { label => 'block_frequency', nlabel => 'parity.stats.block.perminute', set => { - key_values => [ { name => 'block_count', diff => 1 } ], - per_minute => 1, - output_template => "Block frequency: %.2f (block/min)", - perfdatas => [ - { label => 'block', value => 'block_count_per_minute', template => ' %.2f', - label_extra_instance => 1, instance_use => 'display_absolute' } - ], - } - } - ]; - - $self->{maps_counters}->{transaction} = [ - { label => 'transaction_frequency', nlabel => 'parity.stats.transaction.perminute', set => { - key_values => [ { name => 'transaction_count', diff => 1 } ], - per_minute => 1, - output_template => "Transaction frequency: %.2f (tx/min)", - perfdatas => [ - { label => 'transaction', value => 'transaction_count_per_minute', template => '%.2f', - label_extra_instance => 1, instance_use => 'display_absolute' } - ], - } - } - ]; -} - -sub prefix_output_block { - my ($self, %options) = @_; - - return "Block stats '"; -} - -sub prefix_output_fork { - my ($self, %options) = @_; - - return "Fork stats '"; -} - -sub prefix_output_transaction { - my ($self, %options) = @_; - - return "Transaction stats '"; -} - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, statefile => 1); - bless $self, $class; - - $options{options}->add_options(arguments => { - "filter-name:s" => { name => 'filter_name' }, - }); - - return $self; -} - -sub manage_selection { - my ($self, %options) = @_; - - $self->{cache_name} = "parity_ethpoller_" . $self->{mode} . '_' . (defined($self->{option_results}->{hostname}) ? $self->{option_results}->{hostname} : 'me') . '_' . - (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); - - my $result = $options{custom}->request_api(url_path => '/stats'); - - $self->{block} = { block_count => $result->{block}->{count} }; - - $self->{transaction} = { transaction_count => $result->{transaction}->{count} }; - - my $block_timestamp = $result->{block}->{timestamp} == 0 ? '' : localtime($result->{block}->{timestamp}); - $self->{output}->output_add(severity => 'OK', long_msg => 'Last block (#' . $result->{block}->{count} . ') was on ' . $block_timestamp); - - if ($result->{transaction}->{count} > 0) { - my $tx_timestamp = $result->{transaction}->{timestamp} == 0 ? '' : localtime($result->{transaction}->{timestamp}); - $self->{output}->output_add(severity => 'OK', long_msg => 'Last transaction (#' . $result->{transaction}->{count} . ') was on ' . $tx_timestamp); - } else { - $self->{output}->output_add(severity => 'OK', long_msg => 'No transaction...'); - } - - if ($result->{transaction}->{count} > 0) { - my $fork_timestamp = $result->{fork}->{timestamp} == 0 ? '' : localtime($result->{fork}->{timestamp}); - $self->{output}->output_add(severity => 'OK', long_msg => 'Last fork (#' . $result->{fork}->{count} . ') was on ' . $fork_timestamp); - } else { - $self->{output}->output_add(severity => 'OK', long_msg => 'No fork occurence...'); - } -} - -1; - -__END__ - -=head1 MODE - -Check Parity eth-poller for stats - -=cut +# +# Copyright 2020 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 blockchain::parity::ethpoller::mode::stats; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use bigint; +use Digest::MD5 qw(md5_hex); + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'block', cb_prefix_output => 'prefix_output_block', type => 0 }, + { name => 'transaction', cb_prefix_output => 'prefix_output_transaction', type => 0 } + ]; + + $self->{maps_counters}->{block} = [ + { label => 'block-frequency', nlabel => 'parity.stats.block.perminute', set => { + key_values => [ { name => 'block_count', per_minute => 1 }, { name => 'last_block' }, { name => 'last_block_ts' } ], + per_minute => 1, + closure_custom_output => $self->can('custom_block_output'), + perfdatas => [ + { label => 'block', value => 'block_count', template => '%.2f' } + ], + } + } + ]; + + $self->{maps_counters}->{transaction} = [ + { label => 'transaction_frequency', nlabel => 'parity.stats.transaction.perminute', set => { + key_values => [ { name => 'transaction_count', per_minute => 1 } ], + per_minute => 1, + output_template => "Transaction frequency: %.2f (tx/min)", + perfdatas => [ + { label => 'transaction', value => 'transaction_count_per_minute', template => '%.2f' } + ], + } + } + ]; +} + +sub custom_block_output { + my ($self, %options) = @_; + + return sprintf( + "Count: '%.2f', Last block ID: '%s', Last block timestamp '%s' ", + $self->{result_values}->{block_count}, + $self->{result_values}->{last_block}, + $self->{result_values}->{last_block_ts} + ); +} + + +sub prefix_output_block { + my ($self, %options) = @_; + + return "Block stats '"; +} + +sub prefix_output_fork { + my ($self, %options) = @_; + + return "Fork stats '"; +} + +sub prefix_output_transaction { + my ($self, %options) = @_; + + return "Transaction stats '"; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, statefile => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + "filter-name:s" => { name => 'filter_name' }, + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{cache_name} = "parity_ethpoller_" . $self->{mode} . '_' . (defined($self->{option_results}->{hostname}) ? $self->{option_results}->{hostname} : 'me') . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); + + my $result = $options{custom}->request_api(url_path => '/stats'); + + my $last_block = $result->{block}->{count}; + my $last_block_timestamp = (defined($result->{block}->{timestamp}) && $result->{block}->{timestamp} != 0) ? + localtime($result->{block}->{timestamp}) : + 'NONE'; + + $self->{block} = { block_count => $result->{block}->{count}, + last_block => $last_block, + last_block_ts => $last_block_timestamp }; + + $self->{transaction} = { transaction_count => $result->{transaction}->{count} }; + + if ($result->{transaction}->{count} > 0) { + my $tx_timestamp = $result->{transaction}->{timestamp} == 0 ? '' : localtime($result->{transaction}->{timestamp}); + $self->{output}->output_add(severity => 'OK', long_msg => 'Last transaction (#' . $result->{transaction}->{count} . ') was on ' . $tx_timestamp); + } else { + $self->{output}->output_add(severity => 'OK', long_msg => 'No transaction...'); + } + + if ($result->{transaction}->{count} > 0) { + my $fork_timestamp = $result->{fork}->{timestamp} == 0 ? '' : localtime($result->{fork}->{timestamp}); + $self->{output}->output_add(severity => 'OK', long_msg => 'Last fork (#' . $result->{fork}->{count} . ') was on ' . $fork_timestamp); + } else { + $self->{output}->output_add(severity => 'OK', long_msg => 'No fork occurence...'); + } +} + +1; + +__END__ + +=head1 MODE + +Check Parity eth-poller for stats + +=cut + diff --git a/centreon-plugins/blockchain/parity/ethpoller/mode/tracking.pm b/centreon-plugins/blockchain/parity/ethpoller/mode/tracking.pm index 001e33c42..e30e727f4 100644 --- a/centreon-plugins/blockchain/parity/ethpoller/mode/tracking.pm +++ b/centreon-plugins/blockchain/parity/ethpoller/mode/tracking.pm @@ -38,12 +38,12 @@ sub set_counters { $self->{maps_counters}->{events} = [ { label => 'events_frequency', nlabel => 'parity.tracking.events.perminute', set => { - key_values => [ { name => 'events_count', diff => 1 }, { name => 'display' } ], + key_values => [ { name => 'events_count', per_minute => 1 }, { name => 'display' } ], per_minute => 1, output_template => " %.2f (events/min)", perfdatas => [ - { label => 'events', template => '%.2f', value => 'events_count_per_minute', - label_extra_instance => 1, instance_use => 'display_absolute' } + { label => 'events', template => '%.2f', value => 'events_count', + label_extra_instance => 1, instance_use => 'display' } ], } } @@ -51,23 +51,23 @@ sub set_counters { $self->{maps_counters}->{mining} = [ { label => 'mining_frequency', nlabel => 'parity.tracking.mined.block.perminute', set => { - key_values => [ { name => 'mining_count', diff => 1 }, { name => 'display' } ], + key_values => [ { name => 'mining_count', per_minute => 1 }, { name => 'display' } ], per_minute => 1, output_template => " %.2f (blocks/min)", - perfdatas => [ { label => 'mining', template => '%.2f', value => 'mining_count_per_minute', - label_extra_instance => 1, instance_use => 'display_absolute' } ], + perfdatas => [ { label => 'mining', template => '%.2f', value => 'mining_count', + label_extra_instance => 1, instance_use => 'display' } ], } } ]; $self->{maps_counters}->{balance} = [ { label => 'balance_fluctuation', nlabel => 'parity.tracking.balance.variation.perminute', set => { - key_values => [ { name => 'balance', diff => 1 } ], + key_values => [ { name => 'balance', per_minute => 1 } ], per_minute => 1, output_template => " variation: %.2f (diff/min)", perfdatas => [ - { label => 'balances', template => '%.2f', value => 'balance_per_minute', - label_extra_instance => 1, instance_use => 'display_absolute' } + { label => 'balances', template => '%.2f', value => 'balance', + label_extra_instance => 1, instance_use => 'display' } ], } }