Skip to content

Commit 7e9826b

Browse files
authored
Server monthly uptime analytics (#1146)
* add month button * generate by last month, tracing why < week uptime truncated * start hack archiver * add weekly default config for dynamic archive * if monthly archive defined, allow up to ~1 month old uptime date * allow quarterly retention * add comment for archiver * query by archive settings retention
1 parent 607c2e1 commit 7e9826b

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

src/psm/Module/Install/Controller/InstallController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ protected function executeConfig()
202202
'db_pass' => '',
203203
'db_prefix' => 'psm_',
204204
'base_url' => $this->getBaseUrl(),
205+
'uptime_archive' => 'weekly',
205206
);
206207

207208
$changed = false;

src/psm/Util/Server/Archiver/UptimeArchiver.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ public function __construct(Database $db)
5656
}
5757

5858
/**
59-
* Archive all server status records older than 1 week.
59+
* Archive all server status records older than (X) based on config.
60+
* quarterly = up to last 3 months
61+
* monthly = up to last 1 month
62+
* default / weekly = up to 1 week
6063
*
6164
* Archiving means calculating averages per day, and storing 1 single
6265
* history row for each day for each server.
@@ -65,7 +68,13 @@ public function __construct(Database $db)
6568
*/
6669
public function archive($server_id = null)
6770
{
68-
$latest_date = new \DateTime('-1 week 0:0:0');
71+
if(PSM_UPTIME_ARCHIVE == 'quarterly'){
72+
$latest_date = new \DateTime('-3 month 0:0:0');
73+
}else if(PSM_UPTIME_ARCHIVE == 'monthly'){
74+
$latest_date = new \DateTime('-1 month 0:0:0');
75+
}else{
76+
$latest_date = new \DateTime('-1 week 0:0:0');
77+
}
6978

7079
// Lock tables to prevent simultaneous archiving (by other sessions or the cron job)
7180
try {

src/psm/Util/Server/HistoryGraph.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,21 @@ public function createHTML($server_id)
7171
$archive->archive($server_id);
7272

7373
$now = new DateTime();
74+
75+
if(PSM_UPTIME_ARCHIVE == 'quarterly'){
76+
$start_date = new DateTime('-3 month 0:0:0');
77+
}else if(PSM_UPTIME_ARCHIVE == 'monthly'){
78+
$start_date = new DateTime('-1 month 0:0:0');
79+
}else{
80+
$start_date = new DateTime('-1 week 0:0:0');
81+
}
82+
7483
$last_week = new DateTime('-1 week 0:0:0');
84+
$last_month = new DateTime('-1 month 0:0:0');
7585
$last_year = new DateTime('-1 year -1 week 0:0:0');
7686

7787
$graphs = array(
78-
0 => $this->generateGraphUptime($server_id, $last_week, $now),
88+
0 => $this->generateGraphUptime($server_id, $start_date, $now),
7989
1 => $this->generateGraphHistory($server_id, $last_year, $last_week),
8090
);
8191
$info_fields = array(
@@ -120,6 +130,7 @@ public function generateGraphUptime($server_id, $start_time, $end_time)
120130
$hour = new DateTime('-1 hour');
121131
$day = new DateTime('-1 day');
122132
$week = new DateTime('-1 week');
133+
$month = new DateTime('-1 month');
123134

124135
$records = $this->getRecords('uptime', $server_id, $start_time, $end_time);
125136

@@ -146,6 +157,11 @@ public function generateGraphUptime($server_id, $start_time, $end_time)
146157
'time' => $week->getTimestamp() * 1000,
147158
'label' => psm_get_lang('servers', 'week')
148159
);
160+
$data['buttons'][] = array(
161+
'unit' => 'day',
162+
'time' => $month->getTimestamp() * 1000,
163+
'label' => psm_get_lang('servers', 'month')
164+
);
149165

150166
return $data;
151167
}

0 commit comments

Comments
 (0)