What do you use as a system monitor - Servers Administration, Networking, & Virtualization

Users browsing this thread: 1 Guest(s)
venam
Administrators
On that note, I also forgot I have a script for battery status that pops up at certain intervals.
It's running as a systemd user timer (~/.config/systemd/user/timers.target.wants).
The timer unit
Code:
[Unit]
Description=Timer to run battery-notify

[Timer]
OnActiveSec=1min
OnUnitActiveSec=1min

[Install]
WantedBy=timers.target
and service unit:
Code:
[Unit]
Description=battery-notify

[Service]
ExecStart=%h/docu/bin/check-batt

[Install]
WantedBy=default.target

And the actual script that gets called check-batt, which is very similar to what neeasade is doing but with threshold values:
Code:
#!/usr/bin/env bash

BAT_NUM='1'
STATUS_FILE=/tmp/check-bat.tmp
BATTPERC=$(cat /sys/class/power_supply/BAT${BAT_NUM}/capacity)
BATTSTATUS=$(cat /sys/class/power_supply/BAT${BAT_NUM}/status)
LAST_STATUS=''
LAST_NOTIF_LEVEL=0
NOTIF_LEVEL=0

if [ -e $STATUS_FILE ] ; then
    . $STATUS_FILE
fi

save_status() {
    LAST_STATUS=$BATTSTATUS
    echo "LAST_STATUS=${BATTSTATUS}" > $STATUS_FILE
    echo "LAST_NOTIF_LEVEL=${NOTIF_LEVEL}" >> $STATUS_FILE
}

notify() {
    level=$1
    msg=$2
    DISPLAY=:0 /usr/bin/notify-send -t 3500 -u "$level" "POWER" "$msg"
}

# Battery status changed
if [[ "$BATTSTATUS" != "$LAST_STATUS" ]] ; then
    notify "normal" "battery is now $BATTSTATUS, Capacity: $BATTPERC"
    NOTIF_LEVEL=$LAST_NOTIF_LEVEL
    save_status
    exit
fi

if [ "$BATTSTATUS" = Discharging ] && [ "$BATTPERC" -le 10 ]; then
    NOTIF_LEVEL=10
    notify "critical" "battery is less than 10% - Connect charger, going to sleep in 10s"
    sleep 10
    BATTSTATUS=$(cat /sys/class/power_supply/BAT${BAT_NUM}/status)
    if [ "$BATTSTATUS" = Discharging ]; then
        notify "critical" "going to suspend now"
        sleep 3
        logger "Critical battery threshold, suspending"
        save_status
        systemctl suspend
        exit
    else
        notify "normal" "battery is now charging, cancelling suspend"
        save_status
        exit
    fi
fi

if [[ $BATTPERC -le 20 ]] ; then
    NOTIF_LEVEL=20
    notify "critical" "battery $BATTSTATUS is less than 20%"
    save_status
elif [[ $BATTPERC -le 30 ]] ; then
    NOTIF_LEVEL=30
    if [ "$NOTIF_LEVEL" != "$LAST_NOTIF_LEVEL" ]; then
        notify "normal" "battery $BATTSTATUS is at 30%"
        save_status
    fi
elif [[ $BATTPERC -le 50 ]] ; then
    NOTIF_LEVEL=50
    if [ "$NOTIF_LEVEL" != "$LAST_NOTIF_LEVEL" ] ; then
        notify "low" "battery $BATTSTATUS is at 50%"
        save_status
    fi
elif [[ $BATTPERC -le 60 ]] ; then
    NOTIF_LEVEL=60
    if [ "$NOTIF_LEVEL" != "$LAST_NOTIF_LEVEL" ] ; then
        notify "normal" "battery $BATTSTATUS is at 60%"
        save_status
    fi
fi


Messages In This Thread
What do you use as a system monitor - by venam - 10-02-2022, 01:22 PM
RE: What do you use as a system monitor - by movq - 12-02-2022, 04:51 AM
RE: What do you use as a system monitor - by venam - 13-02-2022, 05:49 AM
RE: What do you use as a system monitor - by pfr - 14-02-2022, 10:31 PM
RE: What do you use as a system monitor - by VMS - 15-02-2022, 01:14 PM
RE: What do you use as a system monitor - by jkl - 21-02-2022, 11:31 AM
RE: What do you use as a system monitor - by prx* - 24-02-2022, 06:02 PM
RE: What do you use as a system monitor - by gaak - 31-10-2022, 04:21 AM