centreon-plugins/blockchain/parity/ethpoller/mode/stats.pm

134 lines
4.8 KiB
Perl
Raw Normal View History

#
# 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;
2020-05-11 17:50:37 +02:00
use bigint;
use Digest::MD5 qw(md5_hex);
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
2020-05-11 17:50:37 +02:00
{ name => 'block', cb_prefix_output => 'prefix_output_block', type => 0 },
{ name => 'transaction', cb_prefix_output => 'prefix_output_transaction', type => 0 }
];
2020-05-11 17:50:37 +02:00
$self->{maps_counters}->{block} = [
2020-05-12 22:26:06 +02:00
{ label => 'block_frequency', nlabel => 'parity.stats.block.persecond', set => {
2020-05-14 18:06:15 +02:00
key_values => [ { name => 'block_count', diff => 1 } ],
2020-05-12 22:26:06 +02:00
per_second => 1,
output_template => "Block frequency: %.2f (block/s)",
perfdatas => [
2020-05-12 22:26:06 +02:00
{ label => 'block', value => 'block_count_per_second', template => ' %.2f',
label_extra_instance => 1, instance_use => 'display_absolute' }
],
}
2020-05-11 17:50:37 +02:00
}
];
$self->{maps_counters}->{transaction} = [
2020-05-12 22:26:06 +02:00
{ label => 'transaction_frequency', nlabel => 'parity.stats.transaction.persecond', set => {
key_values => [ { name => 'transaction_count', diff => 1 } ],
per_second => 1,
output_template => "Transaction frequency: %.2f (tx/s)",
perfdatas => [
2020-05-12 22:26:06 +02:00
{ label => 'transaction', value => 'transaction_count_per_second', template => '%.2f',
label_extra_instance => 1, instance_use => 'display_absolute' }
],
}
2020-05-11 17:50:37 +02:00
}
];
2020-05-11 17:50:37 +02:00
}
2020-05-11 17:50:37 +02:00
sub prefix_output_block {
my ($self, %options) = @_;
return "Block stats '";
}
sub prefix_output_fork {
my ($self, %options) = @_;
return "Fork stats '";
}
2020-05-11 17:50:37 +02:00
sub prefix_output_transaction {
my ($self, %options) = @_;
2020-05-11 17:50:37 +02:00
return "Transaction stats '";
}
sub new {
my ($class, %options) = @_;
2020-05-11 17:50:37 +02:00
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) = @_;
2020-05-11 17:50:37 +02:00
$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'));
2020-05-11 17:50:37 +02:00
my $result = $options{custom}->request_api(url_path => '/stats');
2020-05-12 22:26:06 +02:00
$self->{block} = { block_count => $result->{block}->{count} };
2020-05-11 17:50:37 +02:00
2020-05-12 22:26:06 +02:00
$self->{transaction} = { transaction_count => $result->{transaction}->{count} };
2020-05-11 17:50:37 +02:00
2020-05-12 22:26:06 +02:00
my $block_timestamp = $result->{block}->{timestamp} == 0 ? '' : localtime($result->{block}->{timestamp});
2020-05-18 23:25:03 +02:00
$self->{output}->output_add(severity => 'OK', long_msg => 'Last block (#' . $result->{block}->{count} . ') was on ' . $block_timestamp);
2020-05-11 17:50:37 +02:00
2020-05-12 22:26:06 +02:00
if ($result->{transaction}->{count} > 0) {
my $tx_timestamp = $result->{transaction}->{timestamp} == 0 ? '' : localtime($result->{transaction}->{timestamp});
2020-05-18 23:25:03 +02:00
$self->{output}->output_add(severity => 'OK', long_msg => 'Last transaction (#' . $result->{transaction}->{count} . ') was on ' . $tx_timestamp);
2020-05-11 17:50:37 +02:00
} else {
2020-05-12 22:26:06 +02:00
$self->{output}->output_add(severity => 'OK', long_msg => 'No transaction...');
2020-05-11 17:50:37 +02:00
}
2020-05-12 22:26:06 +02:00
if ($result->{transaction}->{count} > 0) {
my $fork_timestamp = $result->{fork}->{timestamp} == 0 ? '' : localtime($result->{fork}->{timestamp});
2020-05-18 23:25:03 +02:00
$self->{output}->output_add(severity => 'OK', long_msg => 'Last fork (#' . $result->{fork}->{count} . ') was on ' . $fork_timestamp);
2020-05-11 17:50:37 +02:00
} else {
2020-05-12 22:26:06 +02:00
$self->{output}->output_add(severity => 'OK', long_msg => 'No fork occurence...');
2020-05-11 17:50:37 +02:00
}
}
1;
__END__
=head1 MODE
2020-05-11 17:50:37 +02:00
Check Parity eth-poller for stats
=cut