Skip to content

Instantly share code, notes, and snippets.

@tiagoamaro
Last active January 15, 2025 13:51
Show Gist options
  • Select an option

  • Save tiagoamaro/b9ac44a31bc26e138cee407cf91fcd71 to your computer and use it in GitHub Desktop.

Select an option

Save tiagoamaro/b9ac44a31bc26e138cee407cf91fcd71 to your computer and use it in GitHub Desktop.
Linux Apps

Fonts

Network

  • Enhanced Sound applet (sound150@claudiux)
  • GPaste Reloaded ([email protected])
  • Graphical hardware monitor (hwmonitor@sylfurd)
  • Notifications ([email protected])
  • QRedshift (qredshift@quintao)
  • Weather (weather@mockturtl)
#!/bin/bash
# System resources shell script, based on several sources, which I will list as I go.
# CPU usage
# Source:xfce4-genmon script to monitor current cpu usage
# 2020 (ɔ) almaceleste
# cpu usage threshold warning (in %) - yellow
warn=70
# cpu usage threshold alarm (in %) - red
alarm=90
cpu=$(top -bn 2 -d 0.2 | grep '^%Cpu' | tail -n 1 | awk '{printf "%2d", $2+$4+$6}')
color='lightgrey'
if [ $cpu -gt $alarm ]
then
color='red'
elif [ $cpu -gt $warn ]
then
color='yellow'
fi
cpu="${cpu}%"
cpu_output="$cpu%"
# Memory usage.
# Source: xfce4-genmon script to monitor current memory usage
# 2020 (ɔ) almaceleste
# `free` has the following output:
# total used free shared buff/cache available
# Mem: 31Gi 13Gi 3.6Gi 369Mi 14Gi 17Gi
# Swap: 8.0Gi 21Mi 8.0Gi
# We're using the total mem with awk parsing to fetch the first line with 2 fields
used=$(free --giga | grep Mem | awk '{printf "%dG", $3}')
total_memory=$(free --giga --human | grep Mem | awk '{printf "%dG", $2}')
# Network
# Source: https://github.com/rxxb/xfce4-genmon-netmonitor/blob/main/netmon.sh
interface=`ip r | grep '^default' | awk '{print $5}'`
if [ ! -d ~/.cache ]; then
mkdir ~/.cache
fi
if [ ! -z $interface ]; then
rx_curr=`cat /sys/class/net/$interface/statistics/rx_bytes`
tx_curr=`cat /sys/class/net/$interface/statistics/tx_bytes`
if [ ! -f ~/.cache/rx_prev_bytes ]; then
echo $rx_curr > ~/.cache/rx_prev_bytes
echo $tx_curr > ~/.cache/tx_prev_bytes
fi
rx_prev=`cat ~/.cache/rx_prev_bytes`
tx_prev=`cat ~/.cache/tx_prev_bytes`
rx_comp=$((($rx_curr-$rx_prev)))
tx_comp=$((($tx_curr-$tx_prev)))
rx_human=$(numfmt --to=iec $rx_comp)
tx_human=$(numfmt --to=iec $tx_comp)
echo $rx_curr > ~/.cache/rx_prev_bytes
echo $tx_curr > ~/.cache/tx_prev_bytes
else
tx_human="Offline"
rx_human="Offline"
if [ -f ~/.cache/rx_prev_bytes ]; then
rm ~/.cache/rx_prev_bytes
rm ~/.cache/tx_prev_bytes
fi
fi
# Disk (similar to the above, but picking up from /sys/block/dm-0/stat)
device="dm-0"
if [ ! -d ~/.cache ]; then
mkdir ~/.cache
fi
# Get sectors read
ioread_curr=`cat /sys/block/$device/stat | awk '{print $3}'`
iowrite_curr=`cat /sys/block/$device/stat | awk '{print $7}'`
ioread_prev=`cat ~/.cache/ioread_prev_bytes`
iowrite_prev=`cat ~/.cache/iowrite_prev_bytes`
ioread_comp=$((($ioread_curr-$ioread_prev) * 512))
iowrite_comp=$((($iowrite_curr-$iowrite_prev) * 512))
ioread_human=$(numfmt --to=iec $ioread_comp)
iowrite_human=$(numfmt --to=iec $iowrite_comp)
echo $ioread_curr > ~/.cache/ioread_prev_bytes
echo $iowrite_curr > ~/.cache/iowrite_prev_bytes
# Output
printf "C: $cpu_output | M: $used/$total_memory | RX: $rx_human, TX: $tx_human | IO/R: $ioread_human, IO/W: $iowrite_human "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment