From b21206c68cb2ec7885522a15a11687da0fb4cd67 Mon Sep 17 00:00:00 2001 From: Andreas Perhab Date: Thu, 14 Oct 2021 14:34:35 +0200 Subject: [PATCH] systemd_mem: add env option to monitor all services --- plugins/systemd/systemd_mem | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/plugins/systemd/systemd_mem b/plugins/systemd/systemd_mem index 3f743054..7a6df4d3 100755 --- a/plugins/systemd/systemd_mem +++ b/plugins/systemd/systemd_mem @@ -15,13 +15,20 @@ Example: env.services defaults to "munin-node". +As an alternative you can use all_services to display memory for all running systemd services + [systemd_mem] + env.all_services true + +all_services shows memory for all running units of type service. + =head1 VERSION -1.0 +1.1 -=head1 AUTHOR +=head1 AUTHORS Paul Alexandrow +Andreas Perhab =head1 LICENSE @@ -51,13 +58,22 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SO . "$MUNIN_LIBDIR/plugins/plugin.sh" +for_services() { + if [ "$all_services" != "" ]; then + systemctl --type=service --state=running --no-pager --no-legend --output=short-precise \ + | awk '{sub(".service$", "", $1); print $1}' + else + echo ${services:-"munin-node"} + fi +} + 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 + for service in $(for_services); do clean_name="$(clean_fieldname "$service")" description=$(systemctl show "$service" --property=Description | cut -d '=' -f 2) warning=$(systemctl show "$service" --property=MemoryHigh | cut -d '=' -f 2) @@ -77,7 +93,7 @@ output_config() { } output_values() { - for service in ${services:-"munin-node"}; do + for service in $(for_services); do clean_name="$(clean_fieldname "$service")" usage=$(systemctl show "$service" --property=MemoryCurrent | cut -d '=' -f 2) if [ "$usage" = "[not set]" ]; then