[script vz_usage.sh] user_beancounters mal übersichtlich

Gagget

New Member
Habe früher als blutiger Anfänger (glaube sogar hier im Forum) mal ein "vzfree.sh" Script gefunden, das den Speicherverbrauch anhand von '/proc/user_beancounters' anzeigt. Über die Jahre hinweg hab ich das Script immer mal ein wenig verändert, um Werte erweitert bzw. die Ausgabe verschönert.

Heute dachte ich mir, evtl könnten andere Leute auch mal ne übersichtliche Darstellung der VZ Werte gebrauchen.
Ich find die Ausgabe immer recht hilfreich und interessant und evtl. gibts ja im Gegenzug auch noch paar Verbesserungsvorschläge ...

Scriptausgabe:
Code:
 RESOURCE NAME     USAGE   LIMIT VISUAL RESOURCE USAGE PERCENT FAILS

 lockedpages         0MB   2.0MB [                    ]  0.00% 0
 privvmpages     114.9MB 328.0MB [#######             ] 35.04% 7455
 shmpages         21.0MB  76.4MB [#####               ] 27.47% 3
 numproc              48     196 [####                ] 24.48% 0
 vmguarpages         0MB 160.0MB [                    ]  0.00% 0
 numtcpsock           19     496 [                    ]  3.83% 0
 numflock              4     246 [                    ]  1.62% 0
 numpty                2      16 [##                  ] 12.50% 0
 numsiginfo            1     256 [                    ]   .39% 0
 tcpsndbuf         389kB  5406kB [#                   ]  7.19% 1173459
 tcprcvbuf         294kB  5406kB [#                   ]  5.45% 0
 othersockbuf      215kB  1689kB [##                  ] 12.78% 101
 dgramrcvbuf         8kB   129kB [#                   ]  6.41% 47
 numothersock        136     496 [#####               ] 27.41% 0
 dcachesize        781kB  3336kB [####                ] 23.41% 0
 numfile            1892    5000 [#######             ] 37.84% 0
 numiptent            14      64 [####                ] 21.87% 0

vz_usage.sh:
Code:
#!/bin/sh -e

main()
{
 echo -ne "\n\033[1m RESOURCE NAME       USAGE     LIMIT "
 echo -ne "VISUAL RESOURCE USAGE PERCENT FAILS\033[0m\n\n";
 count=0
 while read vzline; do
  count=`expr $count + 1`
  if [ $count -le 3 ]; then continue; fi
  outvzvars $vzline
 done < /proc/user_beancounters
 echo ""
}

outvzvars()
{
 rsc=$1; cur=$2; max=$3; brr=$4; lmt=$5; fls=$6;

 case $rsc in
  dummy)
   continue;
  ;;
  physpages)
   continue;
  ;;
  oomguarpages)
   continue;
  ;;
  num*)
   usage=`echo "scale=1; ($max) " | bc -l`"$unt"
   limit=`echo "scale=1; ($lmt) " | bc -l`"$unt"
  ;;
  vmguarpages)
   lmt=$brr
   usage=`echo "scale=1; ($max * 4) / 1024" | bc -l`'MB'
   limit=`echo "scale=1; ($lmt * 4) / 1024" | bc -l`'MB'
  ;;
  *pages)
   usage=`echo "scale=1; ($max * 4) / 1024" | bc -l`'MB'
   limit=`echo "scale=1; ($lmt * 4) / 1024" | bc -l`'MB'
  ;;
  *buf)
   usage=`echo "scale=0; $max / 1024" | bc -l`'kB'
   limit=`echo "scale=0; $lmt / 1024" | bc -l`'kB'
  ;;
  *size)
   usage=`echo "scale=0; $max / 1024" | bc -l`'kB'
   limit=`echo "scale=0; $lmt / 1024" | bc -l`'kB'
  ;;
 esac

 outtext "" 1
 outtext $rsc 15
 outvar $usage 10
 outvar $limit 10
 outbar $max $lmt 20
 echo " $fls"
}

outbar()
{
 use=$1; max=$2; len=$3;
 if [ $max -le 0 ]; then
  bar=20; rst=0; per='~.~~%'
 else
  bar=`echo "scale=0; ($1*$len)/$2" | bc -l`
  per=`echo "scale=2; ($1*100)/$2" | bc -l`'%'
  rst=`expr $len - $bar`
 fi
 echo -ne " ["
 for(( i=0; i < $bar; i++ )); do
  echo -ne '#'; done
 for(( i=0; i < $rst; i++ )); do
  echo -ne ' '; done
 echo -ne "]";
 outvar $per 7
}

outvar()
{
 txt=$1; fln=$2; tln=`echo ${#txt}`
 outspaces `expr $fln - $tln`
 echo -ne "$txt"
}

outtext()
{
 txt=$1; fln=$2; tln=`echo ${#txt}`
 echo -ne "$txt"
 outspaces `expr $fln - $tln`
}

outspaces()
{
 len=$1; for(( i=0 ; i<$len; i++ )); do
  echo -ne ' '; done
}

main
 

Attachments

Last edited by a moderator:
Back
Top