forked from phpmyadmin/phpmyadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver_status.php
1498 lines (1325 loc) · 65.7 KB
/
server_status.php
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
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* displays status variables with descriptions and some hints an optmizing
* + reset status variables
*
* @package phpMyAdmin
*/
/**
* no need for variables importing
* @ignore
*/
if (! defined('PMA_NO_VARIABLES_IMPORT')) {
define('PMA_NO_VARIABLES_IMPORT', true);
}
if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true)
$GLOBALS['is_header_sent'] = true;
require_once './libraries/common.inc.php';
/**
* Function to output refresh rate selection.
*/
function PMA_choose_refresh_rate() {
echo '<option value="5">' . __('Refresh rate') . '</option>';
foreach (array(1, 2, 5, 20, 40, 60, 120, 300, 600) as $rate) {
if ($rate % 60 == 0) {
$minrate = $rate / 60;
echo '<option value="' . $rate . '">' . sprintf(_ngettext('%d minute', '%d minutes', $minrate), $minrate) . '</option>';
} else {
echo '<option value="' . $rate . '">' . sprintf(_ngettext('%d second', '%d seconds', $rate), $rate) . '</option>';
}
}
}
/**
* Ajax request
*/
if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) {
// Send with correct charset
header('Content-Type: text/html; charset=UTF-8');
if (isset($_REQUEST['logging_vars'])) {
if (isset($_REQUEST['varName']) && isset($_REQUEST['varValue'])) {
$value = PMA_sqlAddslashes($_REQUEST['varValue']);
if (!is_numeric($value)) $value="'".$value."'";
if (!preg_match("/[^a-zA-Z0-9_]+/",$_REQUEST['varName']))
PMA_DBI_query('SET GLOBAL ' . $_REQUEST['varName'] . ' = '.$value);
}
$loggingVars = PMA_DBI_fetch_result(
"SHOW GLOBAL VARIABLES WHERE Variable_name IN (
'general_log', 'slow_query_log', 'long_query_time', 'log_output')", 0, 1);
exit(json_encode($loggingVars));
}
// real-time charting data
if (isset($_REQUEST['chart_data'])) {
switch($_REQUEST['type']) {
case 'proc':
$c = PMA_DBI_fetch_result("SHOW GLOBAL STATUS WHERE Variable_name = 'Connections'", 0, 1);
$result = PMA_DBI_query('SHOW PROCESSLIST');
$num_procs = PMA_DBI_num_rows($result);
$ret = array(
'x' => microtime(true)*1000,
'y_proc' => $num_procs,
'y_conn' => $c['Connections']
);
exit(json_encode($ret));
case 'queries':
$queries = PMA_DBI_fetch_result(
"SHOW GLOBAL STATUS
WHERE (Variable_name LIKE 'Com_%' OR Variable_name = 'Questions')
AND Value > 0'", 0, 1);
cleanDeprecated($queries);
// admin commands are not queries
unset($queries['Com_admin_commands']);
$questions = $queries['Questions'];
unset($queries['Questions']);
//$sum=array_sum($queries);
$ret = array(
'x' => microtime(true)*1000,
'y' => $questions,
'pointInfo' => $queries
);
exit(json_encode($ret));
case 'traffic':
$traffic = PMA_DBI_fetch_result(
"SHOW GLOBAL STATUS
WHERE Variable_name = 'Bytes_received'
OR Variable_name = 'Bytes_sent'", 0, 1);
$ret = array(
'x' => microtime(true)*1000,
'y_sent' => $traffic['Bytes_sent'],
'y_received' => $traffic['Bytes_received']
);
exit(json_encode($ret));
case 'chartgrid':
$ret = json_decode($_REQUEST['requiredData'], true);
$statusVars = array();
$sysinfo = $cpuload = $memory = 0;
foreach ($ret as $chart_id => $chartNodes) {
foreach ($chartNodes as $node_id => $node) {
switch ($node['dataType']) {
case 'statusvar':
// Some white list filtering
if (!preg_match('/[^a-zA-Z_]+/',$node['name']))
$statusVars[] = $node['name'];
break;
case 'proc':
$result = PMA_DBI_query('SHOW PROCESSLIST');
$ret[$chart_id][$node_id]['y'] = PMA_DBI_num_rows($result);
break;
case 'cpu':
if (!$sysinfo) {
require_once('libraries/sysinfo.lib.php');
$sysinfo = getSysInfo();
}
if (!$cpuload)
$cpuload = $sysinfo->loadavg();
if (PHP_OS == 'Linux') {
$ret[$chart_id][$node_id]['idle'] = $cpuload['idle'];
$ret[$chart_id][$node_id]['busy'] = $cpuload['busy'];
} else
$ret[$chart_id][$node_id]['y'] = $cpuload['loadavg'];
break;
case 'memory':
if (!$sysinfo) {
require_once('libraries/sysinfo.lib.php');
$sysinfo = getSysInfo();
}
if (!$memory)
$memory = $sysinfo->memory();
$ret[$chart_id][$node_id]['y'] = $memory[$node['name']];
break;
}
}
}
$vars = PMA_DBI_fetch_result(
"SHOW GLOBAL STATUS
WHERE Variable_name='" . implode("' OR Variable_name='", $statusVars) . "'", 0, 1);
foreach ($ret as $chart_id => $chartNodes) {
foreach ($chartNodes as $node_id => $node) {
if ($node['dataType'] == 'statusvar')
$ret[$chart_id][$node_id]['y'] = $vars[$node['name']];
}
}
$ret['x'] = microtime(true)*1000;
exit(json_encode($ret));
}
}
if (isset($_REQUEST['log_data'])) {
$start = intval($_REQUEST['time_start']);
$end = intval($_REQUEST['time_end']);
if ($_REQUEST['type'] == 'slow') {
$q = 'SELECT SUM(query_time) AS TIME(query_time), SUM(lock_time) as lock_time, '.
'SUM(rows_sent) AS rows_sent, SUM(rows_examined) AS rows_examined, sql_text, COUNT(sql_text) AS \'#\' '.
'FROM `mysql`.`slow_log` WHERE event_time > FROM_UNIXTIME('.$start.') '.
'AND event_time < FROM_UNIXTIME('.$end.') GROUP BY sql_text';
$result = PMA_DBI_try_query($q);
$return = array('rows' => array(), 'sum' => array());
$type = '';
while ($row = PMA_DBI_fetch_assoc($result)) {
$type = substr($row['sql_text'],0,strpos($row['sql_text'],' '));
$return['sum'][$type]++;
$return['rows'][] = $row;
}
$return['sum']['TOTAL'] = array_sum($return['sum']);
PMA_DBI_free_result($result);
exit(json_encode($return));
}
if ($_REQUEST['type'] == 'general') {
$q = 'SELECT TIME(event_time) as event_time, user_host, thread_id, server_id, argument, count(argument) as \'#\' FROM `mysql`.`general_log` WHERE command_type=\'Query\' '.
'AND event_time > FROM_UNIXTIME('.$start.') AND event_time < FROM_UNIXTIME('.$end.') '.
'AND argument REGEXP \'^(INSERT|SELECT|UPDATE|DELETE)\' GROUP by argument'; // HAVING count > 1';
$result = PMA_DBI_try_query($q);
$return = array('rows' => array(), 'sum' => array());
$type = '';
$insertTables = array();
$insertTablesFirst = -1;
$i = 0;
while ($row = PMA_DBI_fetch_assoc($result)) {
preg_match('/^(\w+)\s/',$row['argument'],$match);
$type = strtolower($match[1]);
// Ignore undefined index warning, just increase counter by one
@$return['sum'][$type] += $row['#'];
if($type=='insert' || $type=='update') {
// Group inserts if selected
if($type=='insert' && isset($_REQUEST['groupInserts']) && $_REQUEST['groupInserts'] && preg_match('/^INSERT INTO (`|\'|"|)([^\s\\1]+)\\1/i',$row['argument'],$matches)) {
$insertTables[$matches[2]]++;
if ($insertTables[$matches[2]] > 1) {
$return['rows'][$insertTablesFirst]['#'] = $insertTables[$matches[2]];
// Add a ... to the end of this query to indicate that there's been other queries
if($return['rows'][$insertTablesFirst]['argument'][strlen($return['rows'][$insertTablesFirst]['argument'])-1] != '.')
$return['rows'][$insertTablesFirst]['argument'] .= '<br/>...';
// Group this value, thus do not add to the result list
continue;
} else {
$insertTablesFirst = $i;
$insertTables[$matches[2]] += $row['#'] - 1;
}
}
// Cut off big selects, but append byte count therefor
if (strlen($row['argument']) > 180) {
$row['argument'] = substr($row['argument'],0,160) . '... [' .
PMA_formatByteDown(strlen($row['argument']), 2).']';
}
}
$return['rows'][] = $row;
$i++;
}
$return['sum']['TOTAL'] = array_sum($return['sum']);
$return['numRows'] = count($return['rows']);
PMA_DBI_free_result($result);
exit(json_encode($return));
}
}
}
/**
* Replication library
*/
require './libraries/replication.inc.php';
require_once './libraries/replication_gui.lib.php';
/**
* JS Includes
*/
$GLOBALS['js_include'][] = 'server_status.js';
$GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
$GLOBALS['js_include'][] = 'jquery/jquery.tablesorter.js';
$GLOBALS['js_include'][] = 'jquery/jquery.cookie.js'; // For tab persistence
$GLOBALS['js_include'][] = 'jquery/jquery.json-2.2.js';
$GLOBALS['js_include'][] = 'jquery/jquery.sprintf.js';
$GLOBALS['js_include'][] = 'jquery/jquery.sortableTable.js';
$GLOBALS['js_include'][] = 'jquery/timepicker.js';
// Charting
$GLOBALS['js_include'][] = 'highcharts/highcharts.js';
/* Files required for chart exporting */
$GLOBALS['js_include'][] = 'highcharts/exporting.js';
$GLOBALS['js_include'][] = 'canvg/flashcanvas.js';
$GLOBALS['js_include'][] = 'canvg/canvg.js';
$GLOBALS['js_include'][] = 'canvg/rgbcolor.js';
/**
* flush status variables if requested
*/
if (isset($_REQUEST['flush'])) {
$_flush_commands = array(
'STATUS',
'TABLES',
'QUERY CACHE',
);
if (in_array($_REQUEST['flush'], $_flush_commands)) {
PMA_DBI_query('FLUSH ' . $_REQUEST['flush'] . ';');
}
unset($_flush_commands);
}
/**
* Kills a selected process
*/
if (!empty($_REQUEST['kill'])) {
if (PMA_DBI_try_query('KILL ' . $_REQUEST['kill'] . ';')) {
$message = PMA_Message::success(__('Thread %s was successfully killed.'));
} else {
$message = PMA_Message::error(__('phpMyAdmin was unable to kill thread %s. It probably has already been closed.'));
}
$message->addParam($_REQUEST['kill']);
//$message->display();
}
/**
* get status from server
*/
$server_status = PMA_DBI_fetch_result('SHOW GLOBAL STATUS', 0, 1);
/**
* for some calculations we require also some server settings
*/
$server_variables = PMA_DBI_fetch_result('SHOW GLOBAL VARIABLES', 0, 1);
/**
* cleanup of some deprecated values
*/
cleanDeprecated($server_status);
/**
* calculate some values
*/
// Key_buffer_fraction
if (isset($server_status['Key_blocks_unused'])
&& isset($server_variables['key_cache_block_size'])
&& isset($server_variables['key_buffer_size'])) {
$server_status['Key_buffer_fraction_%'] =
100
- $server_status['Key_blocks_unused']
* $server_variables['key_cache_block_size']
/ $server_variables['key_buffer_size']
* 100;
} elseif (isset($server_status['Key_blocks_used'])
&& isset($server_variables['key_buffer_size'])) {
$server_status['Key_buffer_fraction_%'] =
$server_status['Key_blocks_used']
* 1024
/ $server_variables['key_buffer_size'];
}
// Ratio for key read/write
if (isset($server_status['Key_writes'])
&& isset($server_status['Key_write_requests'])
&& $server_status['Key_write_requests'] > 0) {
$server_status['Key_write_ratio_%'] = 100 * $server_status['Key_writes'] / $server_status['Key_write_requests'];
}
if (isset($server_status['Key_reads'])
&& isset($server_status['Key_read_requests'])
&& $server_status['Key_read_requests'] > 0) {
$server_status['Key_read_ratio_%'] = 100 * $server_status['Key_reads'] / $server_status['Key_read_requests'];
}
// Threads_cache_hitrate
if (isset($server_status['Threads_created'])
&& isset($server_status['Connections'])
&& $server_status['Connections'] > 0) {
$server_status['Threads_cache_hitrate_%'] =
100
- $server_status['Threads_created']
/ $server_status['Connections']
* 100;
}
// Format Uptime_since_flush_status : show as days, hours, minutes, seconds
if (isset($server_status['Uptime_since_flush_status'])) {
$server_status['Uptime_since_flush_status'] = PMA_timespanFormat($server_status['Uptime_since_flush_status']);
}
/**
* split variables in sections
*/
$allocations = array(
// variable name => section
// variable names match when they begin with the given string
'Com_' => 'com',
'Innodb_' => 'innodb',
'Ndb_' => 'ndb',
'Handler_' => 'handler',
'Qcache_' => 'qcache',
'Threads_' => 'threads',
'Slow_launch_threads' => 'threads',
'Binlog_cache_' => 'binlog_cache',
'Created_tmp_' => 'created_tmp',
'Key_' => 'key',
'Delayed_' => 'delayed',
'Not_flushed_delayed_rows' => 'delayed',
'Flush_commands' => 'query',
'Last_query_cost' => 'query',
'Slow_queries' => 'query',
'Queries' => 'query',
'Prepared_stmt_count' => 'query',
'Select_' => 'select',
'Sort_' => 'sort',
'Open_tables' => 'table',
'Opened_tables' => 'table',
'Open_table_definitions' => 'table',
'Opened_table_definitions' => 'table',
'Table_locks_' => 'table',
'Rpl_status' => 'repl',
'Slave_' => 'repl',
'Tc_' => 'tc',
'Ssl_' => 'ssl',
'Open_files' => 'files',
'Open_streams' => 'files',
'Opened_files' => 'files',
);
$sections = array(
// section => section name (description)
'com' => 'Com',
'query' => __('SQL query'),
'innodb' => 'InnoDB',
'ndb' => 'NDB',
'handler' => __('Handler'),
'qcache' => __('Query cache'),
'threads' => __('Threads'),
'binlog_cache' => __('Binary log'),
'created_tmp' => __('Temporary data'),
'delayed' => __('Delayed inserts'),
'key' => __('Key cache'),
'select' => __('Joins'),
'repl' => __('Replication'),
'sort' => __('Sorting'),
'table' => __('Tables'),
'tc' => __('Transaction coordinator'),
'files' => __('Files'),
'ssl' => 'SSL',
);
/**
* define some needfull links/commands
*/
// variable or section name => (name => url)
$links = array();
$links['table'][__('Flush (close) all tables')]
= $PMA_PHP_SELF . '?flush=TABLES&' . PMA_generate_common_url();
$links['table'][__('Show open tables')]
= 'sql.php?sql_query=' . urlencode('SHOW OPEN TABLES') .
'&goto=server_status.php&' . PMA_generate_common_url();
if ($server_master_status) {
$links['repl'][__('Show slave hosts')]
= 'sql.php?sql_query=' . urlencode('SHOW SLAVE HOSTS') .
'&goto=server_status.php&' . PMA_generate_common_url();
$links['repl'][__('Show master status')] = '#replication_master';
}
if ($server_slave_status) {
$links['repl'][__('Show slave status')] = '#replication_slave';
}
$links['repl']['doc'] = 'replication';
$links['qcache'][__('Flush query cache')]
= $PMA_PHP_SELF . '?flush=' . urlencode('QUERY CACHE') . '&' .
PMA_generate_common_url();
$links['qcache']['doc'] = 'query_cache';
//$links['threads'][__('Show processes')]
// = 'server_processlist.php?' . PMA_generate_common_url();
$links['threads']['doc'] = 'mysql_threads';
$links['key']['doc'] = 'myisam_key_cache';
$links['binlog_cache']['doc'] = 'binary_log';
$links['Slow_queries']['doc'] = 'slow_query_log';
$links['innodb'][__('Variables')]
= 'server_engines.php?engine=InnoDB&' . PMA_generate_common_url();
$links['innodb'][__('InnoDB Status')]
= 'server_engines.php?engine=InnoDB&page=Status&' .
PMA_generate_common_url();
$links['innodb']['doc'] = 'innodb';
// Variable to contain all com_ variables
$used_queries = array();
// Variable to map variable names to their respective section name (used for js category filtering)
$allocationMap = array();
// sort vars into arrays
foreach ($server_status as $name => $value) {
foreach ($allocations as $filter => $section) {
if (strpos($name, $filter) !== false) {
$allocationMap[$name] = $section;
if ($section == 'com' && $value > 0) $used_queries[$name] = $value;
break; // Only exits inner loop
}
}
}
// admin commands are not queries (e.g. they include COM_PING, which is excluded from $server_status['Questions'])
unset($used_queries['Com_admin_commands']);
/* Ajax request refresh */
if (isset($_REQUEST['show']) && isset($_REQUEST['ajax_request'])) {
switch($_REQUEST['show']) {
case 'query_statistics':
printQueryStatistics();
exit();
case 'server_traffic':
printServerTraffic();
exit();
case 'variables_table':
// Prints the variables table
printVariablesTable();
exit();
default:
break;
}
}
/**
* start output
*/
/**
* Does the common work
*/
require './libraries/server_common.inc.php';
/**
* Displays the links
*/
require './libraries/server_links.inc.php';
$server = 1;
if(isset($_REQUEST['server']) && intval($_REQUEST['server'])) $server = intval($_REQUEST['server']);
$server_db_isLocal = strtolower($cfg['Servers'][$server]['host']) == 'localhost'
|| $cfg['Servers'][$server]['host'] == '127.0.0.1'
|| $cfg['Servers'][$server]['host'] == '::1';
?>
<script type="text/javascript">
pma_token = '<?php echo $_SESSION[' PMA_token ']; ?>';
url_query = '<?php echo str_replace('&','&',$url_query);?>';
server_time_diff = new Date().getTime() - <?php echo microtime(true)*1000; ?>;
server_os = '<?php echo PHP_OS; ?>';
is_superuser = <?php echo PMA_isSuperuser()?'true':'false'; ?>;
server_db_isLocal = <?php echo ($server_db_isLocal)?'true':'false'; ?>;
</script>
<div id="serverstatus">
<h2><?php
/**
* Displays the sub-page heading
*/
if ($GLOBALS['cfg']['MainPageIconic']) {
echo '<img class="icon ic_s_status" src="themes/dot.gif" width="16" height="16" alt="" />';
}
echo __('Runtime Information');
?></h2>
<div id="serverStatusTabs">
<ul>
<li><a href="#statustabs_traffic"><?php echo __('Server'); ?></a></li>
<li><a href="#statustabs_queries"><?php echo __('Query statistics'); ?></a></li>
<li><a href="#statustabs_allvars"><?php echo __('All status variables'); ?></a></li>
<li><a href="#statustabs_charting"><?php echo __('Monitor'); ?></a></li>
</ul>
<div id="statustabs_traffic">
<div class="buttonlinks">
<a class="tabRefresh" href="<?php echo $PMA_PHP_SELF . '?show=server_traffic&' . PMA_generate_common_url(); ?>" >
<img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" style="display: none;" />
<?php echo __('Refresh'); ?>
</a>
<span class="refreshList" style="display:none;">
<label for="trafficChartRefresh"><?php echo __('Refresh rate: '); ?></label>
<?php refreshList('trafficChartRefresh'); ?>
</span>
<a class="tabChart livetrafficLink" href="#">
<?php echo __('Live traffic chart'); ?>
</a>
<a class="tabChart liveconnectionsLink" href="#">
<?php echo __('Live conn./process chart'); ?>
</a>
</div>
<div class="tabInnerContent">
<?php printServerTraffic(); ?>
</div>
</div>
<div id="statustabs_queries">
<div class="buttonlinks">
<a class="tabRefresh" href="<?php echo $PMA_PHP_SELF . '?show=query_statistics&' . PMA_generate_common_url(); ?>" >
<img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" style="display: none;" />
<?php echo __('Refresh'); ?>
</a>
<span class="refreshList" style="display:none;">
<label for="queryChartRefresh"><?php echo __('Refresh rate: '); ?></label>
<?php refreshList('queryChartRefresh'); ?>
</span>
<a class="tabChart livequeriesLink" href="#">
<?php echo __('Live query chart'); ?>
</a>
</div>
<div class="tabInnerContent">
<?php printQueryStatistics(); ?>
</div>
</div>
<div id="statustabs_allvars">
<fieldset id="tableFilter">
<div class="buttonlinks">
<a class="tabRefresh" href="<?php echo $PMA_PHP_SELF . '?show=variables_table&' . PMA_generate_common_url(); ?>" >
<img src="<?php echo $GLOBALS['pmaThemeImage'];?>ajax_clock_small.gif" alt="ajax clock" style="display: none;" />
<?php echo __('Refresh'); ?>
</a>
</div>
<legend>Filters</legend>
<div class="formelement">
<label for="filterText"><?php echo __('Containing the word:'); ?></label>
<input name="filterText" type="text" id="filterText" style="vertical-align: baseline;" />
</div>
<div class="formelement">
<input type="checkbox" name="filterAlert" id="filterAlert">
<label for="filterAlert"><?php echo __('Show only alert values'); ?></label>
</div>
<div class="formelement">
<select id="filterCategory" name="filterCategory">
<option value=''><?php echo __('Filter by category...'); ?></option>
<?php
foreach ($sections as $section_id => $section_name) {
?>
<option value='<?php echo $section_id; ?>'><?php echo $section_name; ?></option>
<?php
}
?>
</select>
</div>
</fieldset>
<div id="linkSuggestions" class="defaultLinks" style="display:none">
<p class="notice"><?php echo __('Related links:'); ?>
<?php
foreach ($links as $section_name => $section_links) {
echo '<span class="status_'.$section_name.'"> ';
$i=0;
foreach ($section_links as $link_name => $link_url) {
if ($i > 0) echo ', ';
if ('doc' == $link_name) {
echo PMA_showMySQLDocu($link_url, $link_url);
} else {
echo '<a href="' . $link_url . '">' . $link_name . '</a>';
}
$i++;
}
echo '</span>';
}
unset($link_url, $link_name, $i);
?>
</p>
</div>
<div class="tabInnerContent">
<?php printVariablesTable(); ?>
</div>
</div>
<div id="statustabs_charting">
<?php printMonitor(); ?>
</div>
</div>
</div>
<?php
function printQueryStatistics() {
global $server_status, $used_queries, $url_query, $PMA_PHP_SELF;
$hour_factor = 3600 / $server_status['Uptime'];
$total_queries = array_sum($used_queries);
?>
<h3 id="serverstatusqueries">
<?php
/* l10n: Questions is the name of a MySQL Status variable */
echo sprintf(__('Questions since startup: %s'),PMA_formatNumber($total_queries, 0)) . ' ';
echo PMA_showMySQLDocu('server-status-variables', 'server-status-variables', false, 'statvar_Questions');
?>
<br>
<span>
<?php
echo 'ø '.__('per hour').': ';
echo PMA_formatNumber($total_queries * $hour_factor, 0);
echo '<br>';
echo 'ø '.__('per minute').': ';
echo PMA_formatNumber( $total_queries * 60 / $server_status['Uptime'], 0);
echo '<br>';
if($total_queries / $server_status['Uptime'] >= 1) {
echo 'ø '.__('per second').': ';
echo PMA_formatNumber( $total_queries / $server_status['Uptime'], 0);
}
?>
</span>
</h3>
<?php
// reverse sort by value to show most used statements first
arsort($used_queries);
$odd_row = true;
$count_displayed_rows = 0;
$perc_factor = 100 / $total_queries; //(- $server_status['Connections']);
?>
<table id="serverstatusqueriesdetails" class="data sortable">
<col class="namecol" />
<col class="valuecol" span="3" />
<thead>
<tr><th><?php echo __('Statements'); ?></th>
<th><?php
/* l10n: # = Amount of queries */
echo __('#');
?>
<th>ø <?php echo __('per hour'); ?></th>
<th>%</th>
</tr>
</thead>
<tbody>
<?php
$chart_json = array();
$query_sum = array_sum($used_queries);
$other_sum = 0;
foreach ($used_queries as $name => $value) {
$odd_row = !$odd_row;
// For the percentage column, use Questions - Connections, because
// the number of connections is not an item of the Query types
// but is included in Questions. Then the total of the percentages is 100.
$name = str_replace(array('Com_', '_'), array('', ' '), $name);
// Group together values that make out less than 2% into "Other", but only if we have more than 6 fractions already
if($value < $query_sum * 0.02 && count($chart_json)>6)
$other_sum += $value;
else $chart_json[$name] = $value;
?>
<tr class="noclick <?php echo $odd_row ? 'odd' : 'even'; ?>">
<th class="name"><?php echo htmlspecialchars($name); ?></th>
<td class="value"><?php echo PMA_formatNumber($value, 5, 0, true); ?></td>
<td class="value"><?php echo
PMA_formatNumber($value * $hour_factor, 4, 1, true); ?></td>
<td class="value"><?php echo
PMA_formatNumber($value * $perc_factor, 0, 2); ?>%</td>
</tr>
<?php
}
?>
</tbody>
</table>
<div id="serverstatusquerieschart">
<span style="display:none;">
<?php
if ($other_sum > 0)
$chart_json[__('Other')] = $other_sum;
echo json_encode($chart_json);
?>
</span>
</div>
<?php
}
function printServerTraffic() {
global $server_status,$PMA_PHP_SELF;
global $server_master_status, $server_slave_status, $replication_types;
$hour_factor = 3600 / $server_status['Uptime'];
/**
* starttime calculation
*/
$start_time = PMA_DBI_fetch_value(
'SELECT UNIX_TIMESTAMP() - ' . $server_status['Uptime']);
?>
<h3><?php
echo sprintf(
__('Network traffic since startup: %s'),
implode(' ', PMA_formatByteDown( $server_status['Bytes_received'] + $server_status['Bytes_sent'], 3, 1))
);
?>
</h3>
<p>
<?php
echo sprintf(__('This MySQL server has been running for %1$s. It started up on %2$s.'),
PMA_timespanFormat($server_status['Uptime']),
PMA_localisedDate($start_time)) . "\n";
?>
</p>
<?php
if ($server_master_status || $server_slave_status) {
echo '<p class="notice">';
if ($server_master_status && $server_slave_status) {
echo __('This MySQL server works as <b>master</b> and <b>slave</b> in <b>replication</b> process.');
} elseif ($server_master_status) {
echo __('This MySQL server works as <b>master</b> in <b>replication</b> process.');
} elseif ($server_slave_status) {
echo __('This MySQL server works as <b>slave</b> in <b>replication</b> process.');
}
echo __('For further information about replication status on the server, please visit the <a href="#replication">replication section</a>.');
echo '</p>';
}
/* if the server works as master or slave in replication process, display useful information */
if ($server_master_status || $server_slave_status)
{
?>
<hr class="clearfloat" />
<h3><a name="replication"></a><?php echo __('Replication status'); ?></h3>
<?php
foreach ($replication_types as $type)
{
if (${"server_{$type}_status"}) {
PMA_replication_print_status_table($type);
}
}
unset($types);
}
?>
<table id="serverstatustraffic" class="data">
<thead>
<tr>
<th colspan="2"><?php echo __('Traffic') . ' ' . PMA_showHint(__('On a busy server, the byte counters may overrun, so those statistics as reported by the MySQL server may be incorrect.')); ?></th>
<th>ø <?php echo __('per hour'); ?></th>
</tr>
</thead>
<tbody>
<tr class="noclick odd">
<th class="name"><?php echo __('Received'); ?></th>
<td class="value"><?php echo
implode(' ',
PMA_formatByteDown($server_status['Bytes_received'], 3, 1)); ?></td>
<td class="value"><?php echo
implode(' ',
PMA_formatByteDown(
$server_status['Bytes_received'] * $hour_factor, 3, 1)); ?></td>
</tr>
<tr class="noclick even">
<th class="name"><?php echo __('Sent'); ?></th>
<td class="value"><?php echo
implode(' ',
PMA_formatByteDown($server_status['Bytes_sent'], 3, 1)); ?></td>
<td class="value"><?php echo
implode(' ',
PMA_formatByteDown(
$server_status['Bytes_sent'] * $hour_factor, 3, 1)); ?></td>
</tr>
<tr class="noclick odd">
<th class="name"><?php echo __('Total'); ?></th>
<td class="value"><?php echo
implode(' ',
PMA_formatByteDown(
$server_status['Bytes_received'] + $server_status['Bytes_sent'], 3, 1)
); ?></td>
<td class="value"><?php echo
implode(' ',
PMA_formatByteDown(
($server_status['Bytes_received'] + $server_status['Bytes_sent'])
* $hour_factor, 3, 1)
); ?></td>
</tr>
</tbody>
</table>
<table id="serverstatusconnections" class="data">
<thead>
<tr>
<th colspan="2"><?php echo __('Connections'); ?></th>
<th>ø <?php echo __('per hour'); ?></th>
<th>%</th>
</tr>
</thead>
<tbody>
<tr class="noclick odd">
<th class="name"><?php echo __('max. concurrent connections'); ?></th>
<td class="value"><?php echo
PMA_formatNumber($server_status['Max_used_connections'], 0); ?> </td>
<td class="value">--- </td>
<td class="value">--- </td>
</tr>
<tr class="noclick even">
<th class="name"><?php echo __('Failed attempts'); ?></th>
<td class="value"><?php echo
PMA_formatNumber($server_status['Aborted_connects'], 4, 1, true); ?></td>
<td class="value"><?php echo
PMA_formatNumber($server_status['Aborted_connects'] * $hour_factor,
4, 2, true); ?></td>
<td class="value"><?php echo
$server_status['Connections'] > 0
? PMA_formatNumber(
$server_status['Aborted_connects'] * 100 / $server_status['Connections'],
0, 2, true) . '%'
: '--- '; ?></td>
</tr>
<tr class="noclick odd">
<th class="name"><?php echo __('Aborted'); ?></th>
<td class="value"><?php echo
PMA_formatNumber($server_status['Aborted_clients'], 4, 1, true); ?></td>
<td class="value"><?php echo
PMA_formatNumber($server_status['Aborted_clients'] * $hour_factor,
4, 2, true); ?></td>
<td class="value"><?php echo
$server_status['Connections'] > 0
? PMA_formatNumber(
$server_status['Aborted_clients'] * 100 / $server_status['Connections'],
0, 2, true) . '%'
: '--- '; ?></td>
</tr>
<tr class="noclick even">
<th class="name"><?php echo __('Total'); ?></th>
<td class="value"><?php echo
PMA_formatNumber($server_status['Connections'], 4, 0); ?></td>
<td class="value"><?php echo
PMA_formatNumber($server_status['Connections'] * $hour_factor,
4, 2); ?></td>
<td class="value"><?php echo
PMA_formatNumber(100, 0, 2); ?>%</td>
</tr>
</tbody>
</table>
<?php
$url_params = array();
if (! empty($_REQUEST['full'])) {
$sql_query = 'SHOW FULL PROCESSLIST';
$url_params['full'] = 1;
$full_text_link = 'server_status.php' . PMA_generate_common_url(array(), 'html', '?');
} else {
$sql_query = 'SHOW PROCESSLIST';
$full_text_link = 'server_status.php' . PMA_generate_common_url(array('full' => 1));
}
$result = PMA_DBI_query($sql_query);
/**
* Displays the page
*/
?>
<table id="tableprocesslist" class="data clearfloat">
<thead>
<tr>
<th><?php echo __('Processes'); ?></th>
<th><?php echo __('ID'); ?></th>
<th><?php echo __('User'); ?></th>
<th><?php echo __('Host'); ?></th>
<th><?php echo __('Database'); ?></th>
<th><?php echo __('Command'); ?></th>
<th><?php echo __('Time'); ?></th>
<th><?php echo __('Status'); ?></th>
<th><?php
echo __('SQL query');
if (! PMA_DRIZZLE) { ?>
<a href="<?php echo $full_text_link; ?>"
title="<?php echo empty($full) ? __('Show Full Queries') : __('Truncate Shown Queries'); ?>">
<img src="<?php echo $GLOBALS['pmaThemeImage'] . 's_' . (empty($_REQUEST['full']) ? 'full' : 'partial'); ?>text.png"
alt="<?php echo empty($_REQUEST['full']) ? __('Show Full Queries') : __('Truncate Shown Queries'); ?>" />