Skip to content

Commit

Permalink
Add real-time monitoring #896
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilia Rostovtsev committed Nov 27, 2017
1 parent 2c7e2ed commit 42efbd0
Show file tree
Hide file tree
Showing 28 changed files with 332 additions and 6 deletions.
7 changes: 6 additions & 1 deletion authentic-lib.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2137,6 +2137,10 @@ sub _settings

'__',
_settings('fa', 'info-circle', &Atext('settings_right_sysinfo_page_options_title')),
'settings_sysinfo_real_time_status',
'true',
'settings_sysinfo_real_time_timeout',
'500',
'settings_sysinfo_easypie_charts',
'true',
'settings_sysinfo_easypie_charts_size',
Expand Down Expand Up @@ -2324,6 +2328,7 @@ sub _settings
$k eq 'settings_hotkey_sysinfo' ||
$k eq 'settings_hotkey_favorites' ||
$k eq 'settings_side_slider_background_refresh_time' ||
$k eq 'settings_sysinfo_real_time_timeout' ||
$k eq 'settings_sysinfo_easypie_charts_size' ||
$k eq 'settings_sysinfo_easypie_charts_width' ||
$k eq 'settings_sysinfo_easypie_charts_scale')
Expand All @@ -2341,7 +2346,7 @@ sub _settings
$k eq 'settings_sysinfo_easypie_charts_width' ||
$k eq 'settings_sysinfo_easypie_charts_scale') ?
' width: 36px; ' :
($k eq 'settings_sysinfo_easypie_charts_size' ? ' width: 48px; ' : ' width: 95%; ');
(($k eq 'settings_sysinfo_real_time_timeout' || $k eq 'settings_sysinfo_easypie_charts_size') ? ' width: 48px; ' : ' width: 95%; ');
my $max_length =
($k =~ /settings_hotkey_toggle_key_/ ||
$k eq 'settings_hotkey_focus_search' ||
Expand Down
53 changes: 53 additions & 0 deletions extensions/init.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#
# Authentic Theme (https://github.com/qooob/authentic-theme)
# Copyright Ilia Rostovtsev <[email protected]>
# Licensed under MIT (https://github.com/qooob/authentic-theme/blob/master/LICENSE)
#

BEGIN {push(@INC, "..");}
use WebminCore;
use lib (dirname(__FILE__) . '/../lib');
use JSON qw( decode_json );

ReadParse();

our %config = ();
read_file_cached(get_env('webmin_config') . "/config", \%config);

sub get_env
{
my ($key) = @_;
return $ENV{ uc($key) };
}

sub get_env_local_path
{
my ($system, $path) = @_;
if ($system eq 'freebsd') {
return "/usr/local/$path/";
}

}

sub enforce_command
{
my ($system, $command) = @_;
if (!has_command($command)) {
if ($system eq 'freebsd') {
backquote_logged("pkg install -y $command 2>&1 </dev/null");
}
}
}

sub get_json
{
return JSON->new->latin1->encode(@_);
}

sub print_json
{
print "Content-type: text/html\n\n";
print get_json(@_);
}

1;
62 changes: 62 additions & 0 deletions extensions/stats/stats.cgi
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#
# Authentic Theme (https://github.com/qooob/authentic-theme)
# Copyright Ilia Rostovtsev <[email protected]>
# Licensed under MIT (https://github.com/qooob/authentic-theme/blob/master/LICENSE)
#

use File::Basename;
require(dirname(__FILE__) . '/../init.pm');

my %data;
if ($in{'xhr-stats'} =~ /[[:alpha:]]/) {
my $target = $in{'xhr-stats'};
if ($target eq 'general') {
my $os = $config{'os_type'};
if ($os =~ /-linux$/ || $os eq 'freebsd') {

# CPU stats
my $cpu = backquote_command("vmstat 1 2 2>/dev/null");
if (!$?) {
my @lines = split(/\r?\n/, $cpu);
my @w = split(/\s+/, $lines[$#lines]);
!length($w[0]) && shift(@w);
if ($os =~ /-linux$/) {
if ($w[8] =~ /^\d+$/ && $w[9] =~ /^\d+$/) {
$data{'io'} = [$w[8], $w[9]];
$data{'cpu'} = int($w[12]);
}
} else {
$data{'cpu'} = int($w[16]);
}
}

# Memory stats
my $memory = 'free';
if ($os eq 'freebsd') {
$memory .= 'color';
enforce_command($os, $memory);
$memory = get_env_local_path($os, 'bin') . $memory . ' -o';
}

my $memory = backquote_command($memory);
if (!$?) {
my @lines = split(/\s+/, $memory);
if ($lines[8] =~ /^\d+$/ && $lines[9] =~ /^\d+$/) {
$data{'mem'} =
[($lines[9] / $lines[8]) * 100, [nice_size(int($lines[8]* 1024 )), nice_size(int($lines[9]* 1024 ))]];
}
if ($lines[15] =~ /^\d+$/ && $lines[16] =~ /^\d+$/) {
$data{'virt'} =
[($lines[16] / $lines[15]) * 100, [nice_size(int($lines[15]* 1024 ) ), nice_size(int($lines[16]* 1024 ))]];
}
}

# Load average
my $load_average = backquote_command("uptime 2>&1");
$data{'cpu'} = [$data{'cpu'},
($load_average =~ /average(s)?:\s+([0-9\.]+),?\s+([0-9\.]+),?\s+([0-9\.]+)/i ? [$2, $3, $4] : [])];

}
}
}
print_json(\%data);
Empty file added extensions/stats/stats.min.css
Empty file.
7 changes: 7 additions & 0 deletions extensions/stats/stats.min.js

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

Empty file added extensions/stats/stats.src.css
Empty file.
91 changes: 91 additions & 0 deletions extensions/stats/stats.src.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*!
* Authentic Theme (https://github.com/qooob/authentic-theme)
* Copyright Ilia Rostovtsev <[email protected]>
* Licensed under MIT (https://github.com/qooob/authentic-theme/blob/master/LICENSE)
*/

/* jshint esversion: 6 */
/* jshint jquery: true */

// Register statistics object
const stats = {
general: {
timeout: 500,
stopped: 1,
call: {},

// Get data
query: function() {

// Repeat right after success
this.stopped && (() => {
this.stopped = 0;
this.call = {};

this.call = $.ajax({
context: this,
url: v___server_extensions_path + "/stats/stats.cgi?xhr-stats=general",
success: function(data) {

// Take half a second delay, render and restart
setTimeout(() => {
this.render(data);
}, this.timeout);

this.stopped = 1;
},
dataType: "json",
})
})();
},

// Display changes
render: function(data) {

// Iterate through response
Object.entries(data).map(([target, data]) => {
let v = parseInt(data),
$pc = $('#system-status .piechart[data-charts*="' + target + '"]'),
$lc = $('.info-container .' + target + '_percent');

if (Number.isInteger(v)) {

// Update pie-charts
if ($pc.length) {
$pc.data('easyPieChart').update(v);
}

// Update line-charts
if ($lc.length) {
$lc.find('.bar').attr('style', 'width:' + v + '%');

// Update line-charts' text
let $dp = $lc.find('.description'),
$tx = $dp.text().split(/\s+/),
$ts;

$.each($tx, function(id, vd) {
if (vd.includes(':')) {
$tx[id + 1] = (v + '%');
$ts = id;
}
})
$dp.text($tx.join(' ')).attr('title', $tx.splice($ts + 2, Infinity).join(' ').slice(1, -1));
}
}
})
this.query();
},

// Stop querying
kill: function() {
let abort = this.call.abort;

typeof abort === "function" && (abort.call(), this.stopped = 0);

setTimeout(() => {
this.stopped = 1, this.call = {};
}, this.timeout + 2);
}
}
}
6 changes: 6 additions & 0 deletions lang/ca.UTF-8
Original file line number Diff line number Diff line change
Expand Up @@ -753,3 +753,9 @@ theme_xhred_signing_in=Signing in
theme_xhred_signing_success=Successfully signed in!
theme_xhred_session_failed_password=Wrong password, please try again.
theme_xhred_global_reauthenticate=Reauthenticate


#19.04
settings_sysinfo_real_time_status=Enable real-time monitoring
settings_sysinfo_real_time_timeout=Interval for performing update
settings_sysinfo_real_time_timeout_description=Set desired interval for updating monitors in background. The value meant to be in milliseconds. Keep this value as low as possible to prevent loss of short-term data.
6 changes: 6 additions & 0 deletions lang/cz.UTF-8
Original file line number Diff line number Diff line change
Expand Up @@ -753,3 +753,9 @@ theme_xhred_signing_in=Signing in
theme_xhred_signing_success=Successfully signed in!
theme_xhred_session_failed_password=Wrong password, please try again.
theme_xhred_global_reauthenticate=Reauthenticate


#19.04
settings_sysinfo_real_time_status=Enable real-time monitoring
settings_sysinfo_real_time_timeout=Interval for performing update
settings_sysinfo_real_time_timeout_description=Set desired interval for updating monitors in background. The value meant to be in milliseconds. Keep this value as low as possible to prevent loss of short-term data.
6 changes: 6 additions & 0 deletions lang/da.UTF-8
Original file line number Diff line number Diff line change
Expand Up @@ -753,3 +753,9 @@ theme_xhred_signing_in=Signing in
theme_xhred_signing_success=Successfully signed in!
theme_xhred_session_failed_password=Wrong password, please try again.
theme_xhred_global_reauthenticate=Reauthenticate


#19.04
settings_sysinfo_real_time_status=Enable real-time monitoring
settings_sysinfo_real_time_timeout=Interval for performing update
settings_sysinfo_real_time_timeout_description=Set desired interval for updating monitors in background. The value meant to be in milliseconds. Keep this value as low as possible to prevent loss of short-term data.
6 changes: 6 additions & 0 deletions lang/de.UTF-8
Original file line number Diff line number Diff line change
Expand Up @@ -745,3 +745,9 @@ theme_xhred_signing_in=Signing in
theme_xhred_signing_success=Successfully signed in!
theme_xhred_session_failed_password=Wrong password, please try again.
theme_xhred_global_reauthenticate=Reauthenticate


#19.04
settings_sysinfo_real_time_status=Enable real-time monitoring
settings_sysinfo_real_time_timeout=Interval for performing update
settings_sysinfo_real_time_timeout_description=Set desired interval for updating monitors in background. The value meant to be in milliseconds. Keep this value as low as possible to prevent loss of short-term data.
6 changes: 6 additions & 0 deletions lang/en.UTF-8
Original file line number Diff line number Diff line change
Expand Up @@ -750,3 +750,9 @@ theme_xhred_signing_in=Signing in
theme_xhred_signing_success=Successfully signed in!
theme_xhred_session_failed_password=Wrong password, please try again.
theme_xhred_global_reauthenticate=Reauthenticate


#19.04
settings_sysinfo_real_time_status=Enable real-time monitoring
settings_sysinfo_real_time_timeout=Interval for performing update
settings_sysinfo_real_time_timeout_description=Set desired interval for updating monitors in background. The value meant to be in milliseconds. Keep this value as low as possible to prevent loss of short-term data.
6 changes: 6 additions & 0 deletions lang/es.UTF-8
Original file line number Diff line number Diff line change
Expand Up @@ -753,3 +753,9 @@ theme_xhred_signing_in=Signing in
theme_xhred_signing_success=Successfully signed in!
theme_xhred_session_failed_password=Wrong password, please try again.
theme_xhred_global_reauthenticate=Reauthenticate


#19.04
settings_sysinfo_real_time_status=Enable real-time monitoring
settings_sysinfo_real_time_timeout=Interval for performing update
settings_sysinfo_real_time_timeout_description=Set desired interval for updating monitors in background. The value meant to be in milliseconds. Keep this value as low as possible to prevent loss of short-term data.
6 changes: 6 additions & 0 deletions lang/fr.UTF-8
Original file line number Diff line number Diff line change
Expand Up @@ -753,3 +753,9 @@ theme_xhred_signing_in=Signing in
theme_xhred_signing_success=Successfully signed in!
theme_xhred_session_failed_password=Wrong password, please try again.
theme_xhred_global_reauthenticate=Reauthenticate


#19.04
settings_sysinfo_real_time_status=Enable real-time monitoring
settings_sysinfo_real_time_timeout=Interval for performing update
settings_sysinfo_real_time_timeout_description=Set desired interval for updating monitors in background. The value meant to be in milliseconds. Keep this value as low as possible to prevent loss of short-term data.
6 changes: 6 additions & 0 deletions lang/id.UTF-8
Original file line number Diff line number Diff line change
Expand Up @@ -755,3 +755,9 @@ theme_xhred_signing_in=Signing in
theme_xhred_signing_success=Successfully signed in!
theme_xhred_session_failed_password=Wrong password, please try again.
theme_xhred_global_reauthenticate=Reauthenticate


#19.04
settings_sysinfo_real_time_status=Enable real-time monitoring
settings_sysinfo_real_time_timeout=Interval for performing update
settings_sysinfo_real_time_timeout_description=Set desired interval for updating monitors in background. The value meant to be in milliseconds. Keep this value as low as possible to prevent loss of short-term data.
6 changes: 6 additions & 0 deletions lang/it.UTF-8
Original file line number Diff line number Diff line change
Expand Up @@ -753,3 +753,9 @@ theme_xhred_signing_in=Signing in
theme_xhred_signing_success=Successfully signed in!
theme_xhred_session_failed_password=Wrong password, please try again.
theme_xhred_global_reauthenticate=Reauthenticate


#19.04
settings_sysinfo_real_time_status=Enable real-time monitoring
settings_sysinfo_real_time_timeout=Interval for performing update
settings_sysinfo_real_time_timeout_description=Set desired interval for updating monitors in background. The value meant to be in milliseconds. Keep this value as low as possible to prevent loss of short-term data.
6 changes: 6 additions & 0 deletions lang/nl.UTF-8
Original file line number Diff line number Diff line change
Expand Up @@ -753,3 +753,9 @@ theme_xhred_signing_in=Signing in
theme_xhred_signing_success=Successfully signed in!
theme_xhred_session_failed_password=Wrong password, please try again.
theme_xhred_global_reauthenticate=Reauthenticate


#19.04
settings_sysinfo_real_time_status=Enable real-time monitoring
settings_sysinfo_real_time_timeout=Interval for performing update
settings_sysinfo_real_time_timeout_description=Set desired interval for updating monitors in background. The value meant to be in milliseconds. Keep this value as low as possible to prevent loss of short-term data.
6 changes: 6 additions & 0 deletions lang/no.UTF-8
Original file line number Diff line number Diff line change
Expand Up @@ -610,3 +610,9 @@ theme_xhred_signing_in=Signing in
theme_xhred_signing_success=Successfully signed in!
theme_xhred_session_failed_password=Wrong password, please try again.
theme_xhred_global_reauthenticate=Reauthenticate


#19.04
settings_sysinfo_real_time_status=Enable real-time monitoring
settings_sysinfo_real_time_timeout=Interval for performing update
settings_sysinfo_real_time_timeout_description=Set desired interval for updating monitors in background. The value meant to be in milliseconds. Keep this value as low as possible to prevent loss of short-term data.
6 changes: 6 additions & 0 deletions lang/pl.UTF-8
Original file line number Diff line number Diff line change
Expand Up @@ -753,3 +753,9 @@ theme_xhred_signing_in=Signing in
theme_xhred_signing_success=Successfully signed in!
theme_xhred_session_failed_password=Wrong password, please try again.
theme_xhred_global_reauthenticate=Reauthenticate


#19.04
settings_sysinfo_real_time_status=Enable real-time monitoring
settings_sysinfo_real_time_timeout=Interval for performing update
settings_sysinfo_real_time_timeout_description=Set desired interval for updating monitors in background. The value meant to be in milliseconds. Keep this value as low as possible to prevent loss of short-term data.
6 changes: 6 additions & 0 deletions lang/pt.UTF-8
Original file line number Diff line number Diff line change
Expand Up @@ -753,3 +753,9 @@ theme_xhred_signing_in=Signing in
theme_xhred_signing_success=Successfully signed in!
theme_xhred_session_failed_password=Wrong password, please try again.
theme_xhred_global_reauthenticate=Reauthenticate


#19.04
settings_sysinfo_real_time_status=Enable real-time monitoring
settings_sysinfo_real_time_timeout=Interval for performing update
settings_sysinfo_real_time_timeout_description=Set desired interval for updating monitors in background. The value meant to be in milliseconds. Keep this value as low as possible to prevent loss of short-term data.
6 changes: 6 additions & 0 deletions lang/ro_RO.UTF-8
Original file line number Diff line number Diff line change
Expand Up @@ -751,3 +751,9 @@ theme_xhred_signing_in=Signing in
theme_xhred_signing_success=Successfully signed in!
theme_xhred_session_failed_password=Wrong password, please try again.
theme_xhred_global_reauthenticate=Reauthenticate


#19.04
settings_sysinfo_real_time_status=Enable real-time monitoring
settings_sysinfo_real_time_timeout=Interval for performing update
settings_sysinfo_real_time_timeout_description=Set desired interval for updating monitors in background. The value meant to be in milliseconds. Keep this value as low as possible to prevent loss of short-term data.
6 changes: 6 additions & 0 deletions lang/ru.UTF-8
Original file line number Diff line number Diff line change
Expand Up @@ -756,3 +756,9 @@ theme_xhred_signing_in=Signing in
theme_xhred_signing_success=Successfully signed in!
theme_xhred_session_failed_password=Wrong password, please try again.
theme_xhred_global_reauthenticate=Reauthenticate


#19.04
settings_sysinfo_real_time_status=Enable real-time monitoring
settings_sysinfo_real_time_timeout=Interval for performing update
settings_sysinfo_real_time_timeout_description=Set desired interval for updating monitors in background. The value meant to be in milliseconds. Keep this value as low as possible to prevent loss of short-term data.
Loading

0 comments on commit 42efbd0

Please sign in to comment.