#!/bin/bash

# wminfo plugin: displays the numbers of threads and processes and disk IOs

# command: wminfo -p conky.sysmon-plus.wmi -u 3 -b#000000 -f#ff0000

#
# CONFIGURATION SECTION BEGINS HERE
#

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

#
# CONFIGURATION SECTION ENDS HERE
#

datafile="$HOME/.wminfo/conky.tmp"
label="SYSMON-PLUS"

if [ -z "$(grep "^${label}: " "${datafile}")" ]
then
cat <<EOF
$0: no "${label}" entries were found in ${datafile} file.
         
         
         
         
EOF
    exit
fi

cpu="100"

`grep "^${label}: " $datafile | sed -E "s/${label}: //;s/\.[0-9]+([BKMGT])/\1/;s/%//;s/^/export /;s/: /=/;s/export ([#_])/export BAR=\1/;s/#/|/g;s/_/ /g"`

CPU="${CPU:-0}"

# The correction of the overestimated value
if [ "$Correction" != "" ]
then
    Correction=${Correction/./}
    CPU=$((100*$CPU/$Correction))
fi

BAR="||||||||||"
length=$((($CPU+5)/10))
BAR=${BAR:0:$length}

CPU="   ${CPU}"
FRQ="   ${FRQ}"
MEM="   ${MEM}"
SWP="   ${SWP}"

THR="   ${THR}"
PRC="   ${PRC}"
IOR="   ${IOR}"
IOW="   ${IOW}"
DIO="   ${DIO}"

CPU=${CPU: -3:4}
FRQ=${FRQ: -4:5}
MEM=${MEM: -3:4}
SWP=${SWP: -3:4}

THR=${THR: -4:5}
PRC=${PRC: -4:5}
IOR=${IOR: -4:5}
IOW=${IOW: -4:5}
DIO=${DIO: -4:5}

BAR="${BAR:-         }"

# echo "CPU: $CPU%"
# echo "$BAR"
# echo "FRQ: $FRQ"
# echo "MEM: $MEM%"
# echo "SWP: $SWP%"

echo "AVG: $AVG"
echo "THR: $THR"
echo "PRC: $PRC"
echo "IOR: $IOR"
echo "IOW: $IOW"
# echo "DIO: $DIO"

echo

