Wednesday, September 28, 2011

Graph of system usage

Sometimes managers need info from the servers and they want to see it in a fancy way... like when you want to know the amount of time users spend on a server but you need a graphic... and I know you can just take the values paste them into a spreadsheet and create a graph... but I like more the automated and lovely look of the console... so Here is one solution.

Graphic_Of_System_Usage
{
    set -A resources user1 user2 user3 user4 user5 user6 user7 user8
    for Q in $(echo ${resources[*]})
    do
       rm /tmp/resource.usage
       last | grep $(date +%h) | grep $Q | awk '{print $9}' | grep '(' | sed 's/(//g' | sed 's/)//g' | sed 's/:/ /g' > /tmp/resource.usage
       USAGE=0
       CHART=0
       J=0
       while read MIN SEC
       do
           (( TMIN = MIN * 60 ))
           (( TSEC = TMIN + SEC ))
           (( USAGE = $USAGE + $TSEC ))
       done < /tmp/resource.usage
       (( CHART = $USAGE / 100 ))
       echo "$Q: \c"
       while [ $J -lt $CHART ]
       do
           echo "|\c"
           (( J = $J +1 ))
       done   
       echo "\n"
    done
}

you will see something like this.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.