dotfiles/.i3blocks/cpu_usage

23 lines
517 B
Text
Raw Normal View History

2019-04-19 22:18:25 +02:00
#!/bin/bash
# Récupération du taux d'IDLE
idle=$(env LC_ALL=C mpstat 1 1 -o JSON | jq '.sysstat.hosts[0].statistics[0]."cpu-load"[0].idle' | cut -d. -f1)
# Calcul du taux d'utilisation
used=$((100 - $idle))
# Choix de la couleur
if [[ $used -ge 90 ]]
then color="#f2777a"
elif [[ $used -ge 70 ]]
then color="#f99157"
elif [[ $used -ge 50 ]]
then color="#ffcc66"
elif [[ $used -ge 10 ]]
then color="#99cc99"
else color="#66cccc"
fi
# Affichage
2020-12-31 11:14:20 +01:00
printf "uct<span foreground=\"%s\">%3d%%</span>\n" "$color" "$used"