Skip to content

Instantly share code, notes, and snippets.

@chusiang
Last active November 10, 2016 05:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chusiang/012c40e423c13b02e5296cac3caab4ec to your computer and use it in GitHub Desktop.
Save chusiang/012c40e423c13b02e5296cac3caab4ec to your computer and use it in GitHub Desktop.
Monitoring specific process memory usage with Shell Script.
#!/bin/bash
# ============================================================
# Author: Chu-Siang Lai / chusiang (at) drx.tw
# Filename: memory-check.sh
# Modified: 2016-10-24 15:47
# Description: Monitoring process memory usage.
#
# `ps aux` 結果中的 RSS (resident set size) 的單位是 KB,而 zabbix-
# server 用的單位是 B,所以得多乘以 1024 才符合真實情況。
#
# Reference:
#
# 1. 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 * 1024 }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment