This repository was archived by the owner on Oct 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathController.php
More file actions
executable file
·782 lines (686 loc) · 25.9 KB
/
Controller.php
File metadata and controls
executable file
·782 lines (686 loc) · 25.9 KB
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
<?php
/**
* Piwik - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\DBHealth;
use Piwik\Db;
use Piwik\Log;
use Piwik\Piwik;
use Piwik\Config;
use Piwik\View;
use Piwik\Access;
use Piwik\Common;
use Piwik\DataTable;
use Piwik\DataTable\BaseFilter;
use Piwik\Plugin\ControllerAdmin;
use Piwik\Plugins\DBHealth\API as DBHealthAPI;
/**
* A controller lets you for example create a page that can be added to a menu. For more information read our guide
* http://developer.piwik.org/guides/mvc-in-piwik or have a look at the our API references for controller and view:
* http://developer.piwik.org/api-reference/Piwik/Plugin/Controller and
* http://developer.piwik.org/api-reference/Piwik/View
*/
class Controller extends \Piwik\Plugin\Controller
{
function index()
{
return null;
}
/**
* Return Database PERFORMANCE_SCHEMA variables
*
* @return array
*/
function showPerformanceSchemaStatus()
{
$db = new Db();
$query = "SHOW ENGINE PERFORMANCE_SCHEMA STATUS";
return $db::fetchAll($query);
}
/**
* Return Calculation od Database index length for InnoDB tables
*
* @return array
*/
function showInnodbIndexes()
{
$db = new Db();
$query = "SELECT SUM(INDEX_LENGTH) var FROM information_schema.tables WHERE ENGINE='InnoDB'";
return $db::fetchAll($query);
}
/**
* Return Calculation od Database size for InnoDB tables
*
* @return array
*/
function showInnodbData()
{
$db = new Db();
$query = "SELECT SUM(DATA_LENGTH) var FROM information_schema.tables WHERE ENGINE='InnoDB'";
return $db::fetchAll($query);
}
/**
* Return Database Setting variables
*
* @return array
*/
function showVariables()
{
$db = new Db();
$query = "SHOW GLOBAL VARIABLES";
return $db::fetchAll($query);
}
function opCacheStatus()
{
if (!extension_loaded('Zend OPcache')) {
return null;
}
else
return opcache_get_configuration();
}
function opCacheEnabled()
{
if (!extension_loaded('Zend OPcache')) {
return false;
}
else
return true;
}
/**
* Return Database Status variables
*
* @return array
*/
function showStatus()
{
$db = new Db();
$query = "SHOW GLOBAL STATUS";
return $db::fetchAll($query);
}
/**
* Calculate Mem usage in DB
*
* @return object
*/
function memUsage()
{
$variables = $this->showVariables();
$stat = $this->showStatus();
//Variables
$read_buffer_size = 0;
$read_rnd_buffer_size = 0;
$sort_buffer_size = 0;
$thread_stack = 0;
$max_connections = 0;
$join_buffer_size = 0;
$tmp_table_size = 0;
$max_heap_table_size = 0;
$log_bin = 0;
$binlog_cache_size = 0;
$innodb_buffer_pool_size= 0;
$innodb_additional_mem_pool_size= 0;
$innodb_log_buffer_size= 0;
$key_buffer_size = 0;
$query_cache_size= 0;
$query_cache_type =0;
//Status
$max_used_connections = 0;
//Calculations
$per_thread_buffers = 0;
$per_thread_max_buffers = 0;
$effective_tmp_table_size = 0;
//Variables
foreach ($variables as $item) {
if($item['Variable_name'] == 'query_cache_type') {
$query_cache_type = $item['Value'];
}
if($item['Variable_name'] == 'innodb_buffer_pool_size') {
$innodb_buffer_pool_size = $item['Value'];
}
if($item['Variable_name'] == 'innodb_additional_mem_pool_size') {
$innodb_additional_mem_pool_size = $item['Value'];
}
if($item['Variable_name'] == 'innodb_log_buffer_size') {
$innodb_log_buffer_size = $item['Value'];
}
if($item['Variable_name'] == 'key_buffer_size') {
$innodb_additional_mem_pool_size = $item['Value'];
}
if($item['Variable_name'] == 'query_cache_size') {
$query_cache_size = $item['Value'];
}
if($item['Variable_name'] == 'read_buffer_size') {
$read_buffer_size = $item['Value'];
}
if($item['Variable_name'] == 'read_rnd_buffer_size') {
$read_rnd_buffer_size = $item['Value'];
}
if($item['Variable_name'] == 'sort_buffer_size') {
$sort_buffer_size = $item['Value'];
}
if($item['Variable_name'] == 'thread_stack') {
$thread_stack = $item['Value'];
}
if($item['Variable_name'] == 'max_connections') {
$max_connections = $item['Value'];
}
if($item['Variable_name'] == 'join_buffer_size') {
$join_buffer_size = $item['Value'];
}
if($item['Variable_name'] == 'tmp_table_size') {
$tmp_table_size = $item['Value'];
}
if($item['Variable_name'] == 'max_heap_table_size') {
$max_heap_table_size = $item['Value'];
}
if($item['Variable_name'] == 'log_bin') {
$tmp_table_size = $item['Value'];
}
if($item['Variable_name'] == 'binlog_cache_size') {
$binlog_cache_size = $item['Value'];
}
}
foreach ($stat as $item) {
if($item['Variable_name'] == 'Max_used_connections') {
$max_used_connections = $item['Value'];
}
}
if ($max_heap_table_size < $tmp_table_size)
$effective_tmp_table_size=$max_heap_table_size;
else
$effective_tmp_table_size=$tmp_table_size;
$per_thread_buffers = ($read_buffer_size + $read_rnd_buffer_size + $sort_buffer_size + $thread_stack + $join_buffer_size + $binlog_cache_size) * $max_connections;
$per_thread_max_buffers = ($read_buffer_size + $read_rnd_buffer_size + $sort_buffer_size + $thread_stack + $join_buffer_size + $binlog_cache_size) * $max_used_connections;
$global_buffers = $innodb_buffer_pool_size + $innodb_additional_mem_pool_size + $innodb_log_buffer_size + $key_buffer_size + $query_cache_size;
$max_memory = $global_buffers + $per_thread_max_buffers; // Max used connections possible
$total_memory = $global_buffers + $per_thread_buffers; // Max connections possible
$result = [ "max_memory" => round($max_memory/ 1024 / 1024,2),
"per_thread_buffers" => round($per_thread_buffers/ 1024 / 1024,2),
"global_buffers" => round($global_buffers/ 1024 / 1024,2),
"total_memory" => round($total_memory/ 1024 / 1024,2),
"effective_tmp_table_size" => round($effective_tmp_table_size/ 1024 / 1024,2),
"tmp_table_size" => round($tmp_table_size/ 1024 / 1024,2),
"max_heap_table_size" => round($max_heap_table_size/ 1024 / 1024,2)
];
return $result;
}
/**
* Calculate Query Cache usage in DB
*
* @return object
*/
function queryCacheCheck()
{
$variables = $this->showVariables();
$stat = $this->showStatus();
$msgFrag = "";
$msgUnused = "Memory usage ratio is fine";
$msgSize = "Memory seems high enough";
$msg = "";
//Variables (settings)
$query_cache_size = 0;
$query_cache_limit = 0;
$query_cache_min_res_unit = 0;
$query_cache_type = 0;
//Status
$qcache_free_memory = 0;
$qcache_used_memory = 0;
$qcache_free_blocks = 0;
$qcache_lowmem_prunes = 0;
$uptime_since_flush_status = 0;
$uptime = 0;
$qcache_hits = 0;
$qcache_inserts = 0;
$qcache_not_cached = 0;
//Calculations
$qcache_mem_fill_ratio = 0;
$qcache_used_memory= 0 ;
$qcache_mem_fill_ratioHR = 0;
$qcache_percent_fragmented = 0;
$qcache_percent_fragmentedHR = 0;
//Variables
foreach ($variables as $item) {
if($item['Variable_name'] == 'query_cache_type') {
$query_cache_type = $item['Value'];
}
if($item['Variable_name'] == 'query_cache_size') {
$query_cache_size = $item['Value'];
}
if($item['Variable_name'] == 'query_cache_limit') {
$query_cache_limit = $item['Value'];
} if($item['Variable_name'] == 'query_cache_min_res_unit') {
$query_cache_min_res_unit = $item['Value'];
}
}
//Status
foreach ($stat as $item) {
if($item['Variable_name'] == 'Qcache_free_memory') {
$qcache_free_memory = (int) $item['Value'];
}
if($item['Variable_name'] == 'Qcache_used_memory') {
$qcache_used_memory = (int) $item['Value'];
}
if($item['Variable_name'] == 'Qcache_free_blocks') {
$qcache_free_blocks = (int) $item['Value'];
}
if($item['Variable_name'] == 'Qcache_total_blocks') {
$qcache_total_blocks = (int) $item['Value'];
}
if($item['Variable_name'] == 'Qcache_hits') {
$qcache_hits = (int) $item['Value'];
}
if($item['Variable_name'] == 'Qcache_not_cached') {
$qcache_not_cached = (int) $item['Value'];
}
if($item['Variable_name'] == 'Qcache_inserts') {
$qcache_inserts = (int) $item['Value'];
}
if($item['Variable_name'] == 'Uptime_since_flush_status') {
$uptime_since_flush_status = (int) $item['Value'];
}
if($item['Variable_name'] == 'Uptime') {
$uptime = (int) $item['Value'];
}
}
if ($query_cache_type == 0) {
$msg = "The Query cache is disabled";
$msgFrag = "";
$msgUnused = "";
$msgSize = "";
}
else if ($query_cache_size == 0) {
$msg = "Query cache is supported but size is 0 perhaps you should set the query_cache_size(" . $query_cache_size . ")";
$msgFrag = "";
$msgUnused = "";
$msgSize = "";
}
else {
$qcache_used_memory = $query_cache_size - $qcache_free_memory;
$qcache_mem_fill_ratio = $qcache_used_memory * 100 / $query_cache_size;
$qcache_mem_fill_ratioHR = $qcache_mem_fill_ratio / 1;
if ($qcache_free_blocks > 2 && $qcache_total_blocks > 0) {
$qcache_percent_fragmented = $qcache_free_blocks * 100 / $qcache_total_blocks;
$qcache_percent_fragmentedHR = $qcache_percent_fragmented / 1;
}
if ( $qcache_mem_fill_ratioHR <= 25) {
$msgUnused = "Your query_cache_size (". round($query_cache_size/ 1024 / 1024,2) . " MB) might to be too high (but if your system was recently restarded you might want to wait and see what happends) ";
$msgUnused = $msgUnused . "The memory fill ratio is " . round($qcache_mem_fill_ratioHR,2) . " %";
$msgUnused = $msgUnused . "Perhaps you can use these resources elsewhere";
}
if ($qcache_lowmem_prunes >= 50 && $qcache_mem_fill_ratioHR >= 80) {
$msgSize = "However " . $qcache_lowmem_prunes . " queries have been removed from the query cache ";
$msgSize = $msgSize ."due to lack of memory. Perhaps you should raise query_cache_size";
}
else {
$msgSize = "Number of querys that has been removed from cache due to lack of memory (Qcache_lowmem_prunes) = " . $qcache_lowmem_prunes;
}
}
$opcach_status;
$last_restart_time;
if (!extension_loaded('Zend OPcache')) {
$opcach_status = null;
}
else {
$opcach_status = opcache_get_status(false);
if( !isset($status['opcache_statistics']['last_restart_time']))
$last_restart_time = "never";
else
$last_restart_time = date('Y-m-d H:i:s', $opcach_status['opcache_statistics']['last_restart_time']);
}
$result = [ "query_cache_size" => round($query_cache_size/ 1024 / 1024,2),
"query_cache_type" => $query_cache_type,
"qcache_free_memory" => round($qcache_free_memory/ 1024 / 1024,2),
"qcache_fill_ratio" => round($qcache_mem_fill_ratioHR,2),
"qcache_percent_fragmentedHR" => round($qcache_percent_fragmentedHR,2),
"qcache_lowmem_prunes" => $qcache_lowmem_prunes,
"query_cache_min_res_unit" => $query_cache_min_res_unit,
"query_cache_limit" => round($query_cache_limit/ 1024 / 1024,2),
"qcache_hits" => $qcache_hits,
"qcache_inserts" => $qcache_inserts,
"qcache_not_cached" => $qcache_not_cached,
"qcache_total_blocks" => $qcache_total_blocks,
"msgUnused" => $msgUnused,
"opcach_status" => $opcach_status,
"last_restart_time" => $last_restart_time,
"uptime_since_flush_status" => $this->convertToHoursMins($uptime_since_flush_status/60, '%02d hour(s) %02d minutes'),
"uptime" => $uptime,
"msgSize" => $msgSize];
return $result;
}
/**
* Calculate Hours Mins from seconds
*
* @return object[hours, minutes]
*/
function convertToHoursMins($time, $format = '%02d:%02d') {
if ($time < 1) {
return;
}
$hours = floor($time / 60);
$minutes = ($time % 60);
return sprintf($format, $hours, $minutes);
}
/**
* Calculate Database Disk usage usage in DB
*
* @return object
*/
function tmpTableCheck()
{
$stat = $this->showStatus();
//TMP Table tests
$tmp_disk_tables = 0;
$created_tmp_tables = 0;
$tmp_disk_tables_ratio = 0;
$pen_files = 0;
$percent_innodb_buffer_pool_free = 0;
$opened_tables = 0;
//Status
foreach ($stat as $item) {
if($item['Variable_name'] == 'Created_tmp_disk_tables') {
$tmp_disk_tables = (int) $item['Value'];
}
if($item['Variable_name'] == 'Created_tmp_tables') {
$created_tmp_tables = (int) $item['Value'];
}
if($item['Variable_name'] == 'Percent_innodb_buffer_pool_free') {
$percent_innodb_buffer_pool_free = (int) $item['Value'];
}
if($item['Variable_name'] == 'Innodb_buffer_pool_pages_free') {
$innodb_buffer_pool_pages_free = (int) $item['Value'];
}
if($item['Variable_name'] == 'Innodb_buffer_pool_pages_total') {
$innodb_buffer_pool_pages_total = (int) $item['Value'];
}
if($item['Variable_name'] == 'Max_used_connections') {
$max_used_connections = (int) $item['Value'];
}
if($item['Variable_name'] == 'Open_files') {
$pen_files = (int) $item['Value'];
}
if($item['Variable_name'] == 'Opened_tables') {
$opened_tables = (int) $item['Value'];
}
}
//Calc $tmp_disk_tables_ratio ratio
if ($tmp_disk_tables == 0 )
$tmp_disk_tables_ratio = 0;
else
$tmp_disk_tables_ratio = (($tmp_disk_tables * 100 / ( $created_tmp_tables + $tmp_disk_tables)));
$result = ["tmp_disk_tables" => $tmp_disk_tables,
"created_tmp_tables" => $created_tmp_tables,
"tmp_disk_tables_ratio" => round($tmp_disk_tables_ratio,2),
"percent_innodb_buffer_pool_free" => $percent_innodb_buffer_pool_free,
"open_files" => $pen_files,
"opened_tables" => $opened_tables
];
return $result;
}
/**
* Calculate Innodb Bufferpool usage in DB
*
* @return object
*/
function getBufferpoolTest() {
$variables = $this->showVariables();
$stat = $this->showStatus();
//Status
$innodb_buffer_pool_pages_data = 0;
$innodb_buffer_pool_pages_misc = 0;
$innodb_buffer_pool_pages_free = 0;
$innodb_buffer_pool_pages_total = 0;
$innodb_buffer_pool_read_ahead_seq = 0;
$innodb_buffer_pool_read_requests = 0;
$innodb_os_log_pending_fsyncs = 0;
$innodb_os_log_pending_writes = 0;
$innodb_log_waits = 0;
$innodb_row_lock_time = 0;
$innodb_row_lock_waits = 0;
//Variables
$innodb_buffer_pool_size = 0;
$innodb_additional_mem_pool_size = 0;
$innodb_fast_shutdown = 0;
$innodb_flush_log_at_trx_commit = 0;
$innodb_locks_unsafe_for_binlog = 0;
$innodb_log_buffer_size = 0;
$innodb_log_file_size = 0;
$innodb_log_files_in_group = 0;
$innodb_safe_binlog = 0;
$innodb_thread_concurrency = 0;
//Calculations
$percent_innodb_buffer_pool_free = 0;
foreach ($variables as $item) {
if($item['Variable_name'] == 'innodb_buffer_pool_size') {
$innodb_buffer_pool_size = (int) $item['Value'];
}
if($item['Variable_name'] == 'innodb_additional_mem_pool_size') {
$innodb_additional_mem_pool_size = (int) $item['Value'];
}
if($item['Variable_name'] == 'innodb_fast_shutdown') {
$innodb_fast_shutdown = $item['Value'];
}
if($item['Variable_name'] == 'innodb_flush_log_at_trx_commit') {
$innodb_flush_log_at_trx_commit = $item['Value'];
}
if($item['Variable_name'] == 'innodb_locks_unsafe_for_binlog') {
$innodb_locks_unsafe_for_binlog = $item['Value'];
}
if($item['Variable_name'] == 'innodb_log_buffer_size') {
$innodb_log_buffer_size = (int) $item['Value'];
}
if($item['Variable_name'] == 'innodb_log_file_size') {
$innodb_log_file_size = (int) $item['Value'];
}
if($item['Variable_name'] == 'innodb_log_files_in_group') {
$innodb_log_files_in_group = $item['Value'];
}
if($item['Variable_name'] == 'innodb_safe_binlog') {
$innodb_safe_binlog = $item['Value'];
}
if($item['Variable_name'] == 'innodb_thread_concurrency') {
$innodb_thread_concurrency = (int) $item['Value'];
}
}
foreach ($stat as $item) {
if($item['Variable_name'] == 'Innodb_buffer_pool_pages_data') {
$innodb_buffer_pool_pages_data = $item['Value'];
}
if($item['Variable_name'] == 'Innodb_buffer_pool_pages_misc') {
$innodb_buffer_pool_pages_misc = $item['Value'];
}
if($item['Variable_name'] == 'Innodb_buffer_pool_pages_free') {
$innodb_buffer_pool_pages_free = (int) $item['Value'];
}
if($item['Variable_name'] == 'Innodb_buffer_pool_pages_total') {
$innodb_buffer_pool_pages_total = (int) $item['Value'];
}
if($item['Variable_name'] == 'Innodb_buffer_pool_read_ahead_seq') {
$innodb_buffer_pool_read_ahead_seq = (int) $item['Value'];
}
if($item['Variable_name'] == 'Innodb_buffer_pool_read_requests') {
$innodb_buffer_pool_read_requests = (int) $item['Value'];
}
if($item['Variable_name'] == 'Innodb_os_log_pending_fsyncs') {
$innodb_os_log_pending_fsyncs = (int) $item['Value'];
}
if($item['Variable_name'] == 'Innodb_log_waits') {
$innodb_log_waits = (int) $item['Value'];
}
if($item['Variable_name'] == 'Innodb_row_lock_time') {
$innodb_row_lock_time = (int) $item['Value'];
}
if($item['Variable_name'] == 'Innodb_row_lock_waits') {
$innodb_row_lock_waits = (int) $item['Value'];
}
}
$percent_innodb_buffer_pool_free = $innodb_buffer_pool_pages_free * 100 / $innodb_buffer_pool_pages_total;
// TODO Need to verify that we have access ti infi schema before we run these - Disable for now
//$innodb_indexes = (int) $this->showInnodbIndexes()[0]['var'];
//$innodb_data = (int) $this->showInnodbData()[0]['var'];
$result = ["innodb_buffer_pool_size" => round($innodb_buffer_pool_size/ 1024 / 1024,2),
"percent_innodb_buffer_pool_free" => round($percent_innodb_buffer_pool_free,2),
"innodb_flush_log_at_trx_commit" => $innodb_flush_log_at_trx_commit
];
return $result;
}
/**
* Run DB tests and Visualize
*
* @return object
*/
function getPerfChecks() {
$api = new DBHealthAPI();
//Only for local dev
//opcache_invalidate('/opt/lampp/htdocs/matomo/plugins/DBHealth/Controller.php');
return $this->renderTemplate(
'perfreport',
[
'db_connection' => $this->dbStatus(),
'tmpTableCheck' => $this->tmpTableCheck(),
'queryCacheCheck' => $this->queryCacheCheck(),
'getBufferpoolTest' => $this->getBufferpoolTest(),
'memUsage' => $this->memUsage(),
'opCacheStatus' => $this->opCacheStatus(),
'opCacheEnabled' => $this->opCacheEnabled(),
'getPhpRealpathCacheUsage' => $this->getPhpRealpathCacheUsage(),
'getPhpRealpathCacheSettings' => $this->getPhpRealpathCacheSettings(),
'phpInfo' => $this->getPhpMemInfo()
]
);
}
function getPhpRealpathCacheUsage() {
return round(realpath_cache_size()/ 1024 / 1024,2) ;
}
/**
* PHP getPhpRealpathCacheSettings
*
* @return object
*/
function getPhpRealpathCacheSettings() {
$result = [];
$result = ["realpath_cache_size" => ini_get('realpath_cache_size') , "realpath_cache_ttl" => ini_get('realpath_cache_ttl')];
return $result;
}
/**
* PHP getXdebugStatus
*
* @return string
*/
function getXdebugStatus() {
if (!extension_loaded('xdebug')) {
return false;
}
else
return true;
}
/**
* PHP Mem info
*
* @return object
*/
function getPhpMemInfo() {
$result = [];
$result = ["memory_limit" => ini_get('memory_limit'),
"post_max_size" => ini_get('post_max_size'),
"upload_max_filesize" => ini_get('upload_max_filesize'),
"max_execution_time" => ini_get('max_execution_time'),
"xdebug_mode" => ini_get('xdebug.mode'),
"xdebug_status" => $this->getXdebugStatus()
];
return $result;
}
/**
* Test db connection time and return time
*
* @return int
*/
function dbStatus() {
$time_start = hrtime(true);
// We use SELECT 1; as the test query as we only want to check for latency between the host and the mysql engine, we are not testing the database schema performance here.
$db = new Db();
$query = "SELECT 1";
$result = $db::fetchAll($query);
$time_end = hrtime(true);
$time = $time_end - $time_start;
return $time/1e+6;
}
/**
* Visualize Table Status Variables
*
* @return object
*/
public function showProblematicSegments() {
//Log::debug("A user accessed getMysqlVariableData()");
try {
$api = new DBHealthAPI();
return $this->renderTemplate(
'segments',
[
'dataTable' => $api->getProblematicSegments()
]
);
} catch (\Exception $e) {
return $e->getMessage();
}
}
/**
* Visualize Table Status Variables
*
* @return object
*/
public function getMysqlTableStatus() {
//Log::debug("A user accessed getMysqlVariableData()");
try {
$api = new DBHealthAPI();
return $this->renderTemplate(
'index',
[
'dataTable' => $api->getMysqlTableStatus()
]
);
} catch (\Exception $e) {
return $e->getMessage();
}
}
/**
* Visualize Setting Variables
*
* @return object
*/
public function getMysqlVariableData() {
//Log::debug("A user accessed getMysqlVariableData()");
try {
$api = new DBHealthAPI();
return $this->renderTemplate(
'index',
[
'dataTable' => $api->getMysqlVariableData()
]
);
} catch (\Exception $e) {
return $e->getMessage();
}
}
/**
* Visualize Status Variables
*
* @return object
*/
public function getMysqlStatus() {
//Log::debug("A user accessed getMysqlstatus()");
try {
$api = new DBHealthAPI();
return $this->renderTemplate(
'index',
[
'dataTable' => $api->getMysqlStatusData()
]
);
} catch (\Exception $e) {
return $e->getMessage();
}
}
}