From 62d2093b8ded4e355437877625905b1747c7cf0b Mon Sep 17 00:00:00 2001 From: Jonny Lai Date: Mon, 24 Oct 2016 13:44:58 +0800 Subject: [PATCH 1/3] add User parameters of monitoring process memory usage - Total memory used by Python process? | Stack Overflow - http://stackoverflow.com/a/40173829/686105 --- README.md | 5 + bin/memory-check.sh | 16 +++ ...Template Specific Process Memory Usage.xml | 110 ++++++++++++++++++ zabbix_agentd.conf.d/memory_sum.conf | 8 ++ 4 files changed, 139 insertions(+) create mode 100644 bin/memory-check.sh create mode 100644 templates/Template Specific Process Memory Usage.xml create mode 100644 zabbix_agentd.conf.d/memory_sum.conf diff --git a/README.md b/README.md index 12fe5a8..fd3ecbe 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ Please let us know if you have any questions or concerns. * [Iptables](#template-app-iptables) * [lm_sensors](#template-app-lm_sensors) * [mdadm](#template-app-mdadm) + * [Memory Usage of Specific Process](#template-specific-process-memory-usage) * [Monit](#template-app-monit) * [MySQL](#template-app-mysqld) * [MySQL Slave](#template-app-mysql-slave) @@ -64,6 +65,7 @@ Please let us know if you have any questions or concerns. * [Inventory](#template-inventory) * [Dell OMSA](#template-omsa) * [SELinux](#template-selinux) + ----- ## Template App Amavisd @@ -108,6 +110,9 @@ Monitoring CPU and MotherBoard temperatures by lm_senros module. ## Template App mdadm Monitoring mdadm arrays. Checking number of corrupted disk arrays. +## Template Specific Process Memory Usage +Monitoring memory usag of Specific Process, like Python, unicorn-rails and Nginx. + ## Template App Monit Monitoring for Monit service. diff --git a/bin/memory-check.sh b/bin/memory-check.sh new file mode 100644 index 0000000..ef02031 --- /dev/null +++ b/bin/memory-check.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# ============================================================ +# Author: chusiang / chusiang (at) drx.tw +# Blog: http://note.drx.tw +# Filename: memory-check.sh +# Modified: 2016-10-24 13:05 +# Description: Monitoring memory usage of specific process. +# Reference: +# +# 1. Total memory used by Python process? | Stack Overflow +# - http://stackoverflow.com/a/40173829/686105 +# +# =========================================================== + +PROCESS_NAME="$1" +ps aux | grep $PROCESS_NAME | awk '{ sum=sum+$6 }; END { print sum }' diff --git a/templates/Template Specific Process Memory Usage.xml b/templates/Template Specific Process Memory Usage.xml new file mode 100644 index 0000000..6a5af11 --- /dev/null +++ b/templates/Template Specific Process Memory Usage.xml @@ -0,0 +1,110 @@ + + + 3.0 + 2016-10-24T05:01:54Z + + + Zabbix Templates + + + + + + + + Specific Memory Used + 900 + 200 + 0.0000 + 100.0000 + 1 + 1 + 0 + 1 + 0 + 0.0000 + 0.0000 + 0 + 0 + 0 + 0 + + + 0 + 0 + 1A7C11 + 0 + 2 + 0 + + Template Specific Process Memory Used + memory_sum[python] + + + + + + diff --git a/zabbix_agentd.conf.d/memory_sum.conf b/zabbix_agentd.conf.d/memory_sum.conf new file mode 100644 index 0000000..59355d9 --- /dev/null +++ b/zabbix_agentd.conf.d/memory_sum.conf @@ -0,0 +1,8 @@ +# ============================================================ +# Author: chusiang / chusiang (at) drx.tw +# Filename: memory_sum.conf +# Modified: 2016-10-24 13:05 +# Description: Custom UserParameter for monitoring specific process memory used. +# =========================================================== + +UserParameter=memory_sum[*],/etc/zabbix/bin/memory-check.sh "$1" From 9ce60691d738cf904e1f6bc13481ee70e91dbd58 Mon Sep 17 00:00:00 2001 From: Jonny Lai Date: Mon, 24 Oct 2016 16:42:29 +0800 Subject: [PATCH 2/3] rename memory_sum.conf to memory.conf I think the '_sum' is not necessary. --- zabbix_agentd.conf.d/{memory_sum.conf => memory.conf} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename zabbix_agentd.conf.d/{memory_sum.conf => memory.conf} (100%) diff --git a/zabbix_agentd.conf.d/memory_sum.conf b/zabbix_agentd.conf.d/memory.conf similarity index 100% rename from zabbix_agentd.conf.d/memory_sum.conf rename to zabbix_agentd.conf.d/memory.conf From 268f591379fd90d52eac329fabbaf7181e6305cf Mon Sep 17 00:00:00 2001 From: Jonny Lai Date: Mon, 24 Oct 2016 19:20:48 +0800 Subject: [PATCH 3/3] convert the memory unit for mapping zabbix-server --- bin/memory-check.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bin/memory-check.sh b/bin/memory-check.sh index ef02031..bb4e83e 100644 --- a/bin/memory-check.sh +++ b/bin/memory-check.sh @@ -5,12 +5,18 @@ # Filename: memory-check.sh # Modified: 2016-10-24 13:05 # Description: Monitoring memory usage of specific process. +# +# The RSS (resident set size) is mean memory used in KB, not B, +# so we need to `* 1024` for mapping zabbix-server. +# # Reference: # # 1. Total memory used by Python process? | Stack Overflow # - http://stackoverflow.com/a/40173829/686105 +# 2. linux - ps aux output meaning | Super User +# - http://superuser.com/a/117921/205255 # # =========================================================== PROCESS_NAME="$1" -ps aux | grep $PROCESS_NAME | awk '{ sum=sum+$6 }; END { print sum }' +ps aux | grep $PROCESS_NAME | awk '{ sum=sum+$6 }; END { print sum*1024 }'