summaryrefslogtreecommitdiffstats
path: root/modules-available/statistics/pages/machine.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/statistics/pages/machine.inc.php')
-rw-r--r--modules-available/statistics/pages/machine.inc.php65
1 files changed, 49 insertions, 16 deletions
diff --git a/modules-available/statistics/pages/machine.inc.php b/modules-available/statistics/pages/machine.inc.php
index 1d46b523..34ed63da 100644
--- a/modules-available/statistics/pages/machine.inc.php
+++ b/modules-available/statistics/pages/machine.inc.php
@@ -310,29 +310,36 @@ class SubPage
}
// Sessions
$NOW = time();
- $cutoff = $NOW - 86400 * 7;
+ $cutoff = $NOW - 86400 * 10;
//if ($cutoff < $client['firstseen']) $cutoff = $client['firstseen'];
$scale = 100 / ($NOW - $cutoff);
- $res = Database::simpleQuery('SELECT dateline, typeid, data FROM statistic'
- . " WHERE dateline > :cutoff AND typeid IN (:sessionLength, :offlineLength) AND machineuuid = :uuid ORDER BY dateline ASC", array(
- 'cutoff' => $cutoff - 86400 * 14,
+ $res = Database::simpleQuery('SELECT dateline, typeid, data FROM statistic
+ WHERE dateline > :cutoff
+ AND typeid IN (:sessionLength, :offlineLength, :suspendLength)
+ AND machineuuid = :uuid ORDER BY dateline ASC', [
+ 'cutoff' => $cutoff - 86400 * 30,
'uuid' => $uuid,
'sessionLength' => Statistics::SESSION_LENGTH,
'offlineLength' => Statistics::OFFLINE_LENGTH,
- ));
- $spans['rows'] = array();
- $spans['graph'] = '';
+ 'suspendLength' => Statistics::SUSPEND_LENGTH,
+ ]);
+ $spans = [
+ 'rows' => array(),
+ 'graph' => '',
+ ];
+ $timeOffline = $timeStandby = $timeIdle = $timeUse = 0;
$last = false;
$first = true;
foreach ($res as $row) {
if (!$client['isclient'] && $row['typeid'] === Statistics::SESSION_LENGTH)
continue; // Don't differentiate between session and idle for non-clients
if ($first && $row['dateline'] > $cutoff && $client['lastboot'] > $cutoff) {
- // Special case: offline before
+ // Special case: offline before query start (longer than 30 days)
+ $timeOffline += min($row['dateline'], $client['lastboot']) - $cutoff;
$spans['graph'] .= '<div style="background:#444;left:0;width:' . round((min($row['dateline'], $client['lastboot']) - $cutoff) * $scale, 2) . '%">&nbsp;</div>';
}
$first = false;
- if ($row['dateline'] + $row['data'] < $cutoff || $row['data'] > 864000) {
+ if ($row['dateline'] + $row['data'] < $cutoff || $row['dateline'] + $row['data'] > $NOW) {
continue;
}
if ($last !== false && abs($last['dateline'] - $row['dateline']) < 30
@@ -354,24 +361,43 @@ class SubPage
if ($row['typeid'] === Statistics::OFFLINE_LENGTH) {
$row['glyph'] = 'off';
$color = '#444';
+ $timeOffline += $row['data'];
} elseif ($row['typeid'] === Statistics::SUSPEND_LENGTH) {
$row['glyph'] = 'pause';
$color = '#686';
+ $timeStandby += $row['data'];
} else {
$row['glyph'] = 'user';
$color = '#e77';
+ $timeUse += $row['data'];
}
$spans['graph'] .= '<div style="background:' . $color . ';left:' . round(($row['dateline'] - $cutoff) * $scale, 2) . '%;width:' . round(($row['data']) * $scale, 2) . '%">&nbsp;</div>';
+ // Reconstructed entry for table: idle - not logged in DB directly
+ if ($last !== false) {
+ $lastEnd = $last['dateline'] + $last['data'];
+ $duration = $row['dateline'] - $lastEnd;
+ if ($client['isclient'] && $duration > 90) {
+ $spans['rows'][] = [
+ 'glyph' => 'ok-circle',
+ 'from' => Util::prettyTime($lastEnd),
+ 'duration' => floor($duration / 86400) . 'd ' . gmdate('H:i', $duration),
+ ];
+ }
+ if ($duration > 0) {
+ $timeIdle += $duration;
+ }
+ }
+ // Normal entry for table
if ($client['isclient']) {
$spans['rows'][] = $row;
}
$last = $row;
}
if ($first && $client['lastboot'] > $cutoff) {
- // Special case: offline before
+ // Special case: offline before and no activity besides bootup
$spans['graph'] .= '<div style="background:#444;left:0;width:' . round(($client['lastboot'] - $cutoff) * $scale, 2) . '%">&nbsp;</div>';
} elseif ($first) {
- // Not seen in last two weeks
+ // Not seen in last weeks
$spans['graph'] .= '<div style="background:#444;left:0;width:100%">&nbsp;</div>';
}
if ($client['state'] === 'OCCUPIED') {
@@ -381,6 +407,7 @@ class SubPage
'duration' => '-',
'glyph' => 'user',
];
+ $timeUse += $NOW - $client['logintime'];
} elseif ($client['state'] === 'OFFLINE') {
$spans['graph'] .= '<div style="background:#444;left:' . round(($client['lastseen'] - $cutoff) * $scale, 2) . '%;width:' . round(($NOW - $client['lastseen'] + 900) * $scale, 2) . '%">&nbsp;</div>';
$spans['rows'][] = [
@@ -388,6 +415,7 @@ class SubPage
'duration' => '-',
'glyph' => 'off',
];
+ $timeOffline += $NOW - $client['lastseen'];
} elseif ($client['state'] === 'STANDBY') {
$spans['graph'] .= '<div style="background:#686;left:' . round(($client['lastseen'] - $cutoff) * $scale, 2) . '%;width:' . round(($NOW - $client['lastseen'] + 900) * $scale, 2) . '%">&nbsp;</div>';
$spans['rows'][] = [
@@ -395,6 +423,10 @@ class SubPage
'duration' => '-',
'glyph' => 'pause',
];
+ $timeStandby += $NOW - $client['lastseen'];
+ } elseif ($last !== false && $client['state'] === 'IDLE') {
+ $lastEnd = $last['dateline'] + $last['data'];
+ $timeIdle += $NOW - $lastEnd;
}
$t = explode('-', date('Y-n-j-G', $cutoff));
if ($t[3] >= 8 && $t[3] <= 22) {
@@ -405,12 +437,13 @@ class SubPage
for ($i = $start; $i < $NOW; $i += 86400) {
$spans['graph'] .= '<div style="background:rgba(0,0,90,.2);left:' . round(($i - $cutoff) * $scale, 2) . '%;width:' . round((10 * 3600) * $scale, 2) . '%">&nbsp;</div>';
}
- if (count($spans['rows']) > 10) {
- $spans['hasrows2'] = true;
- $spans['rows2'] = array_slice($spans['rows'], (int)ceil(count($spans['rows']) / 2));
- $spans['rows'] = array_slice($spans['rows'], 0, (int)ceil(count($spans['rows']) / 2));
- }
$spans['isclient'] = $client['isclient'];
+ $spans['chart'] = json_encode([
+ ['value' => $timeOffline, 'color' => '#444', 'tooltip' => 'OFFLINE: ' . Util::formatDuration($timeOffline)],
+ ['value' => $timeStandby, 'color' => '#686', 'tooltip' => 'STANDBY: ' . Util::formatDuration($timeStandby)],
+ ['value' => $timeIdle, 'color' => '#afc', 'tooltip' => 'IDLE: ' . Util::formatDuration($timeIdle)],
+ ['value' => $timeUse, 'color' => '#e99', 'tooltip' => 'OCCUPIED: ' . Util::formatDuration($timeUse)],
+ ]);
Render::addTemplate('machine-usage', $spans);
// Any hdds?
if (!empty($hdds['hdds'])) {