Skip to content

Commit

Permalink
Add support for selecting the retention period for live stats
Browse files Browse the repository at this point in the history
  • Loading branch information
iliajie committed Oct 27, 2024
1 parent 930d580 commit f5752d5
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 12 deletions.
2 changes: 1 addition & 1 deletion extensions/stats/stats.min.js

Large diffs are not rendered by default.

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 @@ -85,7 +85,7 @@ const stats = {
getInterval: function () {
return settings_sysinfo_real_time_run_rate / 1000;
},
// Get the stored data duration period (e.g., from 300 to 3600 seconds)
// Get the stored data duration period (e.g., from 300 to 86400 seconds)
getStoredDuration: function () {
return settings_sysinfo_real_time_stored_duration;
},
Expand Down Expand Up @@ -440,8 +440,8 @@ const stats = {
if (tg[0] && tg[0].textContent && cached !== 3) {
if (cached === 1) {
let lf = parseInt(this.getStoredDuration());
if (lf < 300 || lf > 3600) {
lf = 600;
if (lf < 300 || lf > 86400) {
lf = 1200;
}
let tdata = sr,
cdata = this[`chart_${type}`].data.series,
Expand Down
8 changes: 8 additions & 0 deletions lang/en
Original file line number Diff line number Diff line change
Expand Up @@ -1482,3 +1482,11 @@ theme_xhred_dashboard_chart_disk_write=Write
theme_xhred_dashboard_chart_net_read=In
theme_xhred_dashboard_chart_net_write=Out
theme_xhred_tooltip_dashboard_live_stats_offline=Live stats aren’t available when the system is accessed in proxy mode; only previously collected stats will be displayed, and only if available, and the page will need to be reloaded to update these stats
settings_sysinfo_real_time_status_history1=Yes, and store stats for
settings_sysinfo_real_time_status_history2=Yes, without storing stats
settings_sysinfo_real_time_status_history_duration1=20 minutes
settings_sysinfo_real_time_status_history_duration2=1 hour
settings_sysinfo_real_time_status_history_duration3=6 hours
settings_sysinfo_real_time_status_history_duration4=12 hours
settings_sysinfo_real_time_status_history_duration5=18 hours
settings_sysinfo_real_time_status_history_duration6=24 hours
6 changes: 3 additions & 3 deletions stats-lib-funcs.pl
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ sub trim_stats_history
my $default = get_stats_empty();
return $default->{'graphs'}{$key};
};
my $n = get_stats_option('stored_duration', 1) || 600;
if ($n < 300 || $n > 3600) {
$n = 600;
my $n = get_stats_option('stored_duration', 1) || 1200;
if ($n < 300 || $n > 86400) {
$n = 1200;
}
foreach my $k (keys %{$graphs}) {
my @new_array;
Expand Down
5 changes: 3 additions & 2 deletions stats.pl
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@
}
# Save stats to history and reset cache
if ($serv->{'ticked'}++ % 20 == 0) {
save_stats_history($stats_period);
save_stats_history($stats_period)
if (get_stats_option('status', 1) != 2);
undef($stats_period);
}
# If interval is set then sleep minus one
Expand All @@ -134,7 +135,7 @@
};
alarm(30);
# Set maximum send size
$conn->max_send_size(384 * 1024); # Sent data must never be more than 384 KB
$conn->max_send_size(9216 * 1024); # Max 9 MiB to accomodate 24h of data
# Handle connection events
$conn->on(
utf8 => sub {
Expand Down
19 changes: 18 additions & 1 deletion tconfig-lib.pl
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ sub theme_settings_filter
'settings_sysinfo_easypie_charts_scale',
'settings_sysinfo_max_servers',
'settings_sysinfo_real_time_status',
'settings_sysinfo_real_time_stored_duration',
'settings_leftmenu_section_hide_refresh_modules',
'settings_leftmenu_section_hide_unused_modules',
'settings_leftmenu_netdata',
Expand Down Expand Up @@ -565,7 +566,23 @@ sub theme_settings_format
} elsif ($k eq 'settings_document_title') {
$v = settings_get_select_document_title($v, $k);
} elsif ($k eq 'settings_sysinfo_real_time_status') {
$v = ui_radio($k, $v, [[1, $text{'yes'}], [0, $text{'no'}]]);
my $realtime = 'settings_sysinfo_real_time_';
my $realtime_pref = "${realtime}status_";
my $duration_key = "${realtime}stored_duration";
my $select = ui_select($duration_key, $theme_config{$duration_key},
[
[(1200, $theme_text{"${realtime_pref}history_duration1"})],
[(3600, $theme_text{"${realtime_pref}history_duration2"})],
[(21600, $theme_text{"${realtime_pref}history_duration3"})],
[(43200, $theme_text{"${realtime_pref}history_duration4"})],
[(64800, $theme_text{"${realtime_pref}history_duration5"})],
[(86400, $theme_text{"${realtime_pref}history_duration6"})]
]);
$v = ui_radio($k, $v, [
[1, $theme_text{"${realtime_pref}history1"}.$select],
[2, $theme_text{"${realtime_pref}history2"}],
[0, $text{'no'}]
]);
} elsif ($k eq 'settings_right_table_links_type') {
$v = ui_radio($k,
$v,
Expand Down
2 changes: 1 addition & 1 deletion unauthenticated/css/bundle.min.css

Large diffs are not rendered by default.

Binary file modified unauthenticated/css/bundle.min.css.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion unauthenticated/js/bundle.min.js

Large diffs are not rendered by default.

Binary file modified unauthenticated/js/bundle.min.js.gz
Binary file not shown.

0 comments on commit f5752d5

Please sign in to comment.