1

My goal is to track the resource usage of a certain command in a easily parse-able time-series. Here's an example where I'm tracking all the node commands for 3 batches:

top -b -n3 | grep node                
 222097 root      20   0  954444 672616  32452 S 105.9   4.1  46:23.02 node
 221922 root      20   0  305792  51408  23900 S   0.0   0.3   0:00.58 node
 222113 root      20   0  554304 343092  23736 S   0.0   2.1   0:26.25 node
 222097 root      20   0  954444 672616  32452 S 159.8   4.1  46:27.83 node
 221922 root      20   0  305792  51408  23900 S   0.0   0.3   0:00.58 node
 222113 root      20   0  554304 343092  23736 S   0.0   2.1   0:26.25 node
 222097 root      20   0  954444 672616  32452 S 167.1   4.1  46:32.86 node
 221922 root      20   0  305792  51408  23900 S   0.0   0.3   0:00.58 node
 222113 root      20   0  554304 343092  23736 S   0.0   2.1   0:26.25 node

The problem is that there's no easy way to distinguish between batches. In this simple example it's easy to see the break point, but in a longer series, or one with more processes it becomes difficult.

With some heavy scripting we could do something fancy, but I'd like to keep it simple. Hoped for output:

 221922 root      20   0  305792  51408  23900 S   0.0   0.3   0:00.58 node
 222113 root      20   0  554304 343092  23736 S   0.0   2.1   0:26.25 node
------------------------------------------------------------------------------
 222097 root      20   0  954444 672616  32452 S 159.8   4.1  46:27.83 node
 221922 root      20   0  305792  51408  23900 S   0.0   0.3   0:00.58 node
 222113 root      20   0  554304 343092  23736 S   0.0   2.1   0:26.25 node
------------------------------------------------------------------------------
 222097 root      20   0  954444 672616  32452 S 167.1   4.1  46:32.86 node
 221922 root      20   0  305792  51408  23900 S   0.0   0.3   0:00.58 node
 222113 root      20   0  554304 343092  23736 S   0.0   2.1   0:26.25 node

1 Answer 1

1

This imperfect bash script took me less time than writing this post:

# /bin/bash

echo "Monitor process $1"
echo " for $2 batches"


for i in $(seq 1 $2); do 
    top -b -n 1 | grep $1
    echo "-------------------------------------------------";
    sleep 1
done
1
  • While this does do what it says on the label, prints out the filtered processes, it's showing the MEM consumption in percentages, which doesn't really fit my desired use-case of showing memory consumed. I understand "memory consumed" is a vague statement, but I'd like some heuristic to compare two different configurations.
    – icicleking
    Nov 25, 2020 at 14:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.