Skip to content

Commit

Permalink
[BS5] add container disk and network stats
Browse files Browse the repository at this point in the history
  • Loading branch information
FreddleSpl0it committed Aug 22, 2022
1 parent 2e10cc8 commit 7f70b0f
Show file tree
Hide file tree
Showing 6 changed files with 443 additions and 155 deletions.
15 changes: 15 additions & 0 deletions data/web/css/build/013-mailcow.css
Original file line number Diff line number Diff line change
Expand Up @@ -378,3 +378,18 @@ table.dataTable.table-striped>tbody>tr>td>input[type="checkbox"] {
.btn-check-label {
color: #555;
}

.caret {
transform: rotate(0deg);
}
a[aria-expanded='true'] > .caret,
button[aria-expanded='true'] > .caret {
transform: rotate(-180deg);
}

.list-group-details {
background: #fff;
}
.list-group-header {
background: #f7f7f7;
}
8 changes: 8 additions & 0 deletions data/web/css/themes/mailcow-darkmode.css
Original file line number Diff line number Diff line change
Expand Up @@ -339,4 +339,12 @@ table.dataTable.dtr-inline.collapsed>tbody>tr>td.dataTables_empty {

.inputMissingAttr {
border-color: #FF4136 !important;
}


.list-group-details {
background: #444444;
}
.list-group-header {
background: #333;
}
27 changes: 27 additions & 0 deletions data/web/inc/functions.docker.inc.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
function docker($action, $service_name = null, $attr1 = null, $attr2 = null, $extra_headers = null) {
global $DOCKER_TIMEOUT;
global $redis;
$curl = curl_init();
curl_setopt($curl, CURLOPT_HTTPHEADER,array('Content-Type: application/json' ));
// We are using our mail certificates for dockerapi, the names will not match, the certs are trusted anyway
Expand Down Expand Up @@ -52,6 +53,7 @@ function docker($action, $service_name = null, $attr1 = null, $attr2 = null, $ex
if (strtolower($container['Config']['Labels']['com.docker.compose.project']) == strtolower(getenv('COMPOSE_PROJECT_NAME'))) {
$out[$container['Config']['Labels']['com.docker.compose.service']]['State'] = $container['State'];
$out[$container['Config']['Labels']['com.docker.compose.service']]['Config'] = $container['Config'];
$out[$container['Config']['Labels']['com.docker.compose.service']]['Id'] = trim($container['Id']);
}
}
}
Expand Down Expand Up @@ -95,6 +97,7 @@ function docker($action, $service_name = null, $attr1 = null, $attr2 = null, $ex
unset($container['Config']['Env']);
$out[$container['Config']['Labels']['com.docker.compose.service']]['State'] = $container['State'];
$out[$container['Config']['Labels']['com.docker.compose.service']]['Config'] = $container['Config'];
$out[$container['Config']['Labels']['com.docker.compose.service']]['Id'] = trim($container['Id']);
}
}
}
Expand All @@ -104,6 +107,7 @@ function docker($action, $service_name = null, $attr1 = null, $attr2 = null, $ex
unset($container['Config']['Env']);
$out[$decoded_response['Config']['Labels']['com.docker.compose.service']]['State'] = $decoded_response['State'];
$out[$decoded_response['Config']['Labels']['com.docker.compose.service']]['Config'] = $decoded_response['Config'];
$out[$decoded_response['Config']['Labels']['com.docker.compose.service']]['Id'] = trim($decoded_response['Id']);
}
}
}
Expand Down Expand Up @@ -147,6 +151,29 @@ function docker($action, $service_name = null, $attr1 = null, $attr2 = null, $ex
}
}
break;
case 'container_stats':
if (empty($service_name)){
return false;
}

$container_id = $service_name;
curl_setopt($curl, CURLOPT_URL, 'https://dockerapi:443/container/' . $container_id . '/stats/update');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, $DOCKER_TIMEOUT);
$response = curl_exec($curl);
if ($response === false) {
$err = curl_error($curl);
curl_close($curl);
return $err;
}
else {
curl_close($curl);
$stats = json_decode($response, true);
if (!empty($stats)) return $stats;
}
return false;
break;
case 'host_stats':
curl_setopt($curl, CURLOPT_URL, 'https://dockerapi:443/host/stats');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
Expand Down
Loading

0 comments on commit 7f70b0f

Please sign in to comment.