1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-21 10:39:53 +00:00
Munin-Contrib/plugins/systemd/systemd_mem
Paul Alexandrow 11c6d82791
initial commit of systemd_mem (v1.0) (#1165)
systemctl calculates memory consumption quite differently than existing plugins, which usually query /proc/.
This plugin monitors what memory a service uses according to systemctl.
2021-01-31 14:56:01 +01:00

117 lines
3.3 KiB
Bash
Executable file

#!/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 <paul@alexandrow.org>
=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