mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-22 02:51:03 +00:00
[docker_] add multigraph support
Signed-off-by: Olivier Mehani <shtrom@ssji.net>
This commit is contained in:
parent
2482518826
commit
1fa5558afd
1 changed files with 194 additions and 153 deletions
|
@ -4,8 +4,9 @@
|
||||||
|
|
||||||
docker_ - Docker wildcard-plugin to monitor a L<Docker|https://www.docker.com> host.
|
docker_ - Docker wildcard-plugin to monitor a L<Docker|https://www.docker.com> host.
|
||||||
|
|
||||||
This wildcard plugin provides at the moment only the suffixes C<containers>, C<images>, C<status>,
|
This wildcard plugin provides series C<containers>, C<images>, C<status>,
|
||||||
C<volumes>, C<cpu>, C<memory> and C<network>.
|
C<volumes>, C<cpu>, C<memory> and C<network> as separate graphs. It also
|
||||||
|
supports a C<multi> suffix that provides all of those as a multigraph.
|
||||||
|
|
||||||
=head1 INSTALLATION
|
=head1 INSTALLATION
|
||||||
|
|
||||||
|
@ -14,6 +15,12 @@ C<volumes>, C<cpu>, C<memory> and C<network>.
|
||||||
|
|
||||||
=over 2
|
=over 2
|
||||||
|
|
||||||
|
If you want all the graphs as a multigraph, create a single multi symlink.
|
||||||
|
|
||||||
|
ln -s /usr/share/munin/plugins/docker_ /etc/munin/plugins/docker_multi
|
||||||
|
|
||||||
|
Or choose a subset of those you want.
|
||||||
|
|
||||||
ln -s /usr/share/munin/plugins/docker_ /etc/munin/plugins/docker_containers
|
ln -s /usr/share/munin/plugins/docker_ /etc/munin/plugins/docker_containers
|
||||||
ln -s /usr/share/munin/plugins/docker_ /etc/munin/plugins/docker_cpu
|
ln -s /usr/share/munin/plugins/docker_ /etc/munin/plugins/docker_cpu
|
||||||
ln -s /usr/share/munin/plugins/docker_ /etc/munin/plugins/docker_images
|
ln -s /usr/share/munin/plugins/docker_ /etc/munin/plugins/docker_images
|
||||||
|
@ -66,12 +73,12 @@ This section has been reverse-engineered from git logs
|
||||||
|
|
||||||
* Rowan Wookey <admin@rwky.net>: performance improvement
|
* Rowan Wookey <admin@rwky.net>: performance improvement
|
||||||
|
|
||||||
* Olivier Mehani <shtrom@ssji.net>: Network support, ClientWrapper, gerenal cleanup
|
* Olivier Mehani <shtrom@ssji.net>: Network support, ClientWrapper, general cleanup, multigraph
|
||||||
|
|
||||||
=head1 MAGIC MARKERS
|
=head1 MAGIC MARKERS
|
||||||
|
|
||||||
#%# family=auto
|
#%# family=auto
|
||||||
#%# capabilities=autoconf suggest
|
#%# capabilities=autoconf suggest multigraph
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
"""
|
"""
|
||||||
|
@ -315,159 +322,123 @@ def volume_summary(volume):
|
||||||
return summary
|
return summary
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def status(client, mode):
|
||||||
try:
|
if mode == "config":
|
||||||
mode = sys.argv[1]
|
print("graph_title Docker status")
|
||||||
except IndexError:
|
print("graph_vlabel containers")
|
||||||
mode = ""
|
print("graph_category virtualization")
|
||||||
wildcard = sys.argv[0].split("docker_")[1].split("_")[0]
|
print("graph_total All containers")
|
||||||
|
print("running.label RUNNING")
|
||||||
|
print("running.draw AREASTACK")
|
||||||
|
print("running.info Running containers can be manipulated with "
|
||||||
|
"`docker container [attach|kill|logs|pause|restart|stop] <NAME>` or "
|
||||||
|
"commands run in them with `docker container exec "
|
||||||
|
"[--detach|--interactive,--privileged,--tty] <NAME> <COMMAND>`"
|
||||||
|
)
|
||||||
|
print("unhealthy.label UNHEALTHY")
|
||||||
|
print("unhealthy.draw AREASTACK")
|
||||||
|
print("unhealthy.warning 1")
|
||||||
|
print("unhealthy.info Unhealthy containers can be restarted with "
|
||||||
|
"`docker container restart <NAME>`")
|
||||||
|
print("paused.label PAUSED")
|
||||||
|
print("paused.draw AREASTACK")
|
||||||
|
print("paused.info Paused containers can be resumed with "
|
||||||
|
"`docker container unpause <NAME>`")
|
||||||
|
print("created.label CREATED")
|
||||||
|
print("created.draw AREASTACK")
|
||||||
|
print("created.info New containers can be created with "
|
||||||
|
"`docker container create --name <NAME> <IMAGE_ID >` or "
|
||||||
|
"`docker container run --name <NAME> <IMAGE_ID> <COMMAND>`")
|
||||||
|
print("restarting.label RESTARTING")
|
||||||
|
print("restarting.draw AREASTACK")
|
||||||
|
print("restarting.info Containers can be restarted with "
|
||||||
|
"`docker container restart <NAME>`")
|
||||||
|
print("removing.label REMOVING")
|
||||||
|
print("removing.draw AREASTACK")
|
||||||
|
print("removing.info Containers can be removed with "
|
||||||
|
"`docker container rm <NAME>`")
|
||||||
|
print("exited.label EXITED")
|
||||||
|
print("exited.draw AREASTACK")
|
||||||
|
print("exited.info Exited containers can be started with "
|
||||||
|
"`docker container start [--attach] <NAME>`")
|
||||||
|
print("dead.label DEAD")
|
||||||
|
print("dead.draw AREASTACK")
|
||||||
|
print("dead.warning 1")
|
||||||
|
print("dead.info Dead containers can be started with "
|
||||||
|
"`docker container start <NAME>`")
|
||||||
|
else:
|
||||||
|
print_containers_status(client)
|
||||||
|
|
||||||
try:
|
|
||||||
import docker
|
|
||||||
client = docker.from_env()
|
|
||||||
if mode == "autoconf":
|
|
||||||
client.ping()
|
|
||||||
print('yes')
|
|
||||||
sys.exit(0)
|
|
||||||
except Exception as e:
|
|
||||||
print(f'no ({e})')
|
|
||||||
if mode == "autoconf":
|
|
||||||
sys.exit(0)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
if mode == "suggest":
|
def containers(client, mode):
|
||||||
print("cpu")
|
if mode == "config":
|
||||||
print("images")
|
print("graph_title Docker containers")
|
||||||
print("memory")
|
print("graph_vlabel containers")
|
||||||
print("network")
|
print("graph_category virtualization")
|
||||||
print("status")
|
print("containers_quantity.label Containers")
|
||||||
print("volumes")
|
else:
|
||||||
sys.exit(0)
|
print('containers_quantity.value', len(client.containers))
|
||||||
|
|
||||||
client = ClientWrapper(client,
|
|
||||||
exclude_re=os.getenv('EXCLUDE_CONTAINER_NAME'))
|
|
||||||
|
|
||||||
if wildcard == "status":
|
def images(client, mode):
|
||||||
if mode == "config":
|
if mode == "config":
|
||||||
print("graph_title Docker status")
|
print("graph_title Docker images")
|
||||||
print("graph_vlabel containers")
|
print("graph_vlabel images")
|
||||||
print("graph_category virtualization")
|
print("graph_category virtualization")
|
||||||
print("graph_total All containers")
|
print("graph_total All images")
|
||||||
print("running.label RUNNING")
|
print("intermediate_quantity.label Intermediate images")
|
||||||
print("running.draw AREASTACK")
|
print("intermediate_quantity.draw AREASTACK")
|
||||||
print("running.info Running containers can be manipulated with "
|
print("intermediate_quantity.info All unused images can be deleted with "
|
||||||
"`docker container [attach|kill|logs|pause|restart|stop] <NAME>` or "
|
"`docker image prune --all`")
|
||||||
"commands run in them with `docker container exec "
|
print("images_quantity.label Images")
|
||||||
"[--detach|--interactive,--privileged,--tty] <NAME> <COMMAND>`"
|
print("images_quantity.draw AREASTACK")
|
||||||
)
|
print("images_quantity.info Images can be used in containers with "
|
||||||
print("unhealthy.label UNHEALTHY")
|
"`docker container create --name <NAME> <IMAGE_ID >` or "
|
||||||
print("unhealthy.draw AREASTACK")
|
"`docker container run --name <NAME> <IMAGE_ID> <COMMAND>`")
|
||||||
print("unhealthy.warning 1")
|
print("dangling_quantity.label Dangling images")
|
||||||
print("unhealthy.info Unhealthy containers can be restarted with "
|
print("dangling_quantity.draw AREASTACK")
|
||||||
"`docker container restart <NAME>`")
|
print("dangling_quantity.info Dangling images can be deleted with "
|
||||||
print("paused.label PAUSED")
|
"`docker image prune`"
|
||||||
print("paused.draw AREASTACK")
|
"or tagged with `docker image tag <IMAGE_ID> <NAME>`")
|
||||||
print("paused.info Paused containers can be resumed with "
|
print("dangling_quantity.warning 10")
|
||||||
"`docker container unpause <NAME>`")
|
else:
|
||||||
print("created.label CREATED")
|
print_images_count(client)
|
||||||
print("created.draw AREASTACK")
|
|
||||||
print("created.info New containers can be created with "
|
|
||||||
"`docker container create --name <NAME> <IMAGE_ID >` or "
|
def volumes(client, mode):
|
||||||
"`docker container run --name <NAME> <IMAGE_ID> <COMMAND>`")
|
if mode == "config":
|
||||||
print("restarting.label RESTARTING")
|
print("graph_title Docker volumes")
|
||||||
print("restarting.draw AREASTACK")
|
print("graph_vlabel volumes")
|
||||||
print("restarting.info Containers can be restarted with "
|
print("graph_category virtualization")
|
||||||
"`docker container restart <NAME>`")
|
print("volumes_quantity.label Volumes")
|
||||||
print("removing.label REMOVING")
|
print("volumes_quantity.draw AREASTACK")
|
||||||
print("removing.draw AREASTACK")
|
print("volumes_quantity.info Unused volumes can be deleted with "
|
||||||
print("removing.info Containers can be removed with "
|
"`docker volume prune`")
|
||||||
"`docker container rm <NAME>`")
|
else:
|
||||||
print("exited.label EXITED")
|
print('volumes_quantity.value', len(client.volumes))
|
||||||
print("exited.draw AREASTACK")
|
print('volumes_quantity.extinfo', ', '.join(volume_summary(v) for v in client.volumes))
|
||||||
print("exited.info Exited containers can be started with "
|
|
||||||
"`docker container start [--attach] <NAME>`")
|
|
||||||
print("dead.label DEAD")
|
def cpu(client, mode):
|
||||||
print("dead.draw AREASTACK")
|
if mode == "config":
|
||||||
print("dead.warning 1")
|
graphlimit = str(os.cpu_count() * 100)
|
||||||
print("dead.info Dead containers can be started with "
|
print("graph_title Docker containers CPU usage")
|
||||||
"`docker container start <NAME>`")
|
print("graph_args --base 1000 -r --lower-limit 0 --upper-limit " + graphlimit)
|
||||||
else:
|
print("graph_scale no")
|
||||||
print_containers_status(client)
|
print("graph_period second")
|
||||||
elif wildcard == "containers":
|
print("graph_vlabel CPU usage (%)")
|
||||||
if mode == "config":
|
print("graph_category virtualization")
|
||||||
print("graph_title Docker containers")
|
print("graph_info This graph shows docker container CPU usage.")
|
||||||
print("graph_vlabel containers")
|
print("graph_total Total CPU usage")
|
||||||
print("graph_category virtualization")
|
for container in client.all_containers:
|
||||||
print("containers_quantity.label Containers")
|
print("{}.label {}".format(container.name, container.name))
|
||||||
else:
|
print("{}.draw AREASTACK".format(container.name))
|
||||||
print('containers_quantity.value', len(client.containers))
|
print("{}.info {}".format(container.name, container_attributes(container)))
|
||||||
elif wildcard == "images":
|
else:
|
||||||
if mode == "config":
|
print_containers_cpu(client)
|
||||||
print("graph_title Docker images")
|
|
||||||
print("graph_vlabel images")
|
|
||||||
print("graph_category virtualization")
|
def network(client, mode):
|
||||||
print("graph_total All images")
|
|
||||||
print("intermediate_quantity.label Intermediate images")
|
|
||||||
print("intermediate_quantity.draw AREASTACK")
|
|
||||||
print("intermediate_quantity.info All unused images can be deleted with "
|
|
||||||
"`docker image prune --all`")
|
|
||||||
print("images_quantity.label Images")
|
|
||||||
print("images_quantity.draw AREASTACK")
|
|
||||||
print("images_quantity.info Images can be used in containers with "
|
|
||||||
"`docker container create --name <NAME> <IMAGE_ID >` or "
|
|
||||||
"`docker container run --name <NAME> <IMAGE_ID> <COMMAND>`")
|
|
||||||
print("dangling_quantity.label Dangling images")
|
|
||||||
print("dangling_quantity.draw AREASTACK")
|
|
||||||
print("dangling_quantity.info Dangling images can be deleted with "
|
|
||||||
"`docker image prune`"
|
|
||||||
"or tagged with `docker image tag <IMAGE_ID> <NAME>`")
|
|
||||||
print("dangling_quantity.warning 10")
|
|
||||||
else:
|
|
||||||
print_images_count(client)
|
|
||||||
elif wildcard == "volumes":
|
|
||||||
if mode == "config":
|
|
||||||
print("graph_title Docker volumes")
|
|
||||||
print("graph_vlabel volumes")
|
|
||||||
print("graph_category virtualization")
|
|
||||||
print("volumes_quantity.label Volumes")
|
|
||||||
print("volumes_quantity.draw AREASTACK")
|
|
||||||
print("volumes_quantity.info Unused volumes can be deleted with "
|
|
||||||
"`docker volume prune`")
|
|
||||||
else:
|
|
||||||
print('volumes_quantity.value', len(client.volumes))
|
|
||||||
print('volumes_quantity.extinfo', ', '.join(volume_summary(v) for v in client.volumes))
|
|
||||||
elif wildcard == "cpu":
|
|
||||||
if mode == "config":
|
|
||||||
graphlimit = str(os.cpu_count() * 100)
|
|
||||||
print("graph_title Docker containers CPU usage")
|
|
||||||
print("graph_args --base 1000 -r --lower-limit 0 --upper-limit " + graphlimit)
|
|
||||||
print("graph_scale no")
|
|
||||||
print("graph_period second")
|
|
||||||
print("graph_vlabel CPU usage (%)")
|
|
||||||
print("graph_category virtualization")
|
|
||||||
print("graph_info This graph shows docker container CPU usage.")
|
|
||||||
print("graph_total Total CPU usage")
|
|
||||||
for container in client.all_containers:
|
|
||||||
print("{}.label {}".format(container.name, container.name))
|
|
||||||
print("{}.draw AREASTACK".format(container.name))
|
|
||||||
print("{}.info {}".format(container.name, container_attributes(container)))
|
|
||||||
else:
|
|
||||||
print_containers_cpu(client)
|
|
||||||
elif wildcard == "memory":
|
|
||||||
if mode == "config":
|
|
||||||
print("graph_title Docker containers memory usage")
|
|
||||||
print("graph_args --base 1024 -l 0")
|
|
||||||
print("graph_vlabel Bytes")
|
|
||||||
print("graph_category virtualization")
|
|
||||||
print("graph_info This graph shows docker container memory usage.")
|
|
||||||
print("graph_total Total memory usage")
|
|
||||||
for container in client.all_containers:
|
|
||||||
print("{}.label {}".format(container.name, container.name))
|
|
||||||
print("{}.draw AREASTACK".format(container.name))
|
|
||||||
print("{}.info {}".format(container.name, container_attributes(container)))
|
|
||||||
else:
|
|
||||||
print_containers_memory(client)
|
|
||||||
elif wildcard == "network":
|
|
||||||
if mode == "config":
|
if mode == "config":
|
||||||
print("graph_title Docker containers network usage")
|
print("graph_title Docker containers network usage")
|
||||||
print("graph_args --base 1024 -l 0")
|
print("graph_args --base 1024 -l 0")
|
||||||
|
@ -492,5 +463,75 @@ def main():
|
||||||
print_containers_network(client)
|
print_containers_network(client)
|
||||||
|
|
||||||
|
|
||||||
|
def memory(client, mode):
|
||||||
|
if mode == "config":
|
||||||
|
print("graph_title Docker containers memory usage")
|
||||||
|
print("graph_args --base 1024 -l 0")
|
||||||
|
print("graph_vlabel Bytes")
|
||||||
|
print("graph_category virtualization")
|
||||||
|
print("graph_info This graph shows docker container memory usage.")
|
||||||
|
print("graph_total Total memory usage")
|
||||||
|
for container in client.all_containers:
|
||||||
|
print("{}.label {}".format(container.name, container.name))
|
||||||
|
print("{}.draw AREASTACK".format(container.name))
|
||||||
|
print("{}.info {}".format(container.name, container_attributes(container)))
|
||||||
|
else:
|
||||||
|
print_containers_memory(client)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
series = [
|
||||||
|
'cpu',
|
||||||
|
'images',
|
||||||
|
'memory',
|
||||||
|
'network',
|
||||||
|
'status',
|
||||||
|
'volumes',
|
||||||
|
]
|
||||||
|
|
||||||
|
try:
|
||||||
|
mode = sys.argv[1]
|
||||||
|
except IndexError:
|
||||||
|
mode = ""
|
||||||
|
wildcard = sys.argv[0].split("docker_")[1].split("_")[0]
|
||||||
|
|
||||||
|
try:
|
||||||
|
import docker
|
||||||
|
client = docker.from_env()
|
||||||
|
if mode == "autoconf":
|
||||||
|
client.ping()
|
||||||
|
print('yes')
|
||||||
|
sys.exit(0)
|
||||||
|
except Exception as e:
|
||||||
|
print(f'no ({e})')
|
||||||
|
if mode == "autoconf":
|
||||||
|
sys.exit(0)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if mode == "suggest":
|
||||||
|
# The multigraph covers all other graphs,
|
||||||
|
# so we only need to suggest one
|
||||||
|
print("multi")
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
client = ClientWrapper(client,
|
||||||
|
exclude_re=os.getenv('EXCLUDE_CONTAINER_NAME'))
|
||||||
|
|
||||||
|
if wildcard in series:
|
||||||
|
# dereference the function name by looking in the globals()
|
||||||
|
# this assumes that the function name matches the series name exactly
|
||||||
|
# if this were to change, a different approach would be needed,
|
||||||
|
# most likely using a Dict of series name string to callable
|
||||||
|
globals()[wildcard](client, mode)
|
||||||
|
elif wildcard == 'multi':
|
||||||
|
for s in series:
|
||||||
|
print(f'multigraph docker_{s}')
|
||||||
|
# ditto
|
||||||
|
globals()[s](client, mode)
|
||||||
|
else:
|
||||||
|
print(f'unknown series ({wildcard})', file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue