Skip to content

Commit

Permalink
Add more info to panels and progressbars
Browse files Browse the repository at this point in the history
  • Loading branch information
RobiNN1 committed Oct 13, 2024
1 parent 4a39cc8 commit e3260c0
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 80 deletions.
70 changes: 51 additions & 19 deletions assets/css/styles.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
.shadow, .shadow-lg {
--tw-ring-offset-shadow: 0 0 #0000;
--tw-ring-shadow: 0 0 #0000;
--tw-shadow: 0 0 #0000;
--tw-shadow-colored: 0 0 #0000;
}

.focus\:ring {
--tw-ring-inset: ;
--tw-ring-offset-width: 0px;
--tw-ring-offset-color: #fff;
--tw-ring-color: rgb(59 130 246 / 0.5);
--tw-ring-offset-shadow: 0 0 #0000;
--tw-ring-shadow: 0 0 #0000;
--tw-shadow: 0 0 #0000;
--tw-shadow-colored: 0 0 #0000;
}

/*
! tailwindcss v3.4.10 | MIT License | https://tailwindcss.com
! tailwindcss v3.4.13 | MIT License | https://tailwindcss.com
*/

/*
Expand Down Expand Up @@ -464,24 +482,6 @@ video {
--link-active-dark: #0f172a;
}

.shadow, .shadow-lg {
--tw-ring-offset-shadow: 0 0 #0000;
--tw-ring-shadow: 0 0 #0000;
--tw-shadow: 0 0 #0000;
--tw-shadow-colored: 0 0 #0000;
}

.focus\:ring {
--tw-ring-inset: ;
--tw-ring-offset-width: 0px;
--tw-ring-offset-color: #fff;
--tw-ring-color: rgb(59 130 246 / 0.5);
--tw-ring-offset-shadow: 0 0 #0000;
--tw-ring-shadow: 0 0 #0000;
--tw-shadow: 0 0 #0000;
--tw-shadow-colored: 0 0 #0000;
}

.fixed {
position: fixed;
}
Expand Down Expand Up @@ -519,6 +519,10 @@ video {
margin-top: -0.375rem;
}

.mb-0\.5 {
margin-bottom: 0.125rem;
}

.mb-2 {
margin-bottom: 0.5rem;
}
Expand Down Expand Up @@ -568,6 +572,10 @@ video {
height: 2.25rem;
}

.h-1\.5 {
height: 0.375rem;
}

.h-4 {
height: 1rem;
}
Expand Down Expand Up @@ -636,6 +644,10 @@ video {
appearance: none;
}

.flex-col {
flex-direction: column;
}

.flex-wrap {
flex-wrap: wrap;
}
Expand Down Expand Up @@ -763,6 +775,10 @@ video {
background-color: #3b82f6;
}

.bg-gray-200 {
background-color: #e5e7eb;
}

.bg-gray-50 {
background-color: #f9fafb;
}
Expand All @@ -771,6 +787,10 @@ video {
background-color: #22c55e;
}

.bg-green-600 {
background-color: #16a34a;
}

.bg-indigo-500 {
background-color: #6366f1;
}
Expand All @@ -779,6 +799,10 @@ video {
background-color: #f97316;
}

.bg-orange-600 {
background-color: #ea580c;
}

.bg-primary-500 {
background-color: var(--primary-color-500);
}
Expand All @@ -791,6 +815,10 @@ video {
background-color: #ef4444;
}

.bg-red-600 {
background-color: #dc2626;
}

.bg-sky-500 {
background-color: #0ea5e9;
}
Expand Down Expand Up @@ -1257,6 +1285,10 @@ video {
background-color: #1d4ed8;
}

.dark\:bg-gray-700:is(.dark *) {
background-color: #374151;
}

.dark\:bg-gray-800:is(.dark *) {
background-color: #1f2937;
}
Expand Down
20 changes: 11 additions & 9 deletions src/Dashboards/APCu/APCuTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ private function panels(): string {
$memory_info = apcu_sma_info(true);

$total_memory = $memory_info['num_seg'] * $memory_info['seg_size'];
$memory_used = ($memory_info['num_seg'] * $memory_info['seg_size']) - $memory_info['avail_mem'];
$memory_usage_percentage = round(($memory_used / $total_memory) * 100, 2);
$memory_used = $total_memory - $memory_info['avail_mem'];
$memory_usage = round(($memory_used / $total_memory) * 100, 2);

$hit_rate = (int) $info['num_hits'] !== 0 ? $info['num_hits'] / ($info['num_hits'] + $info['num_misses']) : 0;
$num_hits = (int) $info['num_hits'];
$num_misses = (int) $info['num_misses'];
$hit_rate = $num_hits !== 0 ? round(($num_hits / ($num_hits + $num_misses)) * 100, 2) : 0;

$panels = [
[
Expand All @@ -39,19 +41,19 @@ private function panels(): string {
[
'title' => 'Memory',
'data' => [
'Type' => $info['memory_type'].' - '.$memory_info['num_seg'].' segment(s) * '.Format::bytes((int) $memory_info['seg_size'], 0),
'Type' => $info['memory_type'].' - '.$memory_info['num_seg'].' segment(s)',
'Total' => Format::bytes((int) $total_memory, 0),
'Used' => Format::bytes((int) $memory_used).' ('.$memory_usage_percentage.'%)',
['Used', Format::bytes((int) $memory_used).' ('.$memory_usage.'%)', $memory_usage],
'Free' => Format::bytes((int) $memory_info['avail_mem']),
],
],
[
'title' => 'Stats',
'data' => [
'Slots' => $info['num_slots'],
'Keys' => Format::number((int) $info['num_entries']),
'Hits / Misses' => Format::number((int) $info['num_hits']).' / '.Format::number((int) $info['num_misses']).
' (Rate '.round($hit_rate * 100, 2).'%)',
'Slots' => $info['num_slots'],
'Keys' => Format::number((int) $info['num_entries']),
['Hits / Misses', Format::number($num_hits).' / '.Format::number($num_misses).' (Rate '.$hit_rate.'%)', $hit_rate, 'higher'],
'Expunges' => Format::number((int) $info['expunges']),
],
],
];
Expand Down
4 changes: 2 additions & 2 deletions src/Dashboards/Memcached/Compatibility/Memcache.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ public function __construct(protected array $server = []) {
}

public function isConnected(): bool {
// Need to be silenced since Memcache doesn't throw exceptions...
$stats = @$this->getStats();
$stats = $this->getServerStats();

return isset($stats['pid']) && $stats['pid'] > 0;
}
Expand All @@ -33,6 +32,7 @@ public function isConnected(): bool {
* @return array<string, mixed>
*/
public function getServerStats(): array {
// Need to be silenced since Memcache doesn't throw exceptions...
return (array) @$this->getStats();
}

