Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script to monitor the usage of CPU, memory by a process via `top`
#!/bin/sh
# Usage: ./monitor-usage.sh <PID of the process>
# Output: top.dat with lines such as `1539689171 305m 2.0`, i.e. unix time - memory with m/g suffix - CPU load in %
# To plot the output, see https://gist.github.com/jakubholynet/931a3441982c833f5f8fcdcf54d05c91
export PID=$1
rm top.dat
while true; do top -p $PID -bMn 1 | egrep '^ *[0-9]+' | awk -v now=$(date +%s.%N) '{print now,$6,$9}' >> top.dat; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment