@@ -19,7 +19,7 @@ trait MemcachedTrait {
1919 /**
2020 * @return array<int|string, mixed>
2121 */
22- private function getPanelsData (): array {
22+ private function getPanelsData (bool $ command_stats = false ): array {
2323 try {
2424 if (class_exists (PHPMem::class)) {
2525 $ title = 'PHPMem v ' .PHPMem::VERSION ;
@@ -29,7 +29,7 @@ private function getPanelsData(): array {
2929
3030 $ memory_usage = ($ info ['limit_maxbytes ' ] > 0 ) ? round (($ info ['bytes ' ] / $ info ['limit_maxbytes ' ]) * 100 , 2 ) : 0 ;
3131
32- return [
32+ $ stats = [
3333 [
3434 'title ' => $ title ?? null ,
3535 'moreinfo ' => true ,
@@ -66,6 +66,12 @@ private function getPanelsData(): array {
6666 ],
6767 ],
6868 ];
69+
70+ if ($ command_stats ) {
71+ $ stats = array_merge ($ stats , $ this ->commandsStatsData ($ info ));
72+ }
73+
74+ return $ stats ;
6975 } catch (MemcachedException $ e ) {
7076 return ['error ' => $ e ->getMessage ()];
7177 }
@@ -313,82 +319,90 @@ private function keysTreeView(array $keys): array {
313319 return $ tree ;
314320 }
315321
316- private function commandsStats (): string {
317- try {
318- $ info = $ this ->memcached ->getServerStats ();
319-
320- $ rate = (static fn (int $ hits , int $ total ): float => $ hits !== 0 ? round (($ hits / $ total ) * 100 , 2 ) : 0 );
321-
322- $ get_hit_rate = $ rate ($ info ['get_hits ' ], $ info ['cmd_get ' ]);
323- $ delete_hit_rate = $ rate ($ info ['delete_hits ' ], $ info ['delete_hits ' ] + $ info ['delete_misses ' ]);
324- $ incr_hit_rate = $ rate ($ info ['incr_hits ' ], $ info ['incr_hits ' ] + $ info ['incr_misses ' ]);
325- $ decr_hit_rate = $ rate ($ info ['decr_hits ' ], $ info ['decr_hits ' ] + $ info ['decr_misses ' ]);
326- $ cas_hit_rate = $ rate ($ info ['cas_hits ' ], $ info ['cas_hits ' ] + $ info ['cas_misses ' ]);
327- $ touch_hit_rate = $ rate ($ info ['touch_hits ' ], $ info ['cmd_touch ' ]);
328-
329- $ commands = [
330- [
331- 'title ' => 'get ' ,
332- 'data ' => [
333- 'Hits ' => Format::number ($ info ['get_hits ' ]),
334- 'Misses ' => Format::number ($ info ['get_misses ' ]),
335- ['Hit Rate ' , $ get_hit_rate .'% ' , $ get_hit_rate , 'higher ' ],
336- ],
322+ /**
323+ * @param array<int|string, mixed> $info
324+ *
325+ * @return array<int|string, mixed>
326+ */
327+ private function commandsStatsData (array $ info ): array {
328+ $ rate = (static fn (int $ hits , int $ total ): float => $ hits !== 0 ? round (($ hits / $ total ) * 100 , 2 ) : 0 );
329+
330+ $ get_hit_rate = $ rate ($ info ['get_hits ' ], $ info ['cmd_get ' ]);
331+ $ delete_hit_rate = $ rate ($ info ['delete_hits ' ], $ info ['delete_hits ' ] + $ info ['delete_misses ' ]);
332+ $ incr_hit_rate = $ rate ($ info ['incr_hits ' ], $ info ['incr_hits ' ] + $ info ['incr_misses ' ]);
333+ $ decr_hit_rate = $ rate ($ info ['decr_hits ' ], $ info ['decr_hits ' ] + $ info ['decr_misses ' ]);
334+ $ cas_hit_rate = $ rate ($ info ['cas_hits ' ], $ info ['cas_hits ' ] + $ info ['cas_misses ' ]);
335+ $ touch_hit_rate = $ rate ($ info ['touch_hits ' ], $ info ['cmd_touch ' ]);
336+
337+ return [
338+ [
339+ 'title ' => 'get ' ,
340+ 'data ' => [
341+ 'Hits ' => Format::number ($ info ['get_hits ' ]),
342+ 'Misses ' => Format::number ($ info ['get_misses ' ]),
343+ ['Hit Rate ' , $ get_hit_rate .'% ' , $ get_hit_rate , 'higher ' ],
337344 ],
338- [
339- ' title ' => ' delete ' ,
340- ' data ' => [
341- ' Hits ' => Format:: number ( $ info [ ' delete_hits ' ]),
342- ' Misses ' => Format::number ($ info ['delete_misses ' ]),
343- [ ' Hit Rate ' , $ delete_hit_rate . ' % ' , $ delete_hit_rate , ' higher ' ] ,
344- ],
345+ ],
346+ [
347+ ' title ' => ' delete ' ,
348+ ' data ' => [
349+ ' Hits ' => Format::number ($ info ['delete_hits ' ]),
350+ ' Misses ' => Format:: number ( $ info [ ' delete_misses ' ]) ,
351+ [ ' Hit Rate ' , $ delete_hit_rate . ' % ' , $ delete_hit_rate , ' higher ' ],
345352 ],
346- [
347- ' title ' => ' incr ' ,
348- ' data ' => [
349- ' Hits ' => Format:: number ( $ info [ ' incr_hits ' ]),
350- ' Misses ' => Format::number ($ info ['incr_misses ' ]),
351- [ ' Hit Rate ' , $ incr_hit_rate . ' % ' , $ incr_hit_rate , ' higher ' ] ,
352- ],
353+ ],
354+ [
355+ ' title ' => ' incr ' ,
356+ ' data ' => [
357+ ' Hits ' => Format::number ($ info ['incr_hits ' ]),
358+ ' Misses ' => Format:: number ( $ info [ ' incr_misses ' ]) ,
359+ [ ' Hit Rate ' , $ incr_hit_rate . ' % ' , $ incr_hit_rate , ' higher ' ],
353360 ],
354- [
355- ' title ' => ' decr ' ,
356- ' data ' => [
357- ' Hits ' => Format:: number ( $ info [ ' decr_hits ' ]),
358- ' Misses ' => Format::number ($ info ['decr_misses ' ]),
359- [ ' Hit Rate ' , $ decr_hit_rate . ' % ' , $ decr_hit_rate , ' higher ' ] ,
360- ],
361+ ],
362+ [
363+ ' title ' => ' decr ' ,
364+ ' data ' => [
365+ ' Hits ' => Format::number ($ info ['decr_hits ' ]),
366+ ' Misses ' => Format:: number ( $ info [ ' decr_misses ' ]) ,
367+ [ ' Hit Rate ' , $ decr_hit_rate . ' % ' , $ decr_hit_rate , ' higher ' ],
361368 ],
362- [
363- ' title ' => ' touch ' ,
364- ' data ' => [
365- ' Hits ' => Format:: number ( $ info [ ' touch_hits ' ]),
366- ' Misses ' => Format::number ($ info ['touch_misses ' ]),
367- [ ' Hit Rate ' , $ touch_hit_rate . ' % ' , $ touch_hit_rate , ' higher ' ] ,
368- ],
369+ ],
370+ [
371+ ' title ' => ' touch ' ,
372+ ' data ' => [
373+ ' Hits ' => Format::number ($ info ['touch_hits ' ]),
374+ ' Misses ' => Format:: number ( $ info [ ' touch_misses ' ]) ,
375+ [ ' Hit Rate ' , $ touch_hit_rate . ' % ' , $ touch_hit_rate , ' higher ' ],
369376 ],
370- [
371- ' title ' => ' cas ' ,
372- ' data ' => [
373- ' Hits ' => Format:: number ( $ info [ ' cas_hits ' ]),
374- ' Misses ' => Format::number ($ info ['cas_misses ' ]),
375- [ ' Hit Rate ' , $ cas_hit_rate . ' % ' , $ cas_hit_rate , ' higher ' ] ,
376- ' Bad Value ' => $ info [ ' cas_badval ' ],
377- ],
377+ ],
378+ [
379+ ' title ' => ' cas ' ,
380+ ' data ' => [
381+ ' Hits ' => Format::number ($ info ['cas_hits ' ]),
382+ ' Misses ' => Format:: number ( $ info [ ' cas_misses ' ]) ,
383+ [ ' Hit Rate ' , $ cas_hit_rate . ' % ' , $ cas_hit_rate , ' higher ' ],
384+ ' Bad Value ' => $ info [ ' cas_badval ' ],
378385 ],
379- [
380- ' title ' => ' set ' ,
381- ' data ' => [
382- ' Total ' => Format:: number ( $ info [ ' cmd_set ' ]),
383- ] ,
386+ ],
387+ [
388+ ' title ' => ' set ' ,
389+ ' data ' => [
390+ ' Total ' => Format:: number ( $ info [ ' cmd_set ' ]) ,
384391 ],
385- [
386- ' title ' => ' flush ' ,
387- ' data ' => [
388- ' Total ' => Format:: number ( $ info [ ' cmd_flush ' ]),
389- ] ,
392+ ],
393+ [
394+ ' title ' => ' flush ' ,
395+ ' data ' => [
396+ ' Total ' => Format:: number ( $ info [ ' cmd_flush ' ]) ,
390397 ],
391- ];
398+ ],
399+ ];
400+ }
401+
402+ private function commandsStats (): string {
403+ try {
404+ $ info = $ this ->memcached ->getServerStats ();
405+ $ commands = $ this ->commandsStatsData ($ info );
392406 } catch (MemcachedException $ e ) {
393407 $ commands = ['error ' => $ e ->getMessage ()];
394408 }
0 commit comments