That's the most wonderful haiku I've ever come across!!
Unfortunately my command line grew quite a bit. Fortunately, it does exactly as it's told to!
CPU usage:
Code:
export LC_ALL=C && ps haxo %cpu$'\t'args | grep -v ]$ | awk '{y=""; for (i=2; i<=NF; i++) y=y $i; {x[y] += $1}} END{ for(z in x) {print x[z]"%\t" z}}' | sort -k1g
Result:
Code:
0.1% php-fpm:pool2
0.9% /usr/sbin/snmpd-c/etc/snmp/snmpd.conf-LS5d-Lf/dev/null-p/var/run/snmpd.pid
1.3% top
2.2% php-fpm:poolsupport
7% pshaxo%cpu?args
41.4% php-fpm:poolwww
60% /usr/sbin/glusterfs--volfile=/etc/glusterfs/glusterfs-www.vol/var/www
MEM usage:
Code:
export LC_ALL=C && ps haxo %mem$'\t'args | grep -v ]$ | awk '{y=""; for (i=2; i<=NF; i++) y=y $i; {x[y] += $1}} END{ for(z in x) {print x[z]"%\t" z}}' | sort -k1g
Result:
Code:
0% -bash
0.1% clamd
0.1% /usr/sbin/glusterfs--volfile=/etc/glusterfs/glusterfs-upload.vol/var/upload
3.9% /usr/sbin/glusterfs--volfile=/etc/glusterfs/glusterfs-www.vol/var/www
Explanation:
- export is so sort reads the decimals properly.
- ps is for fetching the processes, this time with a cleaner output.
- awk does the heavy lifting. We define a variable with the full command and arguments, then sum the percentages of all the seperate processes that have the same name.
- sort does as it says on the tin.
Edit: I spoke too soon. I ran the MEM command on a machine that's working hard and it gave me percentages over 100. The same thing happened with the older command. I'd expected this on CPU but not RAM.
New command:
Code:
1.5% clamd
2.4% php-fpm: pool ru-partner
15.6% php-fpm: pool misc
47.1% php-fpm: pool photowwwru
70% php-fpm: pool wwwru
Old command:
Code:
php-fpm: 134.3%
clamd 1.5%
/usr/sbin/glusterfs 1.2%
Bookmarks