Align sysstat buckets to interval
This commit is contained in:
@@ -35,7 +35,20 @@ class ServerChartsWidget extends Widget
|
||||
$data = $this->getData();
|
||||
$config = $this->rangeConfig($this->range);
|
||||
$sysstat = new SysstatMetrics;
|
||||
$label = now($sysstat->timezoneName())->format($config['label_format']);
|
||||
$labelTime = now($sysstat->timezoneName());
|
||||
if ($config['interval_seconds'] < 60) {
|
||||
$second = intdiv($labelTime->second, $config['interval_seconds']) * $config['interval_seconds'];
|
||||
$labelTime = $labelTime->setTime($labelTime->hour, $labelTime->minute, $second);
|
||||
} else {
|
||||
$labelTime = $labelTime->second(0);
|
||||
if ($config['interval_seconds'] >= 3600) {
|
||||
$labelTime = $labelTime->minute(0);
|
||||
}
|
||||
if ($config['interval_seconds'] >= 86400) {
|
||||
$labelTime = $labelTime->hour(0)->minute(0);
|
||||
}
|
||||
}
|
||||
$label = $labelTime->format($config['label_format']);
|
||||
|
||||
$this->dispatch('server-charts-updated', [
|
||||
'cpu' => $data['cpu']['usage'] ?? 0,
|
||||
|
||||
@@ -20,12 +20,18 @@ class SysstatMetrics
|
||||
}
|
||||
|
||||
$timezone = $this->systemTimezone();
|
||||
$end = CarbonImmutable::now($timezone)->second(0);
|
||||
if ($intervalSeconds >= 3600) {
|
||||
$end = $end->minute(0);
|
||||
}
|
||||
if ($intervalSeconds >= 86400) {
|
||||
$end = $end->hour(0)->minute(0);
|
||||
$end = CarbonImmutable::now($timezone);
|
||||
if ($intervalSeconds < 60) {
|
||||
$second = intdiv($end->second, $intervalSeconds) * $intervalSeconds;
|
||||
$end = $end->setTime($end->hour, $end->minute, $second);
|
||||
} else {
|
||||
$end = $end->second(0);
|
||||
if ($intervalSeconds >= 3600) {
|
||||
$end = $end->minute(0);
|
||||
}
|
||||
if ($intervalSeconds >= 86400) {
|
||||
$end = $end->hour(0)->minute(0);
|
||||
}
|
||||
}
|
||||
$start = $end->subSeconds(($points - 1) * $intervalSeconds);
|
||||
$samples = $this->readSamples($start, $end);
|
||||
|
||||
Reference in New Issue
Block a user