#!/bin/bash

# wminfo plugin: displays CPU, memory, and swap usages as well as average load

# command: wminfo -p sysmon.wmi -u 5 -b#000000 -f#ff0000

# Attention: sysmon.wmi plugin uses sysmon script

# the script by Cezary M. Kruk and Peter Trenholme

#
# CONFIGURATION SECTION BEGINS HERE
#

export Correction="1.00"	# use the number with two digits after the point

CPU_Bar="on"

#
# CONFIGURATION SECTION ENDS HERE
#

if [ "`which sysmon 2> /dev/null`" == "" ]
then
    echo "$0: put sysmon script into PATH."
    echo -e "         \n         \n         \n         \n"
    exit
fi

if [ "$CPU_Bar" == "on" ]
then
    lines="2"
else
    lines="1"
fi

sysmon | head -n $lines
free -m | awk '/Mem:/{printf("MEM:%4d%\n",int(100*($3-$6-$7)/$2))};\
    /Swap:/{printf("SWP:%5s\n",($2)?int(100*($3/$2))"%":"None")}'

if [ "$lines" == "2" ]
then
    top -b -n 1 | awk '/^Tasks/{printf("PRC:%5s\n",$4);exit}'
elif [ "$lines" == "1" ]
then
    top -b -n 1 | awk '/^Tasks/{printf("PRC:%5s\n",$4);exit};/^top /{printf("AVG:%5s\n", gensub(/,/,"",1,$13))}'
fi

