mirror of
https://github.com/mailcow/mailcow-dockerized.git
synced 2026-06-10 16:40:22 +00:00
[Agent] Replace dockerapi container with Redis-based control bus
This commit is contained in:
@@ -16,46 +16,92 @@ if (!isset($_SESSION['gal']) && $license_cache = $redis->Get('LICENSE_STATUS_CAC
|
||||
|
||||
$js_minifier->add('/web/js/site/dashboard.js');
|
||||
|
||||
// vmail df
|
||||
$exec_fields = array('cmd' => 'system', 'task' => 'df', 'dir' => '/var/vmail');
|
||||
$vmail_df = explode(',', (string)json_decode(docker('post', 'dovecot-mailcow', 'exec', $exec_fields), true));
|
||||
$vmail_df_resp = agent('request', 'dovecot', 'exec.df', array('dir' => '/var/vmail'), 5);
|
||||
$vmail_df = (!empty($vmail_df_resp['ok']) && is_string($vmail_df_resp['result']))
|
||||
? explode(',', $vmail_df_resp['result'])
|
||||
: array('', '', '', '', '', '/var/vmail');
|
||||
|
||||
// containers
|
||||
$containers_info = (array) docker('info');
|
||||
if ($clamd_status === false) unset($containers_info['clamd-mailcow']);
|
||||
if ($olefy_status === false) unset($containers_info['olefy-mailcow']);
|
||||
ksort($containers_info);
|
||||
$containers = array();
|
||||
foreach ($containers_info as $container => $container_info) {
|
||||
if (!isset($container_info['State']) || !is_array($container_info['State']) || !isset($container_info['State']['StartedAt'])){
|
||||
continue;
|
||||
}
|
||||
date_default_timezone_set('UTC');
|
||||
$StartedAt = date_parse($container_info['State']['StartedAt']);
|
||||
if ($StartedAt['hour'] !== false) {
|
||||
$date = new \DateTime();
|
||||
$date->setTimestamp(mktime(
|
||||
$StartedAt['hour'],
|
||||
$StartedAt['minute'],
|
||||
$StartedAt['second'],
|
||||
$StartedAt['month'],
|
||||
$StartedAt['day'],
|
||||
$StartedAt['year']));
|
||||
try {
|
||||
$user_tz = new DateTimeZone(getenv('TZ'));
|
||||
$date->setTimezone($user_tz);
|
||||
$container_info['State']['StartedAtHR'] = $date->format('r');
|
||||
} catch(Exception $e) {
|
||||
$container_info['State']['StartedAtHR'] = '?';
|
||||
}
|
||||
}
|
||||
else {
|
||||
$container_info['State']['StartedAtHR'] = '?';
|
||||
}
|
||||
$containers[$container] = $container_info;
|
||||
$known_services = agent('services');
|
||||
|
||||
try {
|
||||
$tz_obj = new DateTimeZone(getenv('TZ') ?: 'UTC');
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$tz_obj = new DateTimeZone('UTC');
|
||||
}
|
||||
|
||||
// get mailcow data
|
||||
$containers = array();
|
||||
foreach ($known_services as $svc) {
|
||||
$live_nodes = agent('live_nodes', $svc);
|
||||
$running = !empty($live_nodes);
|
||||
$first_node = $running ? $live_nodes[0] : '';
|
||||
$first_meta = $running ? (agent('node_meta', $svc, $first_node) ?: array()) : array();
|
||||
|
||||
$started_at_hr = '—';
|
||||
$started_at_iso = isset($first_meta['started_at']) ? $first_meta['started_at'] : '';
|
||||
if ($started_at_iso !== '') {
|
||||
try {
|
||||
$d = new DateTime($started_at_iso);
|
||||
$d->setTimezone($tz_obj);
|
||||
$started_at_hr = $d->format('r');
|
||||
}
|
||||
catch (Exception $e) {}
|
||||
}
|
||||
|
||||
$nodes = array();
|
||||
$unhealthy_nodes = 0;
|
||||
$first_unhealthy_detail = '';
|
||||
foreach ($live_nodes as $n) {
|
||||
$m = agent('node_meta', $svc, $n) ?: array();
|
||||
$s = agent('node_stats', $svc, $n) ?: array();
|
||||
$node_health = isset($m['health']) ? $m['health'] : '';
|
||||
$node_health_detail = isset($m['health_detail']) ? $m['health_detail'] : '';
|
||||
if ($node_health === 'fail') {
|
||||
$unhealthy_nodes++;
|
||||
if ($first_unhealthy_detail === '') {
|
||||
$first_unhealthy_detail = $node_health_detail;
|
||||
}
|
||||
}
|
||||
$nodes[] = array(
|
||||
'NodeId' => $n,
|
||||
'Image' => isset($m['image']) ? $m['image'] : '',
|
||||
'StartedAt' => isset($m['started_at']) ? $m['started_at'] : '',
|
||||
'Version' => isset($m['version']) ? $m['version'] : '',
|
||||
'CPUPercent' => isset($s['cpu_percent']) ? $s['cpu_percent'] : '',
|
||||
'MemoryBytes' => isset($s['memory_bytes']) ? $s['memory_bytes'] : '',
|
||||
'Health' => $node_health,
|
||||
'HealthDetail' => $node_health_detail
|
||||
);
|
||||
}
|
||||
|
||||
$service_health = 'unknown';
|
||||
if ($running) {
|
||||
$service_health = ($unhealthy_nodes === 0) ? 'ok' : (($unhealthy_nodes === count($live_nodes)) ? 'fail' : 'degraded');
|
||||
}
|
||||
|
||||
$containers[$svc . '-mailcow'] = array(
|
||||
'Service' => $svc,
|
||||
'State' => array(
|
||||
'Running' => $running ? 1 : 0,
|
||||
'NodeCount' => count($live_nodes),
|
||||
'UnhealthyCount' => $unhealthy_nodes,
|
||||
'Health' => $service_health,
|
||||
'HealthDetail' => $first_unhealthy_detail,
|
||||
'StartedAt' => $started_at_iso,
|
||||
'StartedAtHR' => $started_at_hr
|
||||
),
|
||||
'Config' => array(
|
||||
'Image' => isset($first_meta['image']) ? $first_meta['image'] : ''
|
||||
),
|
||||
'Id' => $first_node,
|
||||
'Nodes' => $nodes,
|
||||
'External' => false
|
||||
);
|
||||
}
|
||||
|
||||
$infra_containers = infra('status');
|
||||
ksort($containers);
|
||||
|
||||
$hostname = getenv('MAILCOW_HOSTNAME');
|
||||
$timezone = getenv('TZ');
|
||||
|
||||
@@ -70,6 +116,7 @@ $template_data = [
|
||||
'clamd_status' => $clamd_status,
|
||||
'olefy_status' => $olefy_status,
|
||||
'containers' => $containers,
|
||||
'infra_containers' => $infra_containers,
|
||||
'ip_check' => customize('get', 'ip_check'),
|
||||
'lang_admin' => json_encode($lang['admin']),
|
||||
'lang_debug' => json_encode($lang['debug']),
|
||||
@@ -77,5 +124,3 @@ $template_data = [
|
||||
];
|
||||
|
||||
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/footer.inc.php';
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user