Expand Down
37 changes: 30 additions & 7 deletions src/Dashboards/Memcached/MemcachedTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,48 @@ private function panels(): string {
}

try {
$server_info = $this->memcached->getServerStats();
$info = $this->memcached->getServerStats();

$bytes = (int) $info['bytes'];
$max_bytes = (int) $info['limit_maxbytes'];
$get_hits = (int) $info['get_hits'];
$get_misses = (int) $info['get_misses'];
$memory_usage = round(($bytes / $max_bytes) * 100, 2);
$hit_rate = $get_hits !== 0 ? round(($get_hits / ($get_hits + $get_misses)) * 100, 2) : 0;

$panels = [
[
'title' => $title ?? null,
'moreinfo' => true,
'server_id' => $this->current_server,
'data' => [
'Version' => $server_info['version'],
'Open connections' => $server_info['curr_connections'],
'Uptime' => Format::seconds((int) $server_info['uptime']),
'Version' => $info['version'],
'Open connections' => $info['curr_connections'],
'Uptime' => Format::seconds((int) $info['uptime']),
],
],
[
'title' => 'Memory',
'data' => [
'Total' => Format::bytes($max_bytes, 0),
['Used', Format::bytes($bytes).' ('.$memory_usage.'%)', $memory_usage],
'Free' => Format::bytes($max_bytes - $bytes),
],
],
[
'title' => 'Stats',
'data' => [
'Cache limit' => Format::bytes((int) $server_info['limit_maxbytes'], 0),
'Used' => Format::bytes((int) $server_info['bytes']),
'Keys' => Format::number(count($this->all_keys)), // Keys are loaded via sockets and not extension itself
'Keys' => Format::number(count($this->all_keys)),
['Hits / Misses', Format::number($get_hits).' / '.Format::number($get_misses).' (Rate '.$hit_rate.'%)', $hit_rate, 'higher'],
'Evictions' => Format::number((int) $info['evictions']),
],
],
[
'title' => 'Connections',
'data' => [
'Current' => Format::number((int) $info['curr_connections']).' / '.Format::number((int) $info['max_connections']),
'Total' => Format::number((int) $info['total_connections']),
'Rejected' => Format::number((int) $info['rejected_connections']),
],
],
];
Expand Down
57 changes: 29 additions & 28 deletions src/Dashboards/OPCache/OPCacheTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,33 @@ private function panels(): string {

$stats = $status['opcache_statistics'];

$total_memory = $configuration['directives']['opcache.memory_consumption'];
$memory = $status['memory_usage'];
$memory_usage = ($memory['used_memory'] + $memory['wasted_memory']) / $total_memory;
$memory_usage_percentage = round($memory_usage * 100, 2);
$total_memory = $configuration['directives']['opcache.memory_consumption'];
$memory_usage = round((($memory['used_memory'] + $memory['wasted_memory']) / $total_memory) * 100, 2);
$memory_wasted = round($memory['current_wasted_percentage'], 2);

$interned_strings = $status['interned_strings_usage'];
$interned_usage = $interned_strings['used_memory'] / $interned_strings['buffer_size'];
$interned_usage_percentage = round($interned_usage * 100, 2);
$interned_usage = round(($interned_strings['used_memory'] / $interned_strings['buffer_size']) * 100, 2);

$used_keys_percentage = round(($stats['num_cached_keys'] / $stats['max_cached_keys']) * 100);
$used_scripts = round(($stats['num_cached_scripts'] / (int) ini_get('opcache.max_accelerated_files')) * 100);
$used_keys = round(($stats['num_cached_keys'] / $stats['max_cached_keys']) * 100);
$hit_rate = round($stats['opcache_hit_rate'], 2);

$jit_enabled = false;
$jit_enabled = isset($status['jit']['enabled']) && $status['jit']['buffer_size'] > 0;
$jit_info = [];

if (isset($status['jit']['enabled']) && $status['jit']['buffer_size'] > 0) {
$jit_enabled = true;
if ($jit_enabled) {
$jit = $status['jit'];
$jit_used = $jit['buffer_size'] - $jit['buffer_free'];
$jit_usage = $jit_used / $jit['buffer_size'];
$jit_usage_percentage = round($jit_usage * 100, 2);
$jit_usage = round(($jit_used / $jit['buffer_size']) * 100, 2);

$jit_info = [
'title' => 'JIT',
'data' => [
'Buffer size' => Format::bytes($jit['buffer_size']),
'Used' => Format::bytes($jit_used).' ('.$jit_usage_percentage.'%)',
'Free' => Format::bytes($jit['buffer_free']),
'Buffer size' => Format::bytes($jit['buffer_size']),
['Used', Format::bytes($jit_used).' ('.$jit_usage.'%)', $jit_usage],
'Free' => Format::bytes($jit['buffer_free']),
'Optimization level' => $jit['optimization_level'],
],
];
}
Expand All @@ -56,38 +56,39 @@ private function panels(): string {
'title' => 'PHP OPCache extension v'.phpversion('Zend OPcache'),
'moreinfo' => true,
'data' => [
'JIT' => $jit_enabled ? 'Enabled' : 'Disabled',
'Start time' => Format::time($stats['start_time']),
'Uptime' => Format::seconds(time() - $stats['start_time']),
'Last restart' => Format::time($stats['last_restart_time']),
'Cache full' => $status['cache_full'] ? 'Yes' : 'No',
'JIT' => $jit_enabled ? 'Enabled' : 'Disabled',
'Start time' => Format::time($stats['start_time']),
'Uptime' => Format::seconds(time() - $stats['start_time']),
'Last restart' => Format::time($stats['last_restart_time']),
'Cache full' => $status['cache_full'] ? 'Yes' : 'No',
'Restart pending' => $status['restart_pending'] ? 'Yes' : 'No',
'Restart in progress' => $status['restart_in_progress'] ? 'Yes' : 'No',
],
],
[
'title' => 'Memory',
'data' => [
'Total' => Format::bytes($total_memory, 0),
'Used' => Format::bytes($memory['used_memory']).' ('.$memory_usage_percentage.'%)',
'Free' => Format::bytes($memory['free_memory']),
'Wasted' => Format::bytes($memory['wasted_memory']).' ('.round($memory['current_wasted_percentage'], 2).'%)',
'Total' => Format::bytes($total_memory, 0),
['Used', Format::bytes($memory['used_memory']).' ('.$memory_usage.'%)', $memory_usage],
'Free' => Format::bytes($memory['free_memory']),
['Wasted', Format::bytes($memory['wasted_memory']).' ('.$memory_wasted.'%)', $memory_wasted],
],
],
[
'title' => 'Stats',
'data' => [
'Cached scripts' => Format::number($stats['num_cached_scripts']),
'Cached keys' => Format::number($stats['num_cached_keys']).' ('.$used_keys_percentage.'%)',
['Cached scripts', Format::number($stats['num_cached_scripts']).' ('.$used_scripts.'%)', $used_scripts, 'higher'],
['Cached keys', Format::number($stats['num_cached_keys']).' ('.$used_keys.'%)', $used_keys, 'higher'],
'Max cached keys' => Format::number($stats['max_cached_keys']),
'Hits / Misses' => Format::number($stats['hits']).' / '.Format::number($stats['misses']).
' (Rate '.round($stats['opcache_hit_rate'], 2).'%)',
['Hits / Misses', Format::number($stats['hits']).' / '.Format::number($stats['misses']).' (Rate '.$hit_rate.'%)', $hit_rate, 'higher'],
],
],
$jit_info,
[
'title' => 'Interned strings usage',
'data' => [
'Buffer size' => Format::bytes($interned_strings['buffer_size']),
'Used' => Format::bytes($interned_strings['used_memory']).' ('.$interned_usage_percentage.'%)',
['Used', Format::bytes($interned_strings['used_memory']).' ('.$interned_usage.'%)', $interned_usage],
'Free' => Format::bytes($interned_strings['free_memory']),
'Strings' => Format::number($interned_strings['number_of_strings']),
],
Expand Down
4 changes: 2 additions & 2 deletions src/Dashboards/Realpath/RealpathTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ trait RealpathTrait {
private function panels(): string {
$total_memory = Format::iniSizeToBytes(ini_get('realpath_cache_size'));
$memory_used = realpath_cache_size();
$memory_usage_percentage = round(($memory_used / $total_memory) * 100, 2);
$memory_usage = round(($memory_used / $total_memory) * 100, 2);

$panels = [
[
'title' => 'Realpath info',
'data' => [
'Total' => Format::bytes($total_memory, 0),
'Used' => Format::bytes($memory_used).' ('.$memory_usage_percentage.'%)',
['Used', Format::bytes($memory_used).' ('.$memory_usage.'%)', $memory_usage],
],
],
[
Expand Down
Loading

0 comments on commit e3260c0

Please sign in to comment.