mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-27 23:54:18 +02:00
workon parity bc
This commit is contained in:
parent
73e74fb6e1
commit
294f45ee48
@ -40,18 +40,19 @@ sub set_counters {
|
|||||||
manual_keys => 1,
|
manual_keys => 1,
|
||||||
closure_custom_calc => $self->can('custom_prct_calc'),
|
closure_custom_calc => $self->can('custom_prct_calc'),
|
||||||
closure_custom_output => $self->can('custom_prct_output'),
|
closure_custom_output => $self->can('custom_prct_output'),
|
||||||
threshold_use => 'balance_fluctuation',
|
threshold_use => 'balance_fluctuation_prct',
|
||||||
perfdatas => [
|
perfdatas => [
|
||||||
{ value => 'balance_fluctuation', template => '%.2f',
|
{ value => 'balance_fluctuation_prct', template => '%.2f', unit => '%',
|
||||||
min => 0, label_extra_instance => 1, instance_use => 'display' },
|
min => 0, label_extra_instance => 1, instance_use => 'display' }
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ label => 'balance', nlabel => 'parity.tracking.balance', set => {
|
{ label => 'balance', nlabel => 'parity.tracking.balance', set => {
|
||||||
key_values => [ { name => 'balance' } ],
|
key_values => [ { name => 'balance' } ],
|
||||||
output_template => "%d (wei)",
|
output_template => "%s (wei)",
|
||||||
perfdatas => [
|
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 {
|
sub custom_prct_output {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
# use Data::Dumper;
|
|
||||||
# print Dumper('$total_balance');
|
|
||||||
return sprintf(
|
return sprintf(
|
||||||
"balance variation: %.2f ",
|
"balance variation: %.2f ",
|
||||||
$self->{result_values}->{balance_fluctuation}
|
$self->{result_values}->{balance_fluctuation_prct}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sub custom_prct_calc {
|
sub custom_prct_calc {
|
||||||
use Data::Dumper;
|
|
||||||
|
|
||||||
my ($self, %options) = @_;
|
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}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
|
||||||
$self->{result_values}->{balance_fluctuation} = 0;
|
$self->{result_values}->{balance} = $options{new_datas}->{$self->{instance} . '_balance'};
|
||||||
if ($old_balance > 0) {
|
$self->{result_values}->{balance_old} = $options{old_datas}->{$self->{instance} . '_balance'};
|
||||||
$self->{result_values}->{balance_fluctuation} = ($new_balance - $old_balance) / $old_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 {
|
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'));
|
(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');
|
my $result = $options{custom}->request_api(url_path => '/tracking');
|
||||||
use Data::Dumper;
|
|
||||||
# print Dumper($result);
|
|
||||||
|
|
||||||
foreach my $balance (@{$result->{balances}}) {
|
foreach my $balance (@{$result->{balances}}) {
|
||||||
# print Dumper($balance);
|
$self->{balances}->{lc($balance->{label})} = { display => lc($balance->{label}),
|
||||||
$self->{balances}->{$balance->{label}} = { display => $balance->{label} };
|
balance => $balance->{balance}
|
||||||
$self->{balances}->{$balance->{label}}->{'balance'} = $balance->{balance};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,133 +1,148 @@
|
|||||||
#
|
#
|
||||||
# Copyright 2020 Centreon (http://www.centreon.com/)
|
# Copyright 2020 Centreon (http://www.centreon.com/)
|
||||||
#
|
#
|
||||||
# Centreon is a full-fledged industry-strength solution that meets
|
# Centreon is a full-fledged industry-strength solution that meets
|
||||||
# the needs in IT infrastructure and application monitoring for
|
# the needs in IT infrastructure and application monitoring for
|
||||||
# service performance.
|
# service performance.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
# You may obtain a copy of the License at
|
# You may obtain a copy of the License at
|
||||||
#
|
#
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
#
|
#
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
package blockchain::parity::ethpoller::mode::stats;
|
package blockchain::parity::ethpoller::mode::stats;
|
||||||
|
|
||||||
use base qw(centreon::plugins::templates::counter);
|
use base qw(centreon::plugins::templates::counter);
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use bigint;
|
use bigint;
|
||||||
use Digest::MD5 qw(md5_hex);
|
use Digest::MD5 qw(md5_hex);
|
||||||
|
|
||||||
sub set_counters {
|
sub set_counters {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->{maps_counters_type} = [
|
$self->{maps_counters_type} = [
|
||||||
{ name => 'block', cb_prefix_output => 'prefix_output_block', type => 0 },
|
{ name => 'block', cb_prefix_output => 'prefix_output_block', type => 0 },
|
||||||
{ name => 'transaction', cb_prefix_output => 'prefix_output_transaction', type => 0 }
|
{ name => 'transaction', cb_prefix_output => 'prefix_output_transaction', type => 0 }
|
||||||
];
|
];
|
||||||
|
|
||||||
$self->{maps_counters}->{block} = [
|
$self->{maps_counters}->{block} = [
|
||||||
{ label => 'block_frequency', nlabel => 'parity.stats.block.perminute', set => {
|
{ label => 'block-frequency', nlabel => 'parity.stats.block.perminute', set => {
|
||||||
key_values => [ { name => 'block_count', diff => 1 } ],
|
key_values => [ { name => 'block_count', per_minute => 1 }, { name => 'last_block' }, { name => 'last_block_ts' } ],
|
||||||
per_minute => 1,
|
per_minute => 1,
|
||||||
output_template => "Block frequency: %.2f (block/min)",
|
closure_custom_output => $self->can('custom_block_output'),
|
||||||
perfdatas => [
|
perfdatas => [
|
||||||
{ label => 'block', value => 'block_count_per_minute', template => ' %.2f',
|
{ label => 'block', value => 'block_count', template => '%.2f' }
|
||||||
label_extra_instance => 1, instance_use => 'display_absolute' }
|
],
|
||||||
],
|
}
|
||||||
}
|
}
|
||||||
}
|
];
|
||||||
];
|
|
||||||
|
$self->{maps_counters}->{transaction} = [
|
||||||
$self->{maps_counters}->{transaction} = [
|
{ label => 'transaction_frequency', nlabel => 'parity.stats.transaction.perminute', set => {
|
||||||
{ label => 'transaction_frequency', nlabel => 'parity.stats.transaction.perminute', set => {
|
key_values => [ { name => 'transaction_count', per_minute => 1 } ],
|
||||||
key_values => [ { name => 'transaction_count', diff => 1 } ],
|
per_minute => 1,
|
||||||
per_minute => 1,
|
output_template => "Transaction frequency: %.2f (tx/min)",
|
||||||
output_template => "Transaction frequency: %.2f (tx/min)",
|
perfdatas => [
|
||||||
perfdatas => [
|
{ label => 'transaction', value => 'transaction_count_per_minute', template => '%.2f' }
|
||||||
{ label => 'transaction', value => 'transaction_count_per_minute', template => '%.2f',
|
],
|
||||||
label_extra_instance => 1, instance_use => 'display_absolute' }
|
}
|
||||||
],
|
}
|
||||||
}
|
];
|
||||||
}
|
}
|
||||||
];
|
|
||||||
}
|
sub custom_block_output {
|
||||||
|
my ($self, %options) = @_;
|
||||||
sub prefix_output_block {
|
|
||||||
my ($self, %options) = @_;
|
return sprintf(
|
||||||
|
"Count: '%.2f', Last block ID: '%s', Last block timestamp '%s' ",
|
||||||
return "Block stats '";
|
$self->{result_values}->{block_count},
|
||||||
}
|
$self->{result_values}->{last_block},
|
||||||
|
$self->{result_values}->{last_block_ts}
|
||||||
sub prefix_output_fork {
|
);
|
||||||
my ($self, %options) = @_;
|
}
|
||||||
|
|
||||||
return "Fork stats '";
|
|
||||||
}
|
sub prefix_output_block {
|
||||||
|
my ($self, %options) = @_;
|
||||||
sub prefix_output_transaction {
|
|
||||||
my ($self, %options) = @_;
|
return "Block stats '";
|
||||||
|
}
|
||||||
return "Transaction stats '";
|
|
||||||
}
|
sub prefix_output_fork {
|
||||||
|
my ($self, %options) = @_;
|
||||||
sub new {
|
|
||||||
my ($class, %options) = @_;
|
return "Fork stats '";
|
||||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, statefile => 1);
|
}
|
||||||
bless $self, $class;
|
|
||||||
|
sub prefix_output_transaction {
|
||||||
$options{options}->add_options(arguments => {
|
my ($self, %options) = @_;
|
||||||
"filter-name:s" => { name => 'filter_name' },
|
|
||||||
});
|
return "Transaction stats '";
|
||||||
|
}
|
||||||
return $self;
|
|
||||||
}
|
sub new {
|
||||||
|
my ($class, %options) = @_;
|
||||||
sub manage_selection {
|
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, statefile => 1);
|
||||||
my ($self, %options) = @_;
|
bless $self, $class;
|
||||||
|
|
||||||
$self->{cache_name} = "parity_ethpoller_" . $self->{mode} . '_' . (defined($self->{option_results}->{hostname}) ? $self->{option_results}->{hostname} : 'me') . '_' .
|
$options{options}->add_options(arguments => {
|
||||||
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
|
"filter-name:s" => { name => 'filter_name' },
|
||||||
|
});
|
||||||
my $result = $options{custom}->request_api(url_path => '/stats');
|
|
||||||
|
return $self;
|
||||||
$self->{block} = { block_count => $result->{block}->{count} };
|
}
|
||||||
|
|
||||||
$self->{transaction} = { transaction_count => $result->{transaction}->{count} };
|
sub manage_selection {
|
||||||
|
my ($self, %options) = @_;
|
||||||
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);
|
$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'));
|
||||||
if ($result->{transaction}->{count} > 0) {
|
|
||||||
my $tx_timestamp = $result->{transaction}->{timestamp} == 0 ? '' : localtime($result->{transaction}->{timestamp});
|
my $result = $options{custom}->request_api(url_path => '/stats');
|
||||||
$self->{output}->output_add(severity => 'OK', long_msg => 'Last transaction (#' . $result->{transaction}->{count} . ') was on ' . $tx_timestamp);
|
|
||||||
} else {
|
my $last_block = $result->{block}->{count};
|
||||||
$self->{output}->output_add(severity => 'OK', long_msg => 'No transaction...');
|
my $last_block_timestamp = (defined($result->{block}->{timestamp}) && $result->{block}->{timestamp} != 0) ?
|
||||||
}
|
localtime($result->{block}->{timestamp}) :
|
||||||
|
'NONE';
|
||||||
if ($result->{transaction}->{count} > 0) {
|
|
||||||
my $fork_timestamp = $result->{fork}->{timestamp} == 0 ? '' : localtime($result->{fork}->{timestamp});
|
$self->{block} = { block_count => $result->{block}->{count},
|
||||||
$self->{output}->output_add(severity => 'OK', long_msg => 'Last fork (#' . $result->{fork}->{count} . ') was on ' . $fork_timestamp);
|
last_block => $last_block,
|
||||||
} else {
|
last_block_ts => $last_block_timestamp };
|
||||||
$self->{output}->output_add(severity => 'OK', long_msg => 'No fork occurence...');
|
|
||||||
}
|
$self->{transaction} = { transaction_count => $result->{transaction}->{count} };
|
||||||
}
|
|
||||||
|
if ($result->{transaction}->{count} > 0) {
|
||||||
1;
|
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);
|
||||||
__END__
|
} else {
|
||||||
|
$self->{output}->output_add(severity => 'OK', long_msg => 'No transaction...');
|
||||||
=head1 MODE
|
}
|
||||||
|
|
||||||
Check Parity eth-poller for stats
|
if ($result->{transaction}->{count} > 0) {
|
||||||
|
my $fork_timestamp = $result->{fork}->{timestamp} == 0 ? '' : localtime($result->{fork}->{timestamp});
|
||||||
=cut
|
$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
|
||||||
|
|
||||||
|
@ -38,12 +38,12 @@ sub set_counters {
|
|||||||
|
|
||||||
$self->{maps_counters}->{events} = [
|
$self->{maps_counters}->{events} = [
|
||||||
{ label => 'events_frequency', nlabel => 'parity.tracking.events.perminute', set => {
|
{ 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,
|
per_minute => 1,
|
||||||
output_template => " %.2f (events/min)",
|
output_template => " %.2f (events/min)",
|
||||||
perfdatas => [
|
perfdatas => [
|
||||||
{ label => 'events', template => '%.2f', value => 'events_count_per_minute',
|
{ label => 'events', template => '%.2f', value => 'events_count',
|
||||||
label_extra_instance => 1, instance_use => 'display_absolute' }
|
label_extra_instance => 1, instance_use => 'display' }
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -51,23 +51,23 @@ sub set_counters {
|
|||||||
|
|
||||||
$self->{maps_counters}->{mining} = [
|
$self->{maps_counters}->{mining} = [
|
||||||
{ label => 'mining_frequency', nlabel => 'parity.tracking.mined.block.perminute', set => {
|
{ 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,
|
per_minute => 1,
|
||||||
output_template => " %.2f (blocks/min)",
|
output_template => " %.2f (blocks/min)",
|
||||||
perfdatas => [ { label => 'mining', template => '%.2f', value => 'mining_count_per_minute',
|
perfdatas => [ { label => 'mining', template => '%.2f', value => 'mining_count',
|
||||||
label_extra_instance => 1, instance_use => 'display_absolute' } ],
|
label_extra_instance => 1, instance_use => 'display' } ],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
$self->{maps_counters}->{balance} = [
|
$self->{maps_counters}->{balance} = [
|
||||||
{ label => 'balance_fluctuation', nlabel => 'parity.tracking.balance.variation.perminute', set => {
|
{ 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,
|
per_minute => 1,
|
||||||
output_template => " variation: %.2f (diff/min)",
|
output_template => " variation: %.2f (diff/min)",
|
||||||
perfdatas => [
|
perfdatas => [
|
||||||
{ label => 'balances', template => '%.2f', value => 'balance_per_minute',
|
{ label => 'balances', template => '%.2f', value => 'balance',
|
||||||
label_extra_instance => 1, instance_use => 'display_absolute' }
|
label_extra_instance => 1, instance_use => 'display' }
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user