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 retentiondevelop
parent
607c2e1e82
commit
7e9826b532
|
@ -202,6 +202,7 @@ class InstallController extends AbstractController
|
||||||
'db_pass' => '',
|
'db_pass' => '',
|
||||||
'db_prefix' => 'psm_',
|
'db_prefix' => 'psm_',
|
||||||
'base_url' => $this->getBaseUrl(),
|
'base_url' => $this->getBaseUrl(),
|
||||||
|
'uptime_archive' => 'weekly',
|
||||||
);
|
);
|
||||||
|
|
||||||
$changed = false;
|
$changed = false;
|
||||||
|
|
|
@ -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
|
* Archiving means calculating averages per day, and storing 1 single
|
||||||
* history row for each day for each server.
|
* history row for each day for each server.
|
||||||
|
@ -65,7 +68,13 @@ class UptimeArchiver implements ArchiverInterface
|
||||||
*/
|
*/
|
||||||
public function archive($server_id = null)
|
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)
|
// Lock tables to prevent simultaneous archiving (by other sessions or the cron job)
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -71,11 +71,21 @@ class HistoryGraph
|
||||||
$archive->archive($server_id);
|
$archive->archive($server_id);
|
||||||
|
|
||||||
$now = new DateTime();
|
$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_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');
|
$last_year = new DateTime('-1 year -1 week 0:0:0');
|
||||||
|
|
||||||
$graphs = array(
|
$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),
|
1 => $this->generateGraphHistory($server_id, $last_year, $last_week),
|
||||||
);
|
);
|
||||||
$info_fields = array(
|
$info_fields = array(
|
||||||
|
@ -120,6 +130,7 @@ class HistoryGraph
|
||||||
$hour = new DateTime('-1 hour');
|
$hour = new DateTime('-1 hour');
|
||||||
$day = new DateTime('-1 day');
|
$day = new DateTime('-1 day');
|
||||||
$week = new DateTime('-1 week');
|
$week = new DateTime('-1 week');
|
||||||
|
$month = new DateTime('-1 month');
|
||||||
|
|
||||||
$records = $this->getRecords('uptime', $server_id, $start_time, $end_time);
|
$records = $this->getRecords('uptime', $server_id, $start_time, $end_time);
|
||||||
|
|
||||||
|
@ -146,6 +157,11 @@ class HistoryGraph
|
||||||
'time' => $week->getTimestamp() * 1000,
|
'time' => $week->getTimestamp() * 1000,
|
||||||
'label' => psm_get_lang('servers', 'week')
|
'label' => psm_get_lang('servers', 'week')
|
||||||
);
|
);
|
||||||
|
$data['buttons'][] = array(
|
||||||
|
'unit' => 'day',
|
||||||
|
'time' => $month->getTimestamp() * 1000,
|
||||||
|
'label' => psm_get_lang('servers', 'month')
|
||||||
|
);
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue