Created
August 27, 2020 18:06
-
-
Save tangoslee/1be8e1414ae708bc83c4d023fcc4f943 to your computer and use it in GitHub Desktop.
Average Memory Usage of some process
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| #ps --no-headers -o "rss,cmd" -C php-fpm7.4 | awk '{ sum+=$1 } END { printf ("%d%s\n", sum/NR/1024,"MB") }' | |
| function chk() { | |
| name="$1" | |
| val=$(ps --no-headers -o "rss,cmd" -C "$name" | awk '{ sum+=$1 } END { printf ("%d%s\n", sum/NR/1024,"MB") }') | |
| printf " %10s |" $val | |
| } | |
| function header() { | |
| printf "| %-24s | %10s | %10s | %10s | %10s |" "Date" "Node" "Nginx" "PHP" "PHP-FPM" | |
| echo "" | |
| } | |
| function body() { | |
| printf "| %24s |" $now | |
| chk node | |
| chk nginx | |
| chk php | |
| chk php-fpm7.4 | |
| echo "" | |
| } | |
| LOG_FILE="/var/log/proc_mem_$(date +%Y%m%d).log" | |
| now=$(date +%Y-%m-%dT%T%z) | |
| if [ "$1" = "--log" ];then | |
| LOG=1 | |
| else | |
| LOG=0 | |
| fi | |
| if [ $LOG -eq 0 ]; then | |
| header | |
| body | |
| else | |
| [ -f "$LOG_FILE" ] || header > "$LOG_FILE" | |
| body >> "$LOG_FILE" | |
| fi |
Author
tangoslee
commented
Aug 27, 2020
- Output
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment