Skip to content

Commit

Permalink
Fix to further optimize stats performance and drop options
Browse files Browse the repository at this point in the history
  • Loading branch information
iliajie committed Jun 26, 2024
1 parent f4b47c9 commit 7b0dd20
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 45 deletions.
1 change: 0 additions & 1 deletion authentic-lib.pl
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ sub get_extended_sysinfo
}
if (&webmin_user_is_admin() &&
$theme_config{'settings_sysinfo_real_time_status'} ne '0' &&
$theme_config{'settings_sysinfo_real_time_stored'} ne 'false' &&
(acl_system_status('cpu') || acl_system_status('mem') || acl_system_status('load')))
{
my $data = '<div data-charts-loader class="text-muted loading-dots flex-center">
Expand Down
2 changes: 1 addition & 1 deletion extensions/stats/stats.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified extensions/stats/stats.min.js.gz
Binary file not shown.
6 changes: 3 additions & 3 deletions extensions/stats/stats.src.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ const stats = {
this.socket = new WebSocket(data.socket);
this.socket.onopen = () => {
this.activating = 0;
// console.log("WebSocket connection established");
console.log("WebSocket connection established", this.getSocketDefs());
this.socket.send(JSON.stringify(this.getSocketDefs()));
};
this.socket.onmessage = (event) => {
const message = JSON.parse(event.data);
this.render(message);
// console.log("Received stats:", message);
console.log("Received stats:", message);
this.active() && this.fetch();
};
this.socket.onclose = () => {
Expand Down Expand Up @@ -287,7 +287,7 @@ const stats = {
if (tg[0] && tg[0].textContent) {
if (cached === 1) {
let lf = parseInt(this.stored_length());
if (lf < 300 || lf > 86400) {
if (lf < 300 || lf > 3600) {
lf = 600;
}
let tdata = sr,
Expand Down
2 changes: 0 additions & 2 deletions lang/en
Original file line number Diff line number Diff line change
Expand Up @@ -1093,8 +1093,6 @@ theme_xhred_global_today=Today
theme_xhred_global_tomorrow=Tomorrow
theme_xhred_mail_composer_scheduled=Send %1 at %2
theme_global_core=Core
settings_sysinfo_real_time_stored=Enable stats history
settings_sysinfo_real_time_stored_description=If enabled, previously gathered stats will be stored, and displayed in a graph on the Dashboard
theme_dashboard_accordion_live_stats=Stats History
theme_xhred_live_stats_cpu=CPU
theme_xhred_live_stats_mem=Real Memory
Expand Down
57 changes: 27 additions & 30 deletions stats-lib.pl
Original file line number Diff line number Diff line change
Expand Up @@ -57,41 +57,38 @@ sub stats

# Save and return data
if (!$k) {
if (get_stats_option('stored')) {

# Clear existing cache if available features was disabled
my %map = (cpu => ['cpu', 'disk'],
mem => ['mem', 'virt'],
load => ['proc', 'net']);

foreach my $key (keys %map) {
my $feature = acl_system_status($key);
if (ref($map{$key}) eq 'ARRAY') {
foreach my $skey (@{ $map{$key} }) {
if (!$feature) {
delete $cdata->{$skey};
}
}
} else {
# Clear existing cache if available features was disabled
my %map = (cpu => ['cpu', 'disk'],
mem => ['mem', 'virt'],
load => ['proc', 'net']);

foreach my $key (keys %map) {
my $feature = acl_system_status($key);
if (ref($map{$key}) eq 'ARRAY') {
foreach my $skey (@{ $map{$key} }) {
if (!$feature) {
delete $cdata->{ $map{$key} };
delete $cdata->{$skey};
}
}
} else {
if (!$feature) {
delete $cdata->{ $map{$key} };
}
}
}

# Store complete dataset every 20th tick
if ($ticked > 0 && $ticked % 20 == 0) {
lock_file($fdata);
write_file_contents($fdata, convert_to_json($cdata));
unlock_file($fdata);
}
# Store complete dataset every 20th tick
if ($ticked > 0 && $ticked % 20 == 0) {
lock_file($fdata);
write_file_contents($fdata, convert_to_json($cdata));
unlock_file($fdata);
}

# Return requested data
if ($history) {
$data{'_history'} = $cdata;
} else {
$data{'_current'} = $tdata;
}
# Return requested data
if ($history) {
$data{'_history'} = $cdata;
} else {
$data{'_current'} = $tdata;
}
return;
}
Expand All @@ -108,7 +105,7 @@ sub stats
my $n = get_stats_option('stored_length', 1) || 600;

# User option sanity check
if ($n < 300 || $n > 86400) {
if ($n < 300 || $n > 3600) {
$n = 600;
}

Expand Down
Loading

0 comments on commit 7b0dd20

Please sign in to comment.