diff --git a/src/psm/Module/Install/Controller/InstallController.php b/src/psm/Module/Install/Controller/InstallController.php index 7afd97f1..b493ee60 100644 --- a/src/psm/Module/Install/Controller/InstallController.php +++ b/src/psm/Module/Install/Controller/InstallController.php @@ -202,6 +202,7 @@ class InstallController extends AbstractController 'db_pass' => '', 'db_prefix' => 'psm_', 'base_url' => $this->getBaseUrl(), + 'uptime_archive' => 'weekly', ); $changed = false; diff --git a/src/psm/Util/Server/Archiver/UptimeArchiver.php b/src/psm/Util/Server/Archiver/UptimeArchiver.php index e7db3183..e047d0c5 100644 --- a/src/psm/Util/Server/Archiver/UptimeArchiver.php +++ b/src/psm/Util/Server/Archiver/UptimeArchiver.php @@ -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 { diff --git a/src/psm/Util/Server/HistoryGraph.php b/src/psm/Util/Server/HistoryGraph.php index 11425e8b..c61e07b5 100644 --- a/src/psm/Util/Server/HistoryGraph.php +++ b/src/psm/Util/Server/HistoryGraph.php @@ -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; }