Eww update

This commit is contained in:
soraefir
2026-06-12 23:09:31 +02:00
parent 6140123cbc
commit 535c8a3154
15 changed files with 606 additions and 294 deletions

View File

@@ -0,0 +1,49 @@
#!/usr/bin/env bash
COLS=4
declare -A prev_idle prev_total
emit_grid() {
local rows=() row_items=()
while IFS= read -r line; do
[[ $line =~ ^cpu([0-9]+) ]] || continue
local core="${BASH_REMATCH[1]}"
read -ra f <<< "$line"
local idle=$(( f[4] + f[5] ))
local total=0
for x in "${f[@]:1}"; do (( total += x )); done
local usage="0.0"
if [[ -n "${prev_total[$core]+x}" ]]; then
local dt=$(( total - prev_total[$core] ))
local di=$(( idle - prev_idle[$core] ))
(( dt > 0 )) && usage=$(awk "BEGIN{printf \"%.1f\", 100*(1-$di/$dt)}")
fi
prev_idle[$core]=$idle
prev_total[$core]=$total
local freq=0
local fpath="/sys/devices/system/cpu/cpu${core}/cpufreq/scaling_cur_freq"
[[ -r $fpath ]] && freq=$(( $(< "$fpath") / 1000 ))
row_items+=("{\"core\":$core,\"usage\":$usage,\"freq\":$freq}")
if (( ${#row_items[@]} == COLS )); then
local row; printf -v row '%s,' "${row_items[@]}"; row="${row%,}"
rows+=("[$row]")
row_items=()
fi
done < /proc/stat
if (( ${#row_items[@]} > 0 )); then
local row; printf -v row '%s,' "${row_items[@]}"; row="${row%,}"
rows+=("[$row]")
fi
local out; printf -v out '%s,' "${rows[@]}"; out="${out%,}"
echo "[$out]"
}
while true; do
emit_grid
sleep 2
done

View File

@@ -0,0 +1,3 @@
#!/usr/bin/env bash
dir=$(grep -rl k10temp /sys/class/hwmon/*/name 2>/dev/null | head -1 | xargs dirname)
awk '{printf "%.0f\n", $1/1000}' "$dir/temp1_input"

View File

@@ -1,3 +1,22 @@
#!/usr/bin/env zsh
amdgpu_top -J -s 5000 | sed 's/ //g'
#!/usr/bin/env bash
amdgpu_top -J -s 5000 | jq -c --unbuffered '.devices[0] | {
gfx_pct: (.gpu_activity.GFX.value // 0),
mem_pct: (.gpu_activity.Memory.value // 0),
media_pct: (.gpu_activity.MediaEngine.value // 0),
sclk: (.Sensors.GFX_SCLK.value // 0),
mclk: (.Sensors.GFX_MCLK.value // 0),
sclk_pct: (if (.Info["GPU Clock"].max != .Info["GPU Clock"].min) then
100 * ((.Sensors.GFX_SCLK.value // 0) - .Info["GPU Clock"].min) / (.Info["GPU Clock"].max - .Info["GPU Clock"].min)
else 0 end),
mclk_pct: (if (.Info["Memory Clock"].max != .Info["Memory Clock"].min) then
100 * ((.Sensors.GFX_MCLK.value // 0) - .Info["Memory Clock"].min) / (.Info["Memory Clock"].max - .Info["Memory Clock"].min)
else 0 end),
vclk: (.gpu_metrics.average_vclk_frequency // 0),
vclk_pct: (if (.Info["GPU Clock"].max > 0) then
100 * (.gpu_metrics.average_vclk_frequency // 0) / .Info["GPU Clock"].max
else 0 end),
temp: (.Sensors["Edge Temperature"].value // 0),
power: (.Sensors["Average Power"].value // 0),
vram_used: (.VRAM["Total VRAM Usage"].value // 0),
vram_total: (.VRAM["Total VRAM"].value // 1)
}'

View File

@@ -8,5 +8,6 @@ human() {
free --si -s 3 | rg --line-buffered Mem | while read -r line; do
used=$(echo "$line" | awk '{print $3}')
echo '{"human": { "total": "'$(human "$total")'", "used": "'$(human "$used")'"}, "total": "'$total'" , "used": "'$used'"}'
done
cached=$(echo "$line" | awk '{print $6}')
echo '{"human": {"total": "'$(human "$total")'", "used": "'$(human "$used")'", "cached": "'$(human "$cached")'"}, "total": "'$total'", "used": "'$used'", "cached": "'$cached'"}'
done

View File

@@ -0,0 +1,7 @@
#!/usr/bin/env bash
free --si | awk '/Swap/ {
used=$3; total=$2
u = sprintf("%.1fG", used/1000000)
t = sprintf("%.1fG", total/1000000)
printf "{\"used\":%d,\"total\":%d,\"human\":{\"used\":\"%s\",\"total\":\"%s\"}}\n", used, total, u, t
}'