-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
mytop
2408 lines (1855 loc) · 59.6 KB
/
mytop
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl -w
#
# $Id: mytop,v 1.91 2012/01/18 16:49:12 mgrennan Exp $
=pod
=head1 NAME
mytop - display MySQL server performance info like `top'
=cut
## most of the POD is at the bottom of the file
use 5.005;
use strict;
use DBI;
use Config::IniFiles;
use Getopt::Long;
use DBD::mysql;
use Socket;
$main::VERSION = "1.91";
$|=1;
$0 = 'mytop';
my $WIN = ($^O eq 'MSWin32') ? 1 : 0;
## Test for color support.
eval { require Term::ANSIColor; };
my $HAS_COLOR = $@ ? 0 : 1;
$HAS_COLOR = 0 if $WIN;
## Test of Time::HiRes support
eval { require Time::HiRes };
my $HAS_TIME = $@ ? 0 : 1;
my $debug = 0;
## Try to lower our priority (which, who, pri)
setpriority(0,0,10) unless $WIN;
## Prototypes
sub Clear();
sub GetData();
sub GetQPS();
sub FullQueryInfo($);
sub Explain($);
sub PrintTable(@);
sub PrintHelp();
sub Sum(@);
sub commify($);
sub make_short($);
sub Hashes($);
sub Execute($);
sub StringOrRegex($);
sub GetInnoDBStatus();
sub GetCmdSummary();
sub GetShowVariables();
sub GetShowStatus();
sub cmd_s;
sub cmd_S;
sub cmd_q;
sub FindProg($);
## Default Config Values
my %config = (
batchmode => 0,
color => 1,
db => '',
database => '',
delay => 5,
filter_user => qr/.?/,
filter_db => qr/.?/,
filter_host => qr/.?/,
filter_state => qr/.?/,
header => 1,
help => 0,
host => 'localhost',
idle => 1,
long => 120,
long_nums => 0,
mode => 'top',
prompt => 0,
pass => '',
password => '',
port => 3306,
resolve => 0,
slow => 10, # slow query time
socket => '',
sort => 1, # default or reverse sort ("s")
user => 'root'
);
my %qcache = (); ## The query cache--used for full query info support.
my %ucache = (); ## The user cache--used for full killing by user
my %dbcache = (); ## The db cache. This should be merged at some point.
my %statcache = (); ## The show status cache for GetShowStatus()
my (%STATUS, %OLD_STATUS); # header stuff.
my $CLEAR = $WIN ? '': `clear`;
## Term::ReadKey values
my $RM_RESET = 0;
my $RM_NOBLKRD = 3; ## using 4 traps Ctrl-C :-(
## Try ~/.my.cnf first
my $mycnf = "$ENV{HOME}/.my.cnf";
if (-e $mycnf)
{
my $cfgini = new Config::IniFiles( -file => $mycnf );
if ( not defined $cfgini )
{
foreach my $error (@Config::IniFiles::errors)
{
print $error;
print "\n";
}
exit;
}
my @sections = ('client', 'mytop');
foreach my $section (@sections) {
foreach my $param ($cfgini->Parameters ($section))
{
$config{$param} = $cfgini->val($section, $param) if exists $config{$param};
}
}
## map database/password onto db/pass (long version gets precedence in .my.cnf)
$config{'db'} = $config{'database'} if $config{'database'};
$config{'pass'} = $config{'password'} if $config{'password'};
}
## Read the user's config file, if it exists.
my $config = "$ENV{HOME}/.mytop";
if (-e $config)
{
if (open CFG, "<$config")
{
while (<CFG>)
{
next if /^\s*$/; ## skip blanks
next if /^\s*#/; ## skip comments
chomp;
if (/(\S+)\s*=\s*(.*\S)/)
{
$config{lc $1} = $2 if exists $config{lc $1};
}
}
close CFG;
}
## map database/password onto db/pass (short version gets precedence for historical reasons)
$config{'db'} = $config{'database'} unless $config{'db'};
$config{'pass'} = $config{'password'} unless $config{'pass'};
}
## Command-line args.
use vars qw($opt_foo);
Getopt::Long::Configure('no_ignore_case', 'bundling');
GetOptions(
"color!" => \$config{color},
"user|u=s" => \$config{user},
"pass|password|p=s" => \$config{pass},
"database|db|d=s" => \$config{db},
"host|h=s" => \$config{host},
"port|P=i" => \$config{port},
"socket|S=s" => \$config{socket},
"delay|s=i" => \$config{delay},
"batch|batchmode|b" => \$config{batchmode},
"header!" => \$config{header},
"idle|i!" => \$config{idle},
"resolve|r!" => \$config{resolve},
"prompt!" => \$config{prompt},
"long=i" => \$config{long},
"long_nums!" => \$config{long_nums},
"mode|m=s" => \$config{mode},
"slow=i" => \$config{slow},
"sort=s" => \$config{sort}
);
## User may have put the port with the host.
if ($config{host} =~ s/:(\d+)$//)
{
$config{port} = $1;
}
## Don't use Term::ReadKey unless running interactively.
if (not $config{batchmode})
{
require Term::ReadKey;
Term::ReadKey->import();
}
## User may want to disable color.
if ($HAS_COLOR and not $config{color})
{
$HAS_COLOR = 0;
}
if ($HAS_COLOR)
{
import Term::ANSIColor ':constants';
}
else
{
*RESET = sub { };
*YELLOW = sub { };
*RED = sub { };
*MAGENTA = sub { };
*GREEN = sub { };
*BLUE = sub { };
*WHITE = sub { };
*BOLD = sub { };
}
my $RESET = RESET() || '';
my $YELLOW = YELLOW() || '';
my $RED = RED() || '';
my $MAGENTA = MAGENTA() || '';
my $GREEN = GREEN() || '';
my $BLUE = BLUE() || '';
my $WHITE = WHITE() || '';
my $BOLD = BOLD() || '';
## Connect
my $dsn;
## Socket takes precedence.
$dsn ="DBI:mysql:database=$config{db};mysql_read_default_group=mytop;";
if ($config{socket} and -S $config{socket})
{
$dsn .= "mysql_socket=$config{socket}";
}
else
{
$dsn .= "host=$config{host};port=$config{port}";
}
if ($config{prompt})
{
print "Password: ";
ReadMode(2);
chomp($config{pass} = <STDIN>);
ReadMode(0);
print "\n";
}
my $dbh = DBI->connect($dsn, $config{user}, $config{pass},
{ PrintError => 0 });
if (not ref $dbh)
{
my $Error = <<EODIE
Cannot connect to MySQL server. Please check the:
* database you specified "$config{db}" (default is "")
* username you specified "$config{user}" (default is "root")
* password you specified "$config{pass}" (default is "")
* hostname you specified "$config{host}" (default is "localhost")
* port you specified "$config{port}" (default is 3306)
* socket you specified "$config{socket}" (default is "")
The options my be specified on the command-line or in a ~/.mytop or
~/.my.cnf config file. See the manual (perldoc mytop) for details.
Here's the exact error from DBI. It might help you debug:
$DBI::errstr
EODIE
;
die $Error;
}
ReadMode($RM_RESET) unless $config{batchmode};
## Get static data
my $db_version;
my $db_release;
my $have_query_cache;
my @variables = Hashes("show variables");
foreach (@variables)
{
if ($_->{Variable_name} eq "version")
{
if($_->{Value} =~ m/-/)
{
my @tmp_db_version = split(/-/,$_->{Value});
$_->{Value} = $tmp_db_version[0];
}
$db_version = $_->{Value};
$db_release = int(substr($db_version, 0, 1));
next;
}
if ($_->{Variable_name} eq "have_query_cache")
{
# if ($_->{Value} eq 'YES')
if ($_->{Value} eq 'YES' or $_->{Value} eq 'DEMAND') # http://freshmeat.net/users/jerjones
{
$have_query_cache = 1;
}
else
{
$have_query_cache = 0;
}
next;
}
}
#########################################################################
##
## The main loop
##
#########################################################################
ReadMode($RM_NOBLKRD) unless $config{batchmode};
while (1)
{
my $key;
if ($config{mode} eq 'qps')
{
GetQPS();
$key = ReadKey(1);
next unless $key;
if ($key =~ /t/i)
{
$config{mode} = 'top';
}
if ($key =~ /q/)
{
cmd_q();
}
next;
}
if ($config{mode} eq 'top')
{
GetData();
last if $config{batchmode};
$key = ReadKey($config{delay});
next unless $key;
}
elsif ($config{mode} eq 'cmd')
{
GetCmdSummary();
last if $config{batchmode};
$key = ReadKey($config{delay});
next unless $key;
}
elsif ($config{mode} eq 'innodb')
{
GetInnoDBStatus();
last if $config{batchmode};
$key = ReadKey($config{delay});
next unless $key;
}
elsif ($config{mode} eq 'status')
{
GetShowStatus();
last if $config{batchmode};
$key = ReadKey($config{delay});
next unless $key;
}
##
## keystroke command processing (if we get this far)
##
if ($key eq '!')
{
Execute("stop slave");
Execute("set global sql_slave_skip_counter=1");
Execute("start slave");
}
# t - top
if ($key =~ /t/i)
{
$config{mode} = 'top';
}
## q - quit
if ($key eq 'q')
{
cmd_q();
}
if ($key eq 'D')
{
require Data::Dumper;
print Data::Dumper::Dumper([\%config]);
ReadKey(0);
}
## l - change long running hightling
if ($key eq 'l')
{
cmd_l();
next;
}
## m - mode swtich to qps
if ($key eq 'm')
{
$config{mode} = 'qps';
Clear() unless $config{batchmode};
print "Queries Per Second\n";
next;
}
## c - mode swtich to command summary
if ($key eq 'c')
{
$config{mode} = 'cmd';
Clear() unless $config{batchmode};
print "Command Summary\n";
next;
}
## C - change Color on and off
if ($key eq 'C')
{
if ( $HAS_COLOR )
{
$HAS_COLOR = 0;
}
else
{
$HAS_COLOR = 1;
}
}
## s - seconds of delay
if ($key eq 's')
{
cmd_s();
next;
}
if ($key eq 'S')
{
cmd_S();
next;
}
## R - resolve hostnames
if ($key eq 'R')
{
if ($config{resolve})
{
$config{resolve} = 0;
}
else
{
$config{resolve} = 1;
}
}
## t - username based filter
if ($key eq 't')
{
ReadMode($RM_RESET);
print RED(), "Which state (blank for all, /.../ for regex): ", RESET();
$config{filter_state} = StringOrRegex(ReadLine(0));
ReadMode($RM_NOBLKRD);
next;
}
## u - username based filter
if ($key eq 'u')
{
ReadMode($RM_RESET);
print RED(), "Which user (blank for all, /.../ for regex): ", RESET();
$config{filter_user} = StringOrRegex(ReadLine(0));
ReadMode($RM_NOBLKRD);
next;
}
## d - database name based filter
if ($key eq 'd')
{
ReadMode($RM_RESET);
print RED(), "Which database (blank for all, /.../ for regex): ",
RESET();
$config{filter_db} = StringOrRegex(ReadLine(0));
ReadMode($RM_NOBLKRD);
next;
}
## h - hostname based filter
if ($key eq 'h')
{
ReadMode($RM_RESET);
print RED(), "Which hostname (blank for all, /.../ for regex): ",
RESET();
$config{filter_host} = StringOrRegex(ReadLine(0));
ReadMode($RM_NOBLKRD);
next;
}
## E - Show full Replication Error
if ($key eq 'E')
{
my($data) = Hashes('SHOW SLAVE STATUS');
Clear();
print "Error is: $data->{Last_Error}\n";
print RED(), "-- paused. press any key to resume --", RESET();
ReadKey(0);
next;
}
## F - remove all filters
if ($key eq 'F')
{
$config{filter_host} = qr/.?/;
$config{filter_db} = qr/.?/;
$config{filter_user} = qr/.?/;
$config{filter_state} = qr/.?/;
print RED(), "-- display unfiltered --", RESET();
sleep 1;
next;
}
## p - pause
if ($key eq 'p')
{
print RED(), "-- paused. press any key to resume --", RESET();
ReadKey(0);
next;
}
## i - idle toggle
if ($key =~ /i/)
{
if ($config{idle})
{
$config{idle} = 0;
$config{sort} = 1;
print RED(), "-- idle (sleeping) processed filtered --", RESET();
sleep 1;
}
else
{
$config{idle} = 1;
$config{sort} = 0;
print RED(), "-- idle (sleeping) processed unfiltered --", RESET();
sleep 1;
}
}
## I - InnoDB status
if ($key =~ 'I')
{
$config{mode} = 'innodb';
Clear() unless $config{batchmode};
print "InnoDB Status\n";
next;
}
## o - sort order
if ($key =~ /o/)
{
if ($config{sort})
{
$config{sort} = 0;
print RED(), "-- sort order reversed --", RESET();
sleep 1;
}
else
{
$config{sort} = 1;
print RED(), "-- sort order reversed --", RESET();
sleep 1;
}
}
## ? - help
if ($key eq '?')
{
Clear();
PrintHelp();
ReadKey(0);
next;
}
## k - kill
if ($key eq 'k')
{
ReadMode($RM_RESET);
print RED(), "Thread id to kill: ", RESET();
my $id = ReadLine(0);
$id =~ s/\s//g;
if ($id =~ /^\d+$/)
{
Execute("KILL $id");
}
else
{
print RED(), "-- invalid thread id --", RESET();
sleep 1;
}
ReadMode($RM_NOBLKRD);
next;
}
## K - kill based on a username
if ($key =~ /K/)
{
ReadMode($RM_RESET);
print RED(), "User to kill: ", RESET();
my $user = ReadLine(0);
$user =~ s/\s//g;
if ($user =~ /^\S+$/)
{
for my $pid (keys %ucache)
{
next unless $ucache{$pid} eq $user;
Execute("KILL $pid");
select(undef, undef, undef, 0.2);
}
}
else
{
print RED(), "-- invalid thread id --", RESET();
sleep 1;
}
ReadMode($RM_NOBLKRD);
}
## f - full info
if ($key =~ /f/)
{
ReadMode($RM_RESET);
print RED(), "Full query for which thread id: ", RESET();
my $id = ReadLine(0);
chomp $id;
FullQueryInfo($id);
ReadMode($RM_NOBLKRD);
print RED(), "-- paused. press any key to resume or (e) to explain --",
RESET();
my $key = ReadKey(0);
if ($key eq 'e')
{
Explain($id);
print RED(), "-- paused. press any key to resume --", RESET();
ReadKey(0);
}
next;
}
## e - explain
if ($key =~ /e/)
{
ReadMode($RM_RESET);
print RED(), "Explain which query (id): ", RESET();
my $id = ReadLine(0);
chomp $id;
Explain($id);
ReadMode($RM_NOBLKRD);
print RED(), "-- paused. press any key to resume --", RESET();
ReadKey(0);
next;
}
## r - reset status counters
if ($key =~ /r/)
{
Execute("FLUSH STATUS");
print RED(), "-- counters reset --", RESET();
sleep 1;
next;
}
## H - header toggle
if ($key eq 'H')
{
if ($config{header})
{
$config{header} = 0;
}
else
{
$config{header}++;
}
}
## # - magic debug key
if ($key eq '#')
{
$debug = 1;
}
if ($key eq 'V')
{
GetShowVariables();
print RED(), "-- paused. press any key to resume --", RESET();
ReadKey(0);
}
if ($key eq 'S')
{
$config{mode} = 'status';
}
}
ReadMode($RM_RESET) unless $config{batchmode};
exit;
#######################################################################
sub Clear()
{
if (not $WIN)
{
print "$CLEAR"
}
else
{
print "\n" x 90; ## dumb hack for now. Anyone know how to
## clear the screen in dos window on a Win32
## system??
}
}
my $last_time;
sub GetData()
{
## Get terminal info
my $now_time;
%qcache = (); ## recycle memory
%dbcache = ();
my ($width, $height, $wpx, $hpx, $lines_left);
if (not $config{batchmode})
{
($width, $height, $wpx, $hpx) = GetTerminalSize();
$lines_left = $height - 2;
}
else
{
$height = 999_999; ## I hope you don't have more than that!
$lines_left = 999_999;
$width = 80;
}
##
## Header stuff.
##
if ($config{header})
{
my @recs = "";
if ( $db_release > 4 )
{
@recs = Hashes("show global status");
}
else
{
@recs = Hashes("show status");
}
## if the server died or we lost connectivity
if (not @recs)
{
ReadMode($RM_RESET);
exit 1;
}
## get high-res or low-res time
my ($t_delta);
if ($HAS_TIME)
{
$now_time = Time::HiRes::gettimeofday();
}
else
{
$now_time = time;
}
if ($last_time and $last_time != $now_time)
{
$t_delta = $now_time - $last_time;
}
%OLD_STATUS = %STATUS;
foreach my $ref (@recs)
{
my $key = $ref->{Variable_name};
my $val = $ref->{Value};
$STATUS{$key} = $val;
}
## Compute Key Cache Hit Stats
$STATUS{Key_read_requests} ||= 1; ## can't divide by zero next
my $cache_hits_percent = (100-($STATUS{Key_reads}/$STATUS{Key_read_requests}) * 100);
$cache_hits_percent = sprintf("%2.2f",$cache_hits_percent);
## Query Cache info for <= Ver. 4.1
##
## mysql> show status like 'qcache%';
## +-------------------------+----------+
## | Variable_name | Value |
## +-------------------------+----------+
## | Qcache_queries_in_cache | 81 |
## | Qcache_inserts | 4961668 |
## | Qcache_hits | 1374170 |
## | Qcache_not_cached | 5656249 |
## | Qcache_free_memory | 33164800 |
## | Qcache_free_blocks | 2 |
## | Qcache_total_blocks | 168 |
## +-------------------------+----------+
##
## Query Cache info for => Ver. 5.0
##
## mysql> show status like 'qcache%';
## +-------------------------+------------+
## | Variable_name | Value |
## +-------------------------+------------+
## | Qcache_free_blocks | 37652 |
## | Qcache_free_memory | 110289712 |
## | Qcache_hits | 1460617356 |
## | Qcache_inserts | 390563495 |
## | Qcache_lowmem_prunes | 6414172 |
## | Qcache_not_cached | 93002420 |
## | Qcache_queries_in_cache | 66558 |
## | Qcache_total_blocks | 192031 |
## +-------------------------+------------+
my $query_cache_hits = 0;
my $query_cache_hits_per_sec = 0;
my $now_query_cache_hits_per_sec = 0;
if ($have_query_cache)
{
$query_cache_hits = $STATUS{Qcache_hits};
$query_cache_hits_per_sec = $STATUS{Qcache_hits} / $STATUS{Uptime};
if (defined $last_time and $last_time != $now_time)
{
my $q_delta = $STATUS{Qcache_hits} - $OLD_STATUS{Qcache_hits};
$now_query_cache_hits_per_sec = sprintf "%.2f", $q_delta / $t_delta;
}
}
open L, "</proc/loadavg";
my $l = <L>;
close L;
chomp $l;
$last_time = $now_time;
## Server Uptime in meaningful terms...
my $time = $STATUS{Uptime};
my ($d,$h,$m,$s) = (0, 0, 0, 0);
$d += int($time / (60*60*24)); $time -= $d * (60*60*24);
$h += int($time / (60*60)); $time -= $h * (60*60);
$m += int($time / (60)); $time -= $m * (60);
$s += int($time);
my $uptime = sprintf("%d+%02d:%02d:%02d", $d, $h, $m, $s);
## Queries per second...
my $avg_queries_per_sec = sprintf("%.2f", $STATUS{Questions} / $STATUS{Uptime});
my $num_queries = $STATUS{Questions};
my @t = localtime(time);
my $current_time = sprintf "[%02d:%02d:%02d]", $t[2], $t[1], $t[0];
my $host_width = 80;
my $up_width = $width - $host_width;
Clear() unless $config{batchmode};
print RESET();
printf "%-${host_width}s%${up_width}s\n",
"MySQL on $config{host} ($db_version)",
"load $l up $uptime $current_time";
$lines_left--;
printf " Queries: %-7s 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
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};
$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");
printf(" Sorts: %6.0f 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{Sort_rows} - $OLD_STATUS{Sort_rows} ) / $t_delta,
( $STATUS{Questions} - $OLD_STATUS{Questions} ) / $t_delta,
( # slow now (qps)
($STATUS{Slow_queries} ) ?
( $STATUS{Slow_queries} - $OLD_STATUS{Slow_queries} ) / $t_delta :
0
),
$STATUS{Threads_connected},
$STATUS{Threads_running},
$STATUS{Threads_cached},
(100 * ($STATUS{Com_select} - $OLD_STATUS{Com_select} +
($STATUS{Qcache_hits}||0) - ($OLD_STATUS{Qcache_hits}||0)
) ) / ($q_diff ),
(100 * ($STATUS{Com_insert} - $OLD_STATUS{Com_insert} +
$STATUS{Com_replace} - $OLD_STATUS{Com_replace}
) ) / ($q_diff ),
(100 * ($STATUS{Com_update} - $OLD_STATUS{Com_update}) ) / ($q_diff ),
(100 * ($STATUS{Com_delete} - $OLD_STATUS{Com_delete}) ) / ($q_diff ),
);
}