Servicedock: Webgui for Docker Swarm. Manage Docker Swarm a a Service.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.9 KiB

9 years ago
<?php
exec("docker ps -aq", $res, $ret);
if ($ret!=0) {
echo 'digraph {';
echo ' A [label="Error\nCannot get Docker Containers"];';
echo ' B [label="Does the Webserver have Docker rights?"];';
echo ' A->B [label="Probable\nCause"];';
echo '}';
return;
}
exec("docker inspect ".join(" ", $res), $res2, $ret);
if ($ret==0) {
$containers=json_decode(join($res2), true);
echo "digraph {\n";
echo " rankdir=LR;\n";
foreach ($containers as $c) {
$name = preg_replace(',^/,', '', $c['Name']);
$ports = null;
if ($c['NetworkSettings']['Ports']) {
9 years ago
foreach ($c['NetworkSettings']['Ports'] as $ps) {
if (isset($ps))
foreach ($ps as $p) {
if (isset($p['HostPort']))
if (isset($ports)) $ports .= ", ".$p['HostPort'];
else $ports = $p['HostPort'];
}
}
} elseif ($c['HostConfig']['PortBindings']) {
foreach ($c['HostConfig']['PortBindings'] as $ps) {
if (isset($ps))
foreach ($ps as $p) {
if (isset($p['HostPort']))
if (isset($ports)) $ports .= ", ".$p['HostPort'];
else $ports = $p['HostPort'];
}
}
}
9 years ago
$attrs=$name.'\\n'.$c['Config']['Image'].'",URL="javascript:details('."'".$c['Id']."'".')",style=filled';
if (isset($ports)) $attrs = $ports.'\\n'.$attrs.',peripheries=2';
if ($c['State']['Dead']) $attrs.=',fillcolor=red';
elseif ($c['State']['Restarting']) $attrs.=',fillcolor=lightblue';
elseif ($c['State']['Paused']) $attrs.=',fillcolor=lightgrey';
elseif ($c['State']['Running']) $attrs.=',fillcolor=lightgreen';
else $attrs.=',fillcolor=firebrick1';
echo '"'.$name.'" [label="'.$attrs.'];'."\n";
}
echo " {rank=same;\n";
foreach ($containers as $c) {
foreach ($c['Volumes'] as $in => $out) {
echo ' "'.$in.':'.$out.'" [label="'.$in.'";shape=box];',"\n";
9 years ago
}
}
echo " };\n";
echo " {rank=same;\n";
foreach ($containers as $c) {
foreach ($c['Volumes'] as $in => $out) {
if (!preg_match(',^/var/lib/docker/,', $out))
9 years ago
echo ' "'.$out.'" [shape=box];',"\n";
}
}
echo " };\n";
foreach ($containers as $c) {
foreach ($c['Volumes'] as $in => $out) {
if (!preg_match(',^/var/lib/docker/,', $out))
echo ' "'.$in.':'.$out.'" -> "'.$out.'";',"\n";
9 years ago
}
}
foreach ($containers as $c) {
$name = preg_replace(',^/,', '', $c['Name']);
if (isset($c['HostConfig']['Links']))
foreach ($c['HostConfig']['Links'] as $l) {
$to = preg_replace(',^/?([^:]*).*$,', '${1}', $l);
$link = preg_replace(',.*:/?'.$name.'/,', '', $l);
echo '"'.$name.'" -> "'.$to.'" [label="'.$link.'"];'."\n";
}
foreach ($c['Volumes'] as $in => $out) {
echo '"'.$name.'" -> "'.$in.':'.$out.'";',"\n";
9 years ago
}
}
echo "}";
} else {
echo 'digraph {';
echo ' A [label="Error\nCannot Inspect Docker Container"];';
echo '}';
return;
}
?>