line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package # Hide from pause |
2
|
|
|
|
|
|
|
Monitoring::Livestatus::Class::Abstract::Stats; |
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
4913
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use Carp; |
6
|
|
|
|
|
|
|
extends 'Monitoring::Livestatus::Class::Base::Abstract'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use Monitoring::Livestatus::Class; |
9
|
|
|
|
|
|
|
my $TRACE = Monitoring::Livestatus::Class->TRACE() || 0; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub build_mode { return 'Stats'; }; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub build_compining_prefix { return 'Stats'; } |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub build_operators { |
16
|
|
|
|
|
|
|
my $self = shift; |
17
|
|
|
|
|
|
|
my $operators = $self->SUPER::build_operators(); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
push @{ $operators }, { |
20
|
|
|
|
|
|
|
regexp => qr/(groupby)/ix, |
21
|
|
|
|
|
|
|
handler => '_cond_op_groupby', |
22
|
|
|
|
|
|
|
}; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
push @{ $operators }, { |
25
|
|
|
|
|
|
|
regexp => qr/(sum|min|max|avg|std)/ix, |
26
|
|
|
|
|
|
|
handler => '_cond_op_simple' |
27
|
|
|
|
|
|
|
}; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
push @{ $operators }, { |
30
|
|
|
|
|
|
|
regexp => qr/(isa)/ix, |
31
|
|
|
|
|
|
|
handler => '_cond_op_isa' |
32
|
|
|
|
|
|
|
}; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
return $operators; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub _cond_op_groupby { |
38
|
|
|
|
|
|
|
my $self = shift; |
39
|
|
|
|
|
|
|
my $operator = shift; |
40
|
|
|
|
|
|
|
my $value = shift; |
41
|
|
|
|
|
|
|
my $combining_count = shift || 0; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
print STDERR "#IN _cond_op_groupby $operator $value $combining_count\n" if $TRACE > 9; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my ( @child_statment ) = $self->_dispatch_refkind($value, { |
46
|
|
|
|
|
|
|
SCALAR => sub { |
47
|
|
|
|
|
|
|
return ( sprintf("%s%s: %s",$self->compining_prefix, 'GroupBy', $value) ); |
48
|
|
|
|
|
|
|
}, |
49
|
|
|
|
|
|
|
}); |
50
|
|
|
|
|
|
|
print STDERR "#OUT _cond_op_groupby $operator $value $combining_count\n" if $TRACE > 9; |
51
|
|
|
|
|
|
|
return ( $combining_count, @child_statment ); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _cond_op_simple { |
55
|
|
|
|
|
|
|
my $self = shift; |
56
|
|
|
|
|
|
|
my $operator = shift; |
57
|
|
|
|
|
|
|
my $value = shift; |
58
|
|
|
|
|
|
|
my $combining_count = shift || 0; |
59
|
|
|
|
|
|
|
my @child_statment = (); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
print STDERR "#IN _cond_op_simple $operator $value $combining_count\n" if $TRACE > 9; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
( $combining_count,@child_statment ) = $self->_dispatch_refkind($value, { |
64
|
|
|
|
|
|
|
SCALAR => sub { |
65
|
|
|
|
|
|
|
return (++$combining_count, sprintf("%s: %s %s",$self->compining_prefix,$operator,$value) ); |
66
|
|
|
|
|
|
|
}, |
67
|
|
|
|
|
|
|
}); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
print STDERR "#OUT _cond_op_simple $operator $value $combining_count\n" if $TRACE > 9; |
70
|
|
|
|
|
|
|
return ( $combining_count, @child_statment ); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _cond_op_isa { |
74
|
|
|
|
|
|
|
my $self = shift; |
75
|
|
|
|
|
|
|
my $operator = shift; |
76
|
|
|
|
|
|
|
my $value = shift; |
77
|
|
|
|
|
|
|
my $combining_count = shift || 0; |
78
|
|
|
|
|
|
|
my $as_name; |
79
|
|
|
|
|
|
|
print STDERR "#IN _cond_op_isa $operator $value $combining_count\n" if $TRACE > 9; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
my ( $child_combining_count, @statment ) = $self->_dispatch_refkind($value, { |
82
|
|
|
|
|
|
|
HASHREF => sub { |
83
|
|
|
|
|
|
|
my @keys = keys %$value; |
84
|
|
|
|
|
|
|
if ( scalar @keys != 1 ){ |
85
|
|
|
|
|
|
|
die "Isa operator doesn't support more then one key."; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
$as_name = shift @keys; |
88
|
|
|
|
|
|
|
my @values = values(%$value); |
89
|
|
|
|
|
|
|
return $self->_recurse_cond(shift( @values ), 0 ); |
90
|
|
|
|
|
|
|
}, |
91
|
|
|
|
|
|
|
}); |
92
|
|
|
|
|
|
|
$combining_count += $child_combining_count; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
$statment[ $#statment ] = $statment[$#statment] . " as " . $as_name; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
print STDERR "#OUT _cond_op_isa $operator $value $combining_count isa key: " . $self->{_isa_key} . "\n" if $TRACE > 9; |
97
|
|
|
|
|
|
|
return ( $combining_count, @statment ); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |
101
|
|
|
|
|
|
|
__END__ |
102
|
|
|
|
|
|
|
=head1 NAME |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Monitoring::Livestatus::Class::Abstract::Stats - Class to generate livestatus |
105
|
|
|
|
|
|
|
stats |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head2 SYNOPSIS |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 METHODS |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head2 apply |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
please view in L<Monitoring::Livestatus::Class::Base::Abstract> |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 INTERNAL METHODS |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=over 4 |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item build_mode |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=item build_compining_prefix |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=item build_operators |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=back |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 AUTHOR |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
See L<Monitoring::Livestatus::Class/AUTHOR> and L<Monitoring::Livestatus::Class/CONTRIBUTORS>. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Copyright 2009 Robert Bohne. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
138
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
139
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=cut |