This commit is contained in:
M Alfiyan S 2022-04-14 08:29:02 -04:00 committed by GitHub
commit 3531e62818
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 3 deletions

View File

@ -202,6 +202,7 @@ class InstallController extends AbstractController
'db_pass' => '',
'db_prefix' => 'psm_',
'base_url' => $this->getBaseUrl(),
'uptime_archive' => 'weekly',
);
$changed = false;

View File

@ -56,7 +56,10 @@ class UptimeArchiver implements ArchiverInterface
}
/**
* Archive all server status records older than 1 week.
* Archive all server status records older than (X) based on config.
* quarterly = up to last 3 months
* monthly = up to last 1 month
* default / weekly = up to 1 week
*
* Archiving means calculating averages per day, and storing 1 single
* history row for each day for each server.
@ -65,7 +68,13 @@ class UptimeArchiver implements ArchiverInterface
*/
public function archive($server_id = null)
{
$latest_date = new \DateTime('-1 week 0:0:0');
if(PSM_UPTIME_ARCHIVE == 'quarterly'){
$latest_date = new \DateTime('-3 month 0:0:0');
}else if(PSM_UPTIME_ARCHIVE == 'monthly'){
$latest_date = new \DateTime('-1 month 0:0:0');
}else{
$latest_date = new \DateTime('-1 week 0:0:0');
}
// Lock tables to prevent simultaneous archiving (by other sessions or the cron job)
try {

View File

@ -71,11 +71,21 @@ class HistoryGraph
$archive->archive($server_id);
$now = new DateTime();
if(PSM_UPTIME_ARCHIVE == 'quarterly'){
$start_date = new DateTime('-3 month 0:0:0');
}else if(PSM_UPTIME_ARCHIVE == 'monthly'){
$start_date = new DateTime('-1 month 0:0:0');
}else{
$start_date = new DateTime('-1 week 0:0:0');
}
$last_week = new DateTime('-1 week 0:0:0');
$last_month = new DateTime('-1 month 0:0:0');
$last_year = new DateTime('-1 year -1 week 0:0:0');
$graphs = array(
0 => $this->generateGraphUptime($server_id, $last_week, $now),
0 => $this->generateGraphUptime($server_id, $start_date, $now),
1 => $this->generateGraphHistory($server_id, $last_year, $last_week),
);
$info_fields = array(
@ -120,6 +130,7 @@ class HistoryGraph
$hour = new DateTime('-1 hour');
$day = new DateTime('-1 day');
$week = new DateTime('-1 week');
$month = new DateTime('-1 month');
$records = $this->getRecords('uptime', $server_id, $start_time, $end_time);
@ -146,6 +157,11 @@ class HistoryGraph
'time' => $week->getTimestamp() * 1000,
'label' => psm_get_lang('servers', 'week')
);
$data['buttons'][] = array(
'unit' => 'day',
'time' => $month->getTimestamp() * 1000,
'label' => psm_get_lang('servers', 'month')
);
return $data;
}