summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--modules-available/statistics/api.inc.php17
-rw-r--r--modules-available/statistics/install.inc.php14
-rw-r--r--modules-available/statistics/pages/machine.inc.php5
-rw-r--r--modules-available/statistics/templates/machine-main.html7
4 files changed, 36 insertions, 7 deletions
diff --git a/modules-available/statistics/api.inc.php b/modules-available/statistics/api.inc.php
index b8ef2eb1..3e8ed917 100644
--- a/modules-available/statistics/api.inc.php
+++ b/modules-available/statistics/api.inc.php
@@ -112,7 +112,7 @@ if ($type{0} === '~') {
. ' cpumodel = :cpumodel,'
. ' systemmodel = :systemmodel,'
. ' id44mb = :id44mb,'
- . ' live_tmpsize = 0, live_swapsize = 0, live_memsize = 0,'
+ . ' live_tmpsize = 0, live_swapsize = 0, live_memsize = 0, cpuload = 255',
. ' badsectors = :badsectors,'
. ' data = :data,'
. ' state = :state '
@@ -215,11 +215,16 @@ if ($type{0} === '~') {
}
}
}
- foreach (['memsize', 'tmpsize', 'swapsize', 'memfree', 'tmpfree', 'swapfree'] as $item) {
+ foreach (['memsize', 'tmpsize', 'swapsize', 'memfree', 'tmpfree', 'swapfree', 'cpuload'] as $item) {
$liveVal = Request::post($item, false, 'int');
if ($liveVal !== false) {
$strUpdateBoottime .= ' live_' . $item . ' = :_' . $item . ', ';
- $params['_' . $item] = ceil($liveVal / 1024);
+ if ($item === 'cpuload') {
+ $liveVal = round($liveVal);
+ } else {
+ $liveVal = ceil($liveVal / 1024);
+ }
+ $params['_' . $item] = $liveVal;
}
}
// Figure out what's happening - state changes
@@ -358,7 +363,8 @@ if ($type{0} === '~') {
updateIp('suspend', $uuid, $old, $ip);
}
if ($NOW - $old['lastseen'] < 610 && $old['state'] !== 'OFFLINE') {
- Database::exec("UPDATE machine SET lastseen = UNIX_TIMESTAMP(), state = 'STANDBY'
+ Database::exec("UPDATE machine SET lastseen = UNIX_TIMESTAMP(), state = 'STANDBY',
+ standbysem = If(standbysem < 6, standbysem + 1, 6)
WHERE machineuuid = :uuid AND state = :oldstate AND lastseen = :oldlastseen",
array('uuid' => $uuid, 'oldlastseen' => $old['lastseen'], 'oldstate' => $old['state']));
} else {
@@ -371,7 +377,8 @@ if ($type{0} === '~') {
updateIp('resume', $uuid, $old, $ip);
}
if ($old['state'] === 'STANDBY') {
- $res = Database::exec("UPDATE machine SET state = 'IDLE', clientip = :ip, lastseen = UNIX_TIMESTAMP()
+ $res = Database::exec("UPDATE machine SET state = 'IDLE', clientip = :ip, lastseen = UNIX_TIMESTAMP(),
+ standbysem = If(standbysem > 1, standbysem - 2, 0)
WHERE machineuuid = :uuid AND state = :oldstate AND lastseen = :oldlastseen",
array('uuid' => $uuid, 'ip' => $ip, 'oldlastseen' => $old['lastseen'], 'oldstate' => $old['state']));
// Write standby period length to statistic table
diff --git a/modules-available/statistics/install.inc.php b/modules-available/statistics/install.inc.php
index 2831905d..1fb70aef 100644
--- a/modules-available/statistics/install.inc.php
+++ b/modules-available/statistics/install.inc.php
@@ -250,7 +250,7 @@ if (!tableHasColumn('machine', 'live_tmpsize')) {
ADD INDEX `live_tmpfree` (`live_tmpfree`),
ADD INDEX `live_memfree` (`live_memfree`)");
if ($ret === false) {
- finalResponse(UPDATE_FAILED, 'Adding state column to machine table failed: ' . Database::lastError());
+ finalResponse(UPDATE_FAILED, 'Adding mem-stat columns to machine table failed: ' . Database::lastError());
}
$res[] = UPDATE_DONE;
}
@@ -273,5 +273,17 @@ while ($row = $res2->fetch(PDO::FETCH_ASSOC)) {
$res[] = tableAddConstraint('setting_machine', 'machineuuid', 'machine', 'machineuuid',
'ON UPDATE CASCADE ON DELETE CASCADE');
+// 2020-04-25: Track enter/exit standby count, live CPU load
+if (!tableHasColumn('machine', 'live_cpuload')) {
+ $ret = Database::exec("ALTER TABLE `machine`
+ ADD COLUMN `live_cpuload` tinyint(3) UNSIGNED NOT NULL DEFAULT '255' AFTER `live_memfree`,
+ ADD COLUMN `standbysem` tinyint(3) UNSIGNED NOT NULL DEFAULT '0',
+ ADD INDEX `live_cpuload` (`live_cpuload`)");
+ if ($ret === false) {
+ finalResponse(UPDATE_FAILED, 'Adding live_cpuload column to machine table failed: ' . Database::lastError());
+ }
+ $res[] = UPDATE_DONE;
+}
+
// Create response
responseFromArray($res);
diff --git a/modules-available/statistics/pages/machine.inc.php b/modules-available/statistics/pages/machine.inc.php
index 7aa91c16..79166cd5 100644
--- a/modules-available/statistics/pages/machine.inc.php
+++ b/modules-available/statistics/pages/machine.inc.php
@@ -52,7 +52,7 @@ class SubPage
private static function showMachine($uuid)
{
$client = Database::queryFirst('SELECT machineuuid, locationid, macaddr, clientip, firstseen, lastseen, logintime, lastboot, state,
- mbram, live_tmpsize, live_tmpfree, live_swapsize, live_swapfree, live_memsize, live_memfree, Length(position) AS hasroomplan,
+ mbram, live_tmpsize, live_tmpfree, live_swapsize, live_swapfree, live_memsize, live_memfree, live_cpuload, Length(position) AS hasroomplan,
kvmstate, cpumodel, id44mb, data, hostname, currentuser, currentsession, notes FROM machine WHERE machineuuid = :uuid',
array('uuid' => $uuid));
if ($client === false) {
@@ -125,6 +125,9 @@ class SubPage
$client['live_' . $item . 'percent'] = round(($client['live_' . $item . 'free'] / $client['live_' . $item . 'size']) * 100, 2);
$client['live_' . $item . 'free_s'] = Util::readableFileSize($client['live_' . $item . 'free'], -1, 2);
}
+ if ($client['live_cpuload'] <= 100) {
+ $client['live_cpuload_s'] = $client['live_cpuload'] . "\xe2\x80\x89%";
+ }
$client['ramclass'] = StatisticsStyling::ramColorClass($client['mbram']);
$client['kvmclass'] = StatisticsStyling::kvmColorClass($client['kvmstate']);
$client['hddclass'] = StatisticsStyling::hddColorClass($client['gbtmp']);
diff --git a/modules-available/statistics/templates/machine-main.html b/modules-available/statistics/templates/machine-main.html
index 5e3b31f6..83c3a292 100644
--- a/modules-available/statistics/templates/machine-main.html
+++ b/modules-available/statistics/templates/machine-main.html
@@ -225,6 +225,13 @@
{{lang_sockets}}: {{Sockets}}, {{lang_cores}}: {{Realcores}}, {{lang_virtualCores}}: {{Virtualcores}}
</div>
{{/Sockets}}
+ {{#live_cpuload_s}}
+ <div class="meter">
+ <div class="text left">{{lang_cpuload}}</div>
+ <div class="text right">{{live_cpuload_s}}</div>
+ <div class="bar" style="width:{{live_cpuload}}%"></div>
+ </div>
+ {{/live_cpuload_s}}
</td>
</tr>
<tr>