1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
--- mytop.orig 2007-02-17 12:57:46.000000000 +0800
+++ mytop 2012-05-18 13:58:30.000000000 +0800
@@ -153,7 +153,7 @@
"idle|i" => \$config{idle},
"resolve|r" => \$config{resolve},
"prompt!" => \$config{prompt},
- "long|!" => \$config{long_nums},
+ "long!" => \$config{long_nums},
"mode|m=s" => \$config{mode},
"sort=s" => \$config{sort},
);
@@ -193,6 +193,7 @@
*BLUE = sub { };
*WHITE = sub { };
*BOLD = sub { };
+ *MAGENTA = sub { };
}
my $RESET = RESET() || '';
@@ -202,6 +203,7 @@
my $BLUE = BLUE() || '';
my $WHITE = WHITE() || '';
my $BOLD = BOLD() || '';
+my $MAGENTA= MAGENTA() || '';
## Connect
@@ -369,6 +371,10 @@
require Data::Dumper;
print Data::Dumper::Dumper([\%config]);
ReadKey(0);
+
+ if (-M $0) { # restart application, if it was modified - for debugging
+ exec('perl', $0, @ARGV);
+ }
}
## m - mode swtich to qps
@@ -377,7 +383,7 @@
{
$config{mode} = 'qps';
Clear() unless $config{batchmode};
- print "Queries Per Second [hit q to exit this mode]\n";
+ print "Queries Per Second [hit q to exit, hit t for top mode]\n";
next;
}
@@ -710,7 +716,7 @@
##
if ($config{header})
{
- my @recs = Hashes("show status");
+ my @recs = Hashes("SHOW /*!50002 GLOBAL */ STATUS");
## if the server died or we lost connectivity
if (not @recs)
@@ -800,8 +806,15 @@
## Queries per second...
- my $avg_queries_per_sec = sprintf("%.2f", $STATUS{Questions} / $STATUS{Uptime});
- my $num_queries = $STATUS{Questions};
+ my ($num_queries, $old_num_queries);
+ if(defined($STATUS{Queries})) {
+ $num_queries = $STATUS{Queries};
+ $old_num_queries = $OLD_STATUS{Queries};
+ } else {
+ $num_queries = $STATUS{Questions};
+ $old_num_queries = $OLD_STATUS{Questions};
+ }
+ my $avg_queries_per_sec = sprintf("%.2f", $num_queries / $STATUS{Uptime});
my @t = localtime(time);
@@ -819,26 +832,26 @@
$lines_left--;
- printf " Queries: %-5s qps: %4.0f Slow: %7s Se/In/Up/De(%%): %02.0f/%02.0f/%02.0f/%02.0f \n",
- make_short( $STATUS{Questions} ), # q total
- $STATUS{Questions} / $STATUS{Uptime}, # qps, average
+ printf " Queries: %-6s qps: %4.0f Slow: %7s Se/In/Up/De(%%): %02.0f/%02.0f/%02.0f/%02.0f \n",
+ make_short( $num_queries ), # q total
+ $num_queries / $STATUS{Uptime}, # qps, average
make_short( $STATUS{Slow_queries} ), # slow
# hmm. a Qcache hit is really a select and should be counted.
- 100 * ($STATUS{Com_select} + ($STATUS{Qcache_hits}||0) ) / $STATUS{Questions},
- 100 * ($STATUS{Com_insert} + $STATUS{Com_replace} ) / $STATUS{Questions},
- 100 * ($STATUS{Com_update} ) / $STATUS{Questions},
- 100 * $STATUS{Com_delete} / $STATUS{Questions};
+ 100 * ($STATUS{Com_select} + ($STATUS{Qcache_hits}||0) ) / $num_queries,
+ 100 * ($STATUS{Com_insert} + $STATUS{Com_replace} ) / $num_queries,
+ 100 * ($STATUS{Com_update} ) / $num_queries,
+ 100 * $STATUS{Com_delete} / $num_queries;
$lines_left--;
if ($t_delta)
{
- my $q_diff = ( $STATUS{Questions} - $OLD_STATUS{Questions} );
-# print("q_diff: $STATUS{Questions} - $OLD_STATUS{Questions} / $t_delta = $q_diff\n");
+ my $q_diff = ( $num_queries - $old_num_queries );
+# print("q_diff: $num_queries - $old_num_queries / $t_delta = $q_diff\n");
printf(" qps now: %4.0f Slow qps: %3.1f Threads: %4.0f (%4.0f/%4.0f) %02.0f/%02.0f/%02.0f/%02.0f \n",
- ( $STATUS{Questions} - $OLD_STATUS{Questions} ) / $t_delta,
+ ( $num_queries - $old_num_queries ) / $t_delta,
( # slow now (qps)
($STATUS{Slow_queries} ) ?
( $STATUS{Slow_queries} - $OLD_STATUS{Slow_queries} ) / $t_delta :
@@ -889,8 +902,42 @@
make_short(($STATUS{Bytes_received} - $OLD_STATUS{Bytes_received}) / $t_delta ),
make_short(($STATUS{Bytes_sent} - $OLD_STATUS{Bytes_sent}) / $t_delta ))
if ($t_delta);
- print "\n\n";
+ print "\n";
+
+ my @master_status = Hashes("show master status");
+ if (@master_status)
+ {
+ foreach my $m (@master_status) {
+ print " Master: $m->{File}/$m->{Position} ",
+ "do: ", GREEN(), "$m->{Binlog_Do_DB} ", RESET(),
+ "ign: ", MAGENTA(), $m->{Binlog_Ignore_DB}, RESET(), "\n";
+ #$line_prefix = ' ' x length($line_prefix);
+ $lines_left--;
+ }
+ }
+
+ my @slave_status = Hashes("show slave status");
+ if (@slave_status)
+ {
+ my $line_prefix = " Slave: ";
+ foreach my $s (@slave_status) {
+ print $line_prefix, BOLD(),
+ ($s->{Slave_IO_Running} eq 'Yes'
+ && $s->{Slave_SQL_Running} eq 'Yes'
+ && $s->{Last_Errno} == 0
+ ? ($s->{Seconds_Behind_Master} > 60 ? BOLD('WARN') : GREEN('OK ')) : RED('ERR ')
+ ), RESET(),
+ " Delay: ",
+ defined($s->{Seconds_Behind_Master}) ? sprintf('%03d:%02d', int($s->{Seconds_Behind_Master} / 60), $s->{Seconds_Behind_Master} % 60) : '---:--',
+ " $s->{Master_User}\@$s->{Master_Host}: ",
+ "$s->{Master_Log_File}/$s->{Read_Master_Log_Pos} ",
+ "\n";
+ #$line_prefix = ' ' x length($line_prefix);
+ $lines_left--;
+ }
+ }
+ print "\n";
$lines_left--;
}
@@ -952,8 +999,11 @@
{
$thread->{Host} =~ s/:\d+$//;
my $host = gethostbyaddr(inet_aton($thread->{Host}), AF_INET);
- $host =~ s/^([^.]+).*/$1/;
- $thread->{Host} = $host;
+ if ($host)
+ {
+ $host =~ s/^([^.]+).*/$1/;
+ $thread->{Host} = $host;
+ }
}
## Fix possible undefs
@@ -1099,8 +1149,8 @@
my @data = Hashes("SHOW INNODB STATUS");
open P, "|$config{pager}" or die "$!";
- print keys %{$data[0]};
- print $data[0]->{Status},"\n";
+ print P keys %{$data[0]};
+ print P $data[0]->{Status},"\n";
close P;
}
|