diff --git a/plugins/systemd/example-graphs/systemd_mem-day.png b/plugins/systemd/example-graphs/systemd_mem-day.png new file mode 100644 index 00000000..43018fe9 Binary files /dev/null and b/plugins/systemd/example-graphs/systemd_mem-day.png differ diff --git a/plugins/systemd/systemd_mem b/plugins/systemd/systemd_mem new file mode 100755 index 00000000..9604d936 --- /dev/null +++ b/plugins/systemd/systemd_mem @@ -0,0 +1,117 @@ +#!/bin/sh +: << =cut + +=head1 NAME + +systemd_mem - Plugin to graph the memory usage of multiple systemd services as reported by systemctl + +=head1 CONFIGURATION + +The environment variable "services" is used to provide a space separated list of services to graph. + +Example: + [systemd_mem] + env.services apache2 tomcat9 mysql + +env.services defaults to "munin-node". + +=head1 VERSION + +1.0 + +=head1 AUTHOR + +Paul Alexandrow + +=head1 LICENSE + +Copyright 2021 Paul Alexandrow, paul@alexandrow.org + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software +and associated documentation files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or +substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +=head1 MAGIC MARKERS + +#%# family=auto +#%# capabilities=autoconf + +=cut + +. "$MUNIN_LIBDIR/plugins/plugin.sh" + +output_config() { + echo "graph_title Systemd Service Memory Usage" + echo "graph_info Memory usage for selected services as reported by systemctl" + echo "graph_vlabel bytes" + echo "graph_args --base 1024 --lower-limit 0" + echo "graph_category memory" + for service in ${services:-"munin-node"}; do + clean_name="$(clean_fieldname "$service")" + description=$(systemctl show "$service" --all | grep ^Description= | cut -d '=' -f 2) + printf "%s.label %s\n" "$clean_name" "$description" + printf "%s.info memory usage\n" "$clean_name" + done +} + +output_values() { + for service in ${services:-"munin-node"}; do + clean_name="$(clean_fieldname "$service")" + usage=$(systemctl show "$service" --all | grep ^MemoryCurrent= | cut -d '=' -f 2) + if [ "$usage" = "[not set]" ]; then + usage=0 + fi + printf "%s.value %d\n" "$clean_name" "$usage" + done +} + +output_usage() { + printf >&2 "%s - munin plugin to graph memory usage for systemd services\n" "${0##*/}" + printf >&2 "Usage: %s [config]\n" "${0##*/}" +} + +output_autoconf() { + if command -v systemctl >/dev/null 2>&1; then + echo "yes" + else + echo "no (systemctl not found)"; + fi +} + +case $# in + 0) + output_values + ;; + 1) + case $1 in + autoconf) + output_autoconf + ;; + config) + output_config + ;; + fetch) + output_values + ;; + *) + output_usage + exit 1 + ;; + esac + ;; + *) + output_usage + exit 1 + ;; +esac