From 8bdf465a0f04724387f54bf04f564170a14550ed Mon Sep 17 00:00:00 2001 From: M Alfiyan Syamsuddin Date: Thu, 2 Sep 2021 12:55:02 +0700 Subject: [PATCH 1/8] add month button --- src/psm/Util/Server/HistoryGraph.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/psm/Util/Server/HistoryGraph.php b/src/psm/Util/Server/HistoryGraph.php index 11425e8b..110a58e9 100644 --- a/src/psm/Util/Server/HistoryGraph.php +++ b/src/psm/Util/Server/HistoryGraph.php @@ -120,6 +120,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 +147,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; } From 28a998c272cc51aff7aa0dcbf75b7b1d410d2f56 Mon Sep 17 00:00:00 2001 From: M Alfiyan Syamsuddin Date: Thu, 2 Sep 2021 13:25:36 +0700 Subject: [PATCH 2/8] generate by last month, tracing why < week uptime truncated --- src/psm/Util/Server/HistoryGraph.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/psm/Util/Server/HistoryGraph.php b/src/psm/Util/Server/HistoryGraph.php index 110a58e9..9c2be688 100644 --- a/src/psm/Util/Server/HistoryGraph.php +++ b/src/psm/Util/Server/HistoryGraph.php @@ -72,10 +72,11 @@ class HistoryGraph $now = new DateTime(); $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, $last_month, $now), 1 => $this->generateGraphHistory($server_id, $last_year, $last_week), ); $info_fields = array( From 81dc8640be1cc47079054bf24cecd136740ef7e6 Mon Sep 17 00:00:00 2001 From: M Alfiyan Syamsuddin Date: Thu, 2 Sep 2021 13:27:34 +0700 Subject: [PATCH 3/8] start hack archiver --- src/psm/Util/Server/Archiver/UptimeArchiver.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/psm/Util/Server/Archiver/UptimeArchiver.php b/src/psm/Util/Server/Archiver/UptimeArchiver.php index e7db3183..f4430c74 100644 --- a/src/psm/Util/Server/Archiver/UptimeArchiver.php +++ b/src/psm/Util/Server/Archiver/UptimeArchiver.php @@ -65,6 +65,7 @@ class UptimeArchiver implements ArchiverInterface */ public function archive($server_id = null) { + // WIP, create more dynamic by config, temp use config.php $latest_date = new \DateTime('-1 week 0:0:0'); // Lock tables to prevent simultaneous archiving (by other sessions or the cron job) From f03ab5065c59ad0e0f9b374368041ba263ce739b Mon Sep 17 00:00:00 2001 From: M Alfiyan Syamsuddin Date: Thu, 2 Sep 2021 13:34:12 +0700 Subject: [PATCH 4/8] add weekly default config for dynamic archive --- src/psm/Module/Install/Controller/InstallController.php | 1 + 1 file changed, 1 insertion(+) 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; From d5471d623777846263b74bfd8b6bd2cb1f16590a Mon Sep 17 00:00:00 2001 From: M Alfiyan Syamsuddin Date: Thu, 2 Sep 2021 13:39:17 +0700 Subject: [PATCH 5/8] if monthly archive defined, allow up to ~1 month old uptime date --- src/psm/Util/Server/Archiver/UptimeArchiver.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/psm/Util/Server/Archiver/UptimeArchiver.php b/src/psm/Util/Server/Archiver/UptimeArchiver.php index f4430c74..de1305b6 100644 --- a/src/psm/Util/Server/Archiver/UptimeArchiver.php +++ b/src/psm/Util/Server/Archiver/UptimeArchiver.php @@ -66,7 +66,12 @@ class UptimeArchiver implements ArchiverInterface public function archive($server_id = null) { // WIP, create more dynamic by config, temp use config.php - $latest_date = new \DateTime('-1 week 0:0:0'); + + 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 { From bcf64fcb376e51bcf075a0b4b1b1b6f27e72b5b3 Mon Sep 17 00:00:00 2001 From: M Alfiyan Syamsuddin Date: Thu, 2 Sep 2021 13:41:11 +0700 Subject: [PATCH 6/8] allow quarterly retention --- src/psm/Util/Server/Archiver/UptimeArchiver.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/psm/Util/Server/Archiver/UptimeArchiver.php b/src/psm/Util/Server/Archiver/UptimeArchiver.php index de1305b6..1b9eff9e 100644 --- a/src/psm/Util/Server/Archiver/UptimeArchiver.php +++ b/src/psm/Util/Server/Archiver/UptimeArchiver.php @@ -67,7 +67,9 @@ class UptimeArchiver implements ArchiverInterface { // WIP, create more dynamic by config, temp use config.php - if(PSM_UPTIME_ARCHIVE == 'monthly'){ + 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'); From 54fd8a645990005af9a27a20abf35e19f1d88caa Mon Sep 17 00:00:00 2001 From: M Alfiyan Syamsuddin Date: Thu, 2 Sep 2021 13:48:26 +0700 Subject: [PATCH 7/8] add comment for archiver --- src/psm/Util/Server/Archiver/UptimeArchiver.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/psm/Util/Server/Archiver/UptimeArchiver.php b/src/psm/Util/Server/Archiver/UptimeArchiver.php index 1b9eff9e..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,8 +68,6 @@ class UptimeArchiver implements ArchiverInterface */ public function archive($server_id = null) { - // WIP, create more dynamic by config, temp use config.php - if(PSM_UPTIME_ARCHIVE == 'quarterly'){ $latest_date = new \DateTime('-3 month 0:0:0'); }else if(PSM_UPTIME_ARCHIVE == 'monthly'){ From 309fa0b15db0f151959671c02f1b7fe3de2c06e1 Mon Sep 17 00:00:00 2001 From: M Alfiyan Syamsuddin Date: Thu, 2 Sep 2021 13:49:38 +0700 Subject: [PATCH 8/8] query by archive settings retention --- src/psm/Util/Server/HistoryGraph.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/psm/Util/Server/HistoryGraph.php b/src/psm/Util/Server/HistoryGraph.php index 9c2be688..c61e07b5 100644 --- a/src/psm/Util/Server/HistoryGraph.php +++ b/src/psm/Util/Server/HistoryGraph.php @@ -71,12 +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_month, $now), + 0 => $this->generateGraphUptime($server_id, $start_date, $now), 1 => $this->generateGraphHistory($server_id, $last_year, $last_week), ); $info_fields = array(