Skip to content

Instantly share code, notes, and snippets.

@EHJ-52n
Created February 13, 2020 09:03
Show Gist options
  • Save EHJ-52n/800bc93c2b3c6ea34dcd72ddab3b5596 to your computer and use it in GitHub Desktop.
Save EHJ-52n/800bc93c2b3c6ea34dcd72ddab3b5596 to your computer and use it in GitHub Desktop.
munin docker status pluins
#!/bin/bash
#
# Author : c.autermann@52north.org
# License: To Be Defined
#
states=(starting healthy unhealthy)
function output_config() {
echo "graph_title Docker container health"
echo "graph_category virtualization"
echo "graph_info This graph shows the Docker container health states"
echo "graph_vlable Number of containers"
echo "graph_order unknown ${states[@]} total"
echo "graph_args -l 0"
echo "unknown.label unknown"
echo "unknown.draw AREA"
echo "unknown.info The number of containers without a health check."
echo "unknown.colour 808080"
echo "starting.label starting"
echo "starting.draw STACK"
echo "starting.info The number of starting containers."
echo "starting.colour 0080C0"
echo "healthy.label healthy"
echo "healthy.draw STACK"
echo "healthy.info The number of healthy containers."
echo "healthy.colour 22FF22"
echo "unhealthy.label unhealthy"
echo "unhealthy.draw STACK"
echo "unhealthy.info The number of unhealthy containers."
echo "unhealthy.colour FF0000"
echo "total.label total"
echo "total.draw LINE1"
echo "total.info The total number of containers."
echo "total.colour 000000"
}
function output_values() {
values=$(docker inspect --format '{{.State.Health|json}}' $(docker ps -aq) | jq -r '.Status')
echo "unknown.value $(grep -c "^null$"<<<"${values}" || true)"
for state in ${states[@]}; do
echo "${state}.value $(grep -c "^${state}$"<<<"${values}" || true)"
done
echo "total.value $(wc -l<<<"${values}")"
}
output_usage() {
echo "${0##*/} - munin plugin to graph docker container health"
echo "Usage: ${0##*/} [config|help]"
}
case $# in
0)
output_values
;;
1)
case $1 in
config)
output_config
;;
help)
output_usage
;;
*)
output_usage >&2
exit 1
esac
;;
*)
output_usage >&2
exit 1
;;
esac
#!/bin/bash
#
# Author : c.autermann@52north.org
# License: To Be Defined
#
states=(created restarting running paused exited dead)
function output_config() {
echo "graph_title Docker container status"
echo "graph_category virtualization"
echo "graph_info This graph shows the Docker container states"
echo "graph_vlable Number of containers"
echo "graph_order ${states[@]} total"
echo "graph_args -l 0"
echo
echo "created.label created"
echo "created.draw AREA"
echo "created.info The number of created containers."
echo "created.colour 00AAAA"
echo "restarting.label restarting"
echo "restarting.draw STACK"
echo "restarting.info The number of restarting containers."
echo "restarting.colour 0080C0"
echo "running.label running"
echo "running.draw STACK"
echo "running.info The number of running containers."
echo "running.colour 22FF22"
echo "paused.label paused"
echo "paused.draw STACK"
echo "paused.info The number of paused containers."
echo "paused.colour FF8000"
echo "exited.label exited"
echo "exited.draw STACK"
echo "exited.info The number of exited containers."
echo "exited.colour FF0000"
echo "dead.label dead"
echo "dead.draw STACK"
echo "dead.info The number of dead containers."
echo "dead.colour CC0000"
echo "total.label total"
echo "total.draw LINE1"
echo "total.info The total number of containers."
echo "total.colour 000000"
}
function output_values() {
values="$(docker inspect -f '{{.State.Status}}' $(docker ps -aq))"
for state in "${states[@]}"; do
echo "${state}.value $(grep -Fc "${state}"<<<"${values}" || true)"
done
echo "total.value $(wc -l<<<"${values}")"
}
output_usage() {
echo "${0##*/} - munin plugin to graph docker container status"
echo "Usage: ${0##*/} [config|help]"
}
case $# in
0)
output_values
;;
1)
case $1 in
config)
output_config
;;
help)
output_usage
;;
*)
output_usage >&2
exit 1
esac
;;
*)
output_usage >&2
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment