Begin adding WSL2 support for system-info

This commit is contained in:
Kenneth Benzie 2021-11-28 11:40:23 +00:00
parent 1389817cb4
commit e912a5902b
3 changed files with 45 additions and 0 deletions

39
system-info/system-info-WSL.sh Executable file
View File

@ -0,0 +1,39 @@
#!/usr/bin/env bash
cache_dir=~/.cache/tmux
cache_file=$cache_dir/system-info
while true; do
# Assumes OpenHardwareMonitor is has the Remote Web Server enabled on port
# 8085 of the Windows host. In WSL2 the Windows host IP is accessible using
# $(homename).local, use this to grab sensor data but this depends on WSL2
# being allowed to make connections to the Windows host:
#
# ```powershell
# New-NetFirewallRule -DisplayName "WSL" -Direction Inbound -InterfaceAlias "vEthernet (WSL)" -Action Allow
# ```
#
# However this setting must be applied each boot, there's probably a sticky
# setting but not sure what it is.
cpu_json=`curl --silent $(hostname).local:8085/data.json | jq \
".Children[] | select(.Text | test(\"$(hostname | awk '{print toupper($0)}')\"))"\
'.Children[] | select(.ImageURL | test("images_icon/cpu.png"))'`
# cpu_load=`echo $cpu_json | jq --raw-output \
# '.Children[] | select(.Text | test("Load"))'\
# '.Children[] | select(.Text | test("CPU Core #[0-9]+")).Value'`
# echo cpu load: $cpu_load
cpu_load=`mpstat -P ALL -n 1 -u 1 -o JSON | \
jq '.sysstat.hosts[0].statistics[0]["cpu-load"][1:]|.[].idle' | \
awk '$idle ~ /[-.0-9]*/ { printf "%s", substr("█▇▆▅▄▃▂▁ ", int($idle / 11), 1) }'`
cpu_temp=`echo $cpu_json | jq --raw-output \
'.Children[] | select(.Text | test("Temperatures"))'\
'.Children[] | select(.Text | test("CPU Package")).Value' | \
awk '{gsub(/ /,""); print}'`
echo "$cpu_temp $cpu_load" > $cache_file
# echo -e "HTTP/1.1 200 OK\n\n$cpu_temp $cpu_load" | nc -l -k -p 8080 -q 1;
sleep 1
done

View File

@ -64,3 +64,7 @@
# TODO: - name: Enable tmux system-info service
# command: system-info/install.sh
# TODO: WSL2 system-info
# when: '"WSL" in ansible_kernel'
# figure out best way to run daemon...

View File

@ -127,6 +127,8 @@ setw -g status-style fg=colour240,bg=colour233
# Right status style shows system info, date, and time.
setw -g status-right "#[fg=colour240]#(cat ~/.cache/tmux/system-info)#[fg=white] %a %d-%m-%y %H:%M "
setw -g status-right-style fg=white,bg=colour233
if -b '[[ "`uname`" != "Darwin" ]]' \
run 'tmux setw -g status-right-length $((`nproc --all` + 32))'
# Active window status style
setw -g window-status-current-format " #{window_index}: #{window_name}"