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