prct improvments

This commit is contained in:
Lotfi zaouche 2020-05-14 05:40:48 +00:00
parent 6d0b3ef31e
commit 4eb67c696a
1 changed files with 34 additions and 14 deletions

View File

@ -35,42 +35,62 @@ sub set_counters {
]; ];
$self->{maps_counters}->{balances} = [ $self->{maps_counters}->{balances} = [
{ label => 'balance-fluctuation-prct', nlabel => 'parity.tracking.balances.variation.persecond', display_ok => 0, set => { { label => 'balance-fluctuation-prct', nlabel => 'parity.tracking.balances.fluctuation', display_ok => 0, set => {
key_values => [], key_values => [],
manual_keys => 1, manual_keys => 1,
closure_custom_calc => $self->can('custom_loss_calc'), closure_custom_calc => $self->can('custom_prct_calc'),
closure_custom_output => $self->can('custom_loss_output'), closure_custom_output => $self->can('custom_prct_output'),
threshold_use => 'balance_fluctuation', threshold_use => 'balance_fluctuation',
perfdatas => [ perfdatas => [
{ value => 'balance_fluctuation', template => '%d', { value => 'balance_fluctuation', template => '%.2f',
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 => {
key_values => [ { name => 'balance' } ],
output_template => "%d (wei)",
perfdatas => [
{ label => 'balance', template => '%d', value => 'balance_absolute' }
],
}
} }
]; ];
} }
sub custom_loss_output { sub custom_prct_output {
my ($self, %options) = @_; my ($self, %options) = @_;
# use Data::Dumper; # use Data::Dumper;
# print Dumper('$total_balance'); # print Dumper('$total_balance');
return sprintf( return sprintf(
"balance variation: %.2f%% ", "balance variation: %.2f ",
$self->{result_values}->{balance_fluctuation} $self->{result_values}->{balance_fluctuation}
); );
} }
sub custom_loss_calc { sub custom_prct_calc {
use Data::Dumper;
my ($self, %options) = @_; my ($self, %options) = @_;
my $new_balance = $options{new_datas}->{$_}; my ($old_balance, $new_balance) = (0, 0);
my $old_balance = $options{old_datas}->{$_}; 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);
}
}
# use Data::Dumper;
# print Dumper($total_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_fluctuation} = 0;
if ($old_balance > 0) { if ($old_balance > 0) {
@ -83,7 +103,7 @@ sub custom_loss_calc {
sub prefix_output_balances { sub prefix_output_balances {
my ($self, %options) = @_; my ($self, %options) = @_;
return "Balance '" . $options{instance_value}->{display} . "' "; return "Balance '" . $options{instance_value}->{display} . "': ";
} }
sub new { sub new {
@ -111,7 +131,7 @@ sub manage_selection {
foreach my $balance (@{$result->{balances}}) { foreach my $balance (@{$result->{balances}}) {
# print Dumper($balance); # print Dumper($balance);
$self->{balances}->{$balance->{label}} = { display => $balance->{label} }; $self->{balances}->{$balance->{label}} = { display => $balance->{label} };
$self->{balances}->{$balance->{label}}->{'balance_fluctuation'} = $balance->{balance}; $self->{balances}->{$balance->{label}}->{'balance'} = $balance->{balance};
} }
} }