ACPI Power/Battery Status
How about including ACPI power status monitoring. Battery status for instance. And initiate shutdown at x%?
Comments (7)
-
-
@Henning Bopp Hi wrote a small utility to check the main battery status under linux and windows.
It exits with code 255 if there isn’t a battery or it is charging.
Otherwise it exits with the value of the percentage of charge, 0 to 100.
How can I submit the source code to @Tildeslash @Tilde development so they can include it with monit?
-
repo owner Interesting, though Monit is usually run on servers without a battery so the use case is maybe limited and best served via a script and check program. We are reluctant to include code unless it works on all supported platforms.
-
@Tildeslash The utility supports freebsd, linux, windows. I agree it is better as an external utility. If you surely adopt this utility, I will look at macos development.
-
repo owner No need. We already have the code for macOS battery check which we use in the Monit Widget. It is not trivial if you haven’t done any macOS sysdev before. Anyway, as mentioned above, let's try to use check program and a script when possible.
-
repo owner - changed status to closed
Use a script and check program when possible. This is more general and flexible
-
We already have the code for macOS battery check which we use in the Monit Widget https://mmonit.com/widget/
Hi Can you share the source code of the battery check?
- Log in to comment
The following is true for my Arch Linux, pathes also match my debian. But since I only have access to a Arch based battery-powered device, it might neither work on every distribution nor on Mac.
You can use the program type with path
/usr/bin/bash -c 'exit $(cat /sys/class/power_supply/BAT0/capacity)'
. So the exit status is now your battery percentage.This schedules a shutdown in 1 minute (+1) and will halt your system (-h). It will also post a message on any tty available.
Since this just uses the
shutdown
command, you can avoid the shutdown by callingsudo shutdown -c
on a bash.Keep some more things in mind:
PS: This technique might be used with any binary that returns a number only, since exit only allows numerical exit codes.