line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::RedisTop::PerformStat; |
2
|
1
|
|
|
1
|
|
1248
|
use Term::ANSIColor qw/colored/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
67
|
|
3
|
1
|
|
|
1
|
|
5
|
use List::Util qw/max/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
63
|
|
4
|
1
|
|
|
1
|
|
6
|
use App::RedisTop::Redis; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
1433
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
my $version = eval { |
7
|
|
|
|
|
|
|
require App::RedisTop; |
8
|
|
|
|
|
|
|
$App::RedisTop::VERSION; |
9
|
|
|
|
|
|
|
}; |
10
|
|
|
|
|
|
|
if($@) { $version = '?' } |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
14
|
|
|
|
|
|
|
|
15
|
0
|
|
|
|
|
|
chomp(my $rows = qx{tput lines}); |
16
|
0
|
|
0
|
|
|
|
$rows ||= 24; |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
my $self = bless { |
19
|
|
|
|
|
|
|
groups => [], |
20
|
|
|
|
|
|
|
instances => [], |
21
|
|
|
|
|
|
|
width => 20, |
22
|
|
|
|
|
|
|
summary => {}, |
23
|
|
|
|
|
|
|
prev_stats => {}, |
24
|
|
|
|
|
|
|
displayed => 0, |
25
|
|
|
|
|
|
|
rows => $rows, |
26
|
|
|
|
|
|
|
@_, |
27
|
|
|
|
|
|
|
}, $class; |
28
|
0
|
|
|
|
|
|
my $max_len = max (map { length($_) } @{$self->{instances}}); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
$self->{width} = $max_len; |
30
|
0
|
|
|
|
|
|
$self; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
0
|
0
|
|
sub separator { colored("|", "blue") } |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub build_title { |
36
|
0
|
|
|
0
|
0
|
|
return (); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub build_header { |
40
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
41
|
0
|
|
|
|
|
|
my $out_str = sprintf("%s ", ' ' x $self->{width}); |
42
|
0
|
|
|
|
|
|
for my $group (@{$self->{groups}}) { |
|
0
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
$out_str .= $group->header; |
44
|
|
|
|
|
|
|
} |
45
|
0
|
|
|
|
|
|
return ("$out_str\n"); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub build_sub_header { |
49
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
50
|
0
|
|
|
|
|
|
my $format = "%" . $self->{width} . "s%s"; |
51
|
0
|
|
|
|
|
|
my $out_str = colored(sprintf($format, 'INSTANCE', $self->separator), "bold"); |
52
|
0
|
|
|
|
|
|
for my $group (@{$self->{groups}}) { |
|
0
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
$out_str .= $group->sub_header; |
54
|
|
|
|
|
|
|
} |
55
|
0
|
|
|
|
|
|
return ("$out_str\n"); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub build_line { |
59
|
0
|
|
|
0
|
0
|
|
my ($self, $spt) = @_; |
60
|
0
|
|
|
|
|
|
my $out_str = colored(sprintf("%s ", $spt x $self->{width}), "blue"); |
61
|
0
|
|
|
|
|
|
for my $group (@{$self->{groups}}) { |
|
0
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
$out_str .= $group->line($spt); |
63
|
|
|
|
|
|
|
} |
64
|
0
|
|
|
|
|
|
return ("$out_str\n"); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub build_body { |
68
|
0
|
|
|
0
|
0
|
|
my ($self, $instance, $stats, $prev_stats, $redis_config) = @_; |
69
|
0
|
|
|
|
|
|
my $format = "%" . $self->{width} . "s%s"; |
70
|
0
|
|
|
|
|
|
my $out_str = sprintf($format, $instance, $self->separator); |
71
|
0
|
|
|
|
|
|
for my $group (@{$self->{groups}}) { |
|
0
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
$group->redis_config($redis_config); |
73
|
0
|
|
|
|
|
|
$out_str .= $group->body($stats, $prev_stats); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# stash total count |
76
|
0
|
|
|
|
|
|
my @values = $group->stat_values($stats, $prev_stats); |
77
|
0
|
|
|
|
|
|
my $key = $group->{group}; |
78
|
0
|
|
0
|
|
|
|
my $total_values = $self->{summary}->{$key} || []; |
79
|
0
|
|
|
|
|
|
for (my $i = 0; $i < scalar @values; $i++){ |
80
|
0
|
|
0
|
|
|
|
$total_values->[$i] ||= 0; |
81
|
0
|
|
|
|
|
|
$total_values->[$i] += $values[$i]; |
82
|
|
|
|
|
|
|
} |
83
|
0
|
|
|
|
|
|
$self->{summary}->{$key} = $total_values; |
84
|
|
|
|
|
|
|
} |
85
|
0
|
|
|
|
|
|
return ("$out_str\n"); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub build_average { |
89
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
90
|
0
|
|
|
|
|
|
my $instance_count = scalar @{$self->{instances}}; |
|
0
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
my $format = "%" . $self->{width} . "s%s"; |
93
|
0
|
|
|
|
|
|
my $out_str = colored(sprintf($format, 'AVERAGE', $self->separator), "bold"); |
94
|
0
|
|
|
|
|
|
for my $group (@{$self->{groups}}) { |
|
0
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
my $key = $group->{group}; |
96
|
0
|
|
|
|
|
|
$out_str .= $group->average($self->{summary}->{$key}, $instance_count); |
97
|
|
|
|
|
|
|
} |
98
|
0
|
|
|
|
|
|
return ("$out_str\n"); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub build_total { |
102
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
103
|
0
|
|
|
|
|
|
my $format = "%" . $self->{width} . "s%s"; |
104
|
0
|
|
|
|
|
|
my $out_str = colored(sprintf($format, 'TOTAL', $self->separator), "bold"); |
105
|
0
|
|
|
|
|
|
for my $group (@{$self->{groups}}) { |
|
0
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
my $key = $group->{group}; |
107
|
0
|
|
|
|
|
|
$out_str .= $group->total($self->{summary}->{$key}); |
108
|
|
|
|
|
|
|
} |
109
|
0
|
|
|
|
|
|
return ("$out_str\n"); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub run { |
113
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# init total |
116
|
0
|
|
|
|
|
|
$self->{summary} = {}; |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
my @lines; |
119
|
0
|
0
|
|
|
|
|
if ($self->{displayed} == 0) { |
120
|
|
|
|
|
|
|
# build header |
121
|
0
|
|
|
|
|
|
push @lines, $self->build_title; |
122
|
0
|
|
|
|
|
|
push @lines, $self->build_header; |
123
|
0
|
|
|
|
|
|
push @lines, $self->build_sub_header; |
124
|
0
|
|
|
|
|
|
push @lines, $self->build_line('-'); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
# instances loop |
128
|
0
|
|
|
|
|
|
foreach my $instance (@{$self->{instances}}) { |
|
0
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
my ($host, $port) = split(/:/, $instance); |
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
my $redis = App::RedisTop::Redis->new(host => $host, port => $port); |
132
|
0
|
|
|
|
|
|
my $config = $redis->config(); |
133
|
0
|
|
|
|
|
|
my $stats = $redis->info(); |
134
|
0
|
|
|
|
|
|
my $slowlog = $redis->slowlog(); |
135
|
|
|
|
|
|
|
# add slowlog len into stats |
136
|
0
|
|
|
|
|
|
$stats->{slowlog_len} = $slowlog; |
137
|
|
|
|
|
|
|
|
138
|
0
|
|
0
|
|
|
|
push @lines, $self->build_body( |
139
|
|
|
|
|
|
|
$instance, |
140
|
|
|
|
|
|
|
$stats, |
141
|
|
|
|
|
|
|
$self->{prev_stats}->{$instance} || {}, |
142
|
|
|
|
|
|
|
$config, |
143
|
|
|
|
|
|
|
); |
144
|
0
|
|
|
|
|
|
$self->{prev_stats}->{$instance} = $stats; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
0
|
0
|
|
|
|
|
if ($self->{displayed} == 0) { |
148
|
|
|
|
|
|
|
# average |
149
|
0
|
|
|
|
|
|
push @lines, $self->build_average(); |
150
|
|
|
|
|
|
|
# total |
151
|
0
|
|
|
|
|
|
push @lines, $self->build_total(); |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
0
|
|
|
|
|
|
print join('', @lines); |
155
|
0
|
|
|
|
|
|
$self->{displayed} += scalar(@lines); |
156
|
0
|
0
|
|
|
|
|
if ($self->{displayed} >= $self->{rows}) { |
157
|
0
|
|
|
|
|
|
$self->{displayed} = 0; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
1; |