netdata dashboard using guages for hosts and docker containers
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.
 

154 lines
5.7 KiB

#!/bin/bash
# Write a master dashboard based on the hosts.ini file in the current directory
# Vars for the site
sitename="Dev0 Netdata"
title="Dev0 Netdata"
desc="Docker Dashboard"
theme="'slate'"
# put our file head in place
echo '<!DOCTYPE html>
<!-- SPDX-License-Identifier: GPL-3.0-or-later -->
<html lang="en">
<head>
<title>NetData Dashboard</title>
<meta name="application-name" content="netdata">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="author" content="costa@tsaousis.gr">
<meta property="og:locale" content="en_US" />
<meta property="og:image" content="https://cloud.githubusercontent.com/assets/2662304/22945737/e98cd0c6-f2fd-11e6-96f1-5501934b0955.png"/>
<meta property="og:url" content="http://my-netdata.io/"/>
<meta property="og:type" content="website"/>
<meta property="og:site_name" content="$sitename"/>
<meta property="og:title" content="$title"/>
<meta property="og:description" content="$desc" />
</head>
<script>var netdataTheme = '$theme';</script>
<script type="text/javascript" src="http://netdata.dev0.sh/dashboard.js"></script>
<script>NETDATA.options.current.stop_updates_when_focus_is_lost = false;</script>
<body>
<div style="width: 100%; text-align: center; padding-top: 1%;">' > docker.html
# We need to read each docker host into its own process, this is so we can append both the host and the containers it contains to the right blocks
# read hosts.ini as the HOSTS array
readarray HOSTS < docker.ini
# erase existing containers.ini so we can populate accurate ones
rm *.containers.ini
# curl the docker hosts to get container names. They will be named host.containers.ini. We will take these ini files and work them as their own loops. I use the net_packets filter to pull unique containers from each host, this may need to be adjusted (cpu_limit didnt pull any hosts from one of my dockers)
for h in "${HOSTS[@]}"
do
h=$(tr -d ' ' <<< "$h")
curl http://$h:19999/api/v1/charts | grep -oP 'chart=cgroup_\K\w+(?=.net_packets)' >> $h.containers.ini
done
## read in a container list and append it to our page before moving on to the next host
for h in "${HOSTS[@]}"
do
h=$(tr -d ' ' <<< "$h")
readarray CONTAINERS < $h.containers.ini
# iterate over the dashboard for each host, adding it to the docker.html
for c in "${CONTAINERS[@]}"
do
c=$(tr -d ' ' <<< "$c")
echo ' <div style="margin-right: 10px; width: 20%;"
class="netdata-container-easypiechart"
data-host="http://'$h':19999"
data-netdata="cgroup_'$c'.mem_usage"
data-dimensions="ram"
data-chart-library="easypiechart"
data-title="Memory"
data-easypiechart-max-value=512
data-width="8%"
data-after="-360"
data-points="360"
data-colors="#16A086"
role="application">
</div>
<div style="margin-right: 10px; width: 20%;"
class="netdata-container-easypiechart"
data-host="http://'$h':19999"
data-netdata="cgroup_'$c'.net_eth0"
data-dimensions="received"
data-chart-library="easypiechart"
data-title="NetIn"
data-width="8%"
data-after="-360"
data-points="360"
data-colors="#16A086"
role="application">
</div>
<div style="margin-right: 10px; width: 20%;"
class="netdata-container-easypiechart"
data-host="http://'$h':19999"
data-netdata="cgroup_'$c'.net_eth0"
data-dimensions="sent"
data-chart-library="easypiechart"
data-title="NetOut"
data-width="8%"
data-after="-360"
data-points="360"
data-colors="#16A086"
role="application">
</div>
<div style="margin-right: 10px; width: 20%;"
class="netdata-container-gauge"
data-host="http://'$h':19999"
data-netdata="cgroup_'$c'.cpu"
data-chart-library="gauge"
data-title="'$h'['$c']" data-units="%"
data-gauge-max-value="100"
data-width="15%"
data-after="-360"
data-points="360"
data-colors="#16A086"
role="application">
</div>
<div style="margin-right: 10px; width: 20%;"
class="netdata-container-easypiechart"
data-host="http://'$h':19999"
data-netdata="cgroup_'$c'.throttle_io"
data-dimensions="write"
data-append-options="percentage"
data-chart-library="easypiechart"
data-easypiechart-max-value="10240"
data-title="Disk Write"
data-width="8%"
data-after="-360"
data-points="360"
data-colors="#16A086"
role="application">
</div>
<div style="margin-right: 10px; width: 20%;"
class="netdata-container-easypiechart"
data-host="http://'$h':19999"
data-netdata="cgroup_'$c'.throttle_io"
data-dimensions="read"
data-chart-library="easypiechart"
data-easypiechart-max-value="10240"
data-title="Disk Read"
data-width="8%"
data-after="-360"
data-points="360"
data-colors="#16A086"
role="application">
</div>
<br>'>> docker.html
done
done
# finish up the file
echo '
</div>
</body>
</html>' >> docker.html