-
-
Save idnovic/d07310d6bf9e127f846cf6a6081b65c3 to your computer and use it in GitHub Desktop.
#!/bin/bash | |
source .bashrc | |
loadavg=$(cat /proc/loadavg | awk '{print $2}' | sed 's/[^0-9]*//g') | |
cpucount=$(sed -n '/ cores/ s/[^0-9]//gp' /proc/cpuinfo | sed '1,1d') | |
cpu=$(($loadavg/$cpucount)) | |
memtotal=$(sed -n '/^MemTotal:/ s/[^0-9]//gp' /proc/meminfo) | |
memavail=$(sed -n '/^MemAvailable:/ s/[^0-9]//gp' /proc/meminfo) | |
mem=$(((($memtotal-$memavail))/($memtotal/100))) | |
io=$(iostat -d --dec=0 -hmsxz -p ALL -g hdd ALL -H | grep hdd | awk '{print $7}') | |
hdd=$(df / | grep dev | awk '{print $5}') | |
#netavg=$(nicstat -nMz | grep -m1 -A1 %Util | sed '1,1d' | awk '{print $9}' | sed 's/[^1-9]*//g') | |
#net=$(awk "BEGIN {printf \"%.0f\",${netavg}}") | |
widget cpu "$cpu%" memorychip "$mem%" externaldrive.badge.timemachine "$io" |
If something does not work take a look at every "print $X". Different versions of the console tools may provide different outputs.
It seems that
cpu=$((100-${idle%.*})) from the shellfish authors tweet does not work. At least not with german locale. Possibly because of swapped delimiters. The calculation is wrong and only uses the digits after the delimiter.
Disk usage is read out by mount point. Should work for most configurations.
IO is somewhat confusing. Basically it was the simplest option to group all active disk drives as "hdd" and read out a "single" output. That way it should also work on most configurations.
Note: Normally we would add % to the widget command line to get a bar instead of text. But for hdd and io we do not need to add % to the widget command because the original output of the readout already includes an "%".
Added network utilization using nicstat.
Fixed CPU calculations based on core count
Fixed network stat utilization
nicstat seems to be a wrong choice.
The provided values do not make sense.
I need to find an other way to get link utilization.
fixed memory calculation.
Net usage does not work currently.
install shellfish integration for the root user.
save shellfishwidget.sh in /root
make it executable
chmod +x shellfishwidget.sh
Install nicstat
apt install nicstat
and run it with crontab every 15 minutes
nano /etc/crontab
add the following line
crontab */15 * * * * root /bin/bash /root/shellfishwidget.sh >/dev/null 2>&1
You may need to deactivate outputs based on the widget size. Simply remove things from line 15.
A widget output is generated with an icon name + variable. Example
cpu "$cpu%"