Skip to content

Instantly share code, notes, and snippets.

@etissieres
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save etissieres/9409063 to your computer and use it in GitHub Desktop.

Select an option

Save etissieres/9409063 to your computer and use it in GitHub Desktop.
Shell utils

CPU load average

$ uptime|rev|cut -d' ' -f-3|rev|sed -e 's/, / /g'

Les trois nombres correspondent à une moyenne de la charge calculée sur 1min, 5min et 15min

Memory usage

$ free|head -n2|tail -n1|sed -e 's/  */ /g'|cut -d' ' -f2-4

Les trois nombres correspondent à la mémoire totale, la mémoire utilisée et la mémoire libre

Files descriptors counts

#!/bin/bash

procs=(`ps -e -o pid,comm|tail -n+2`)
len=${#procs[@]}
i=0
disp=''
total=0
while [ $i -lt $len ]
do
  pid=${procs[$i]}
  cmd=${procs[$((i+1))]}
  of=`ls /proc/$pid/fd 2> /dev/null |wc -l`
  disp+="$of : $pid -> $cmd\n"
  i=$((i+2))
  total=$((total+of))
done
echo -e $disp|sort -n
echo "TOTAL $total"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment