131 lines
2.7 KiB
Bash
Executable file
131 lines
2.7 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
TITLE="Recycled Cloud Status"
|
|
LOCATIONS="lnth.ch lsne.ch fvil.ch"
|
|
EXTERNAL_PROMETHEUS_ADDR=http://localhost:9090
|
|
|
|
query () {
|
|
endpoint="$1/api/v1/query"
|
|
query=$2
|
|
|
|
curl "$endpoint" --data-urlencode "query=$query" | jq --raw-output .data.result[].value[1]
|
|
}
|
|
|
|
get_state () {
|
|
case "$1" in
|
|
0)
|
|
echo "down"
|
|
;;
|
|
1)
|
|
echo "up"
|
|
;;
|
|
*)
|
|
echo "unknown"
|
|
;;
|
|
esac
|
|
}
|
|
|
|
get_canary_state () {
|
|
location=$1
|
|
inet=$2
|
|
|
|
instance="canary.$location.recycled.cloud"
|
|
job="blackbox-external-v$inet"
|
|
result=$(query $EXTERNAL_PROMETHEUS_ADDR \
|
|
"probe_success{instance=\"$instance\", job=\"$job\"}")
|
|
|
|
get_state "$result"
|
|
}
|
|
|
|
get_edge_state () {
|
|
location=$1
|
|
edge=$2
|
|
|
|
instance="edge$edge-$(echo "$location" | cut -d. -f1).transfer.recycled.cloud"
|
|
result=$(query $EXTERNAL_PROMETHEUS_ADDR \
|
|
"probe_success{instance=\"$instance\"}")
|
|
|
|
get_state "$result"
|
|
}
|
|
|
|
cat << EOF
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8"/>
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
|
<title>${TITLE:?}</title>
|
|
<link rel="stylesheet" href="assets/main.css">
|
|
<link rel="stylesheet" href="assets/bootstrap-reboot.min.css">
|
|
<link rel="stylesheet" href="assets/bootstrap-grid.min.css">
|
|
</head>
|
|
<body>
|
|
<div id="header">
|
|
<img src="assets/cloud.svg" id="logo" />
|
|
<h1>${TITLE:?}</h1>
|
|
<p>This page reports the status of the <a
|
|
href="https://recycled.cloud">Recycled Cloud</a> infrastructure,
|
|
regenerated every minute.
|
|
</p>
|
|
<p>
|
|
States:
|
|
<span class="up">up</span>
|
|
<span class="down">down</span>
|
|
<span class="unknown">unknown</span>
|
|
</p>
|
|
<p>
|
|
Last refresh on <b>$(date)</b>.
|
|
</p>
|
|
</div>
|
|
EOF
|
|
|
|
for location in $LOCATIONS; do
|
|
canary_v6=$(get_canary_state "$location" 6)
|
|
canary_v4=$(get_canary_state "$location" 4)
|
|
|
|
edge1_transfer=$(get_edge_state "$location" 1)
|
|
edge2_transfer=$(get_edge_state "$location" 2)
|
|
|
|
cat <<- EOF
|
|
<div class="location">
|
|
<hr />
|
|
<h2>$location</h2>
|
|
|
|
<div class="row">
|
|
<div class="col-6">
|
|
<h3>Routers</h3>
|
|
<ul>
|
|
<li>edge1 <span class="$edge1_transfer">$edge1_transfer</span></li>
|
|
<li>edge2 <span class="$edge2_transfer">$edge2_transfer</span></li>
|
|
</ul>
|
|
</div>
|
|
<div class="col-6">
|
|
<h3>Canary VM</h3>
|
|
<ul>
|
|
<li>IPv6 <span class="$canary_v6">$canary_v6</span></li>
|
|
<li>IPv4 <span class="$canary_v4">$canary_v4</span></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- not implemented yet
|
|
<h3>Capacity</h3>
|
|
|
|
<div class="row">
|
|
<div class="col-6">
|
|
<p>Used RAM: X / XX GB</p>
|
|
</div>
|
|
<div class="col-6">
|
|
<p>Used Storage: X / XX GB</p>
|
|
</div>
|
|
</div>
|
|
-->
|
|
</div>
|
|
EOF
|
|
done
|
|
|
|
cat << EOF
|
|
</body>
|
|
</html>
|
|
EOF
|