The recent frequency of electric breakdowns, coupled with sitting in front of a dimmed laptop screen hoping against hope that the power would come back on before my battery died, produced an interesting result. Fortunately, my brain doesn’t need electricity to light bulbs in the air above my head.
With the blessings of KESC and Worldcall, I went through some web pages about ACPI, the linux power management framework. I found this website quite helpful. Really interesting stuff. (No seriously).
In particular, reading sections 6.3 and 6.4, I struck on a wonderful idea. What if I could log when KESC shuts down my electricity and when it brings it back up. Now what if that data were to be made available on the web!
No, its not that awesome. Still, it would be interesting to see the trends (or lack thereof), appearing through the statistics.
For those of you who don’t want to read my ravings about how I did it, here’s the link to the log. Let me know if you have any problems viewing it. Keep in mind, this is running off my laptop, with my not-so-reliable connection, so you might see some problems.
Now to the meat. There’s this daemon by the name of acpid which should be running on your linux system already. It’s included in most distributions, so if its not running you can probably install it very easily. This daemon has certain events that cause it to do certain things. For example, if you’ve got a laptop with some extra keys (brightness, hibernate etc.), its more than likely they’re functionality is controlled through the ACPI daemon. What we need to do is find the events corresponding to AC Power and Battery status. In my case these were ac_adapter and battery respectively. (If you haven’t read the sections in the article I mentioned earlier, I strongly recommend you do so before reading further. The path names could vary depending on your system, as they did in my case.)
What we need to know is that there needs to be a file in /etc/acpi/events/ that indicates which script to run when a particular even occurs. In addition, of course, there needs to be a script file for the acpi daemon to actually run when the event occurs. You can download my script files here.
You will probably have to change the paths in these scripts. The files powerlog.sh and battlog.sh should go into /etc/acpi, and the files ac_adapter and battery should go into /etc/acpi/events.
Once you’ve edited and copied to the proper directories, you need to restart the ACPI daemon. This can be done ( on a Debian system),
# /etc/init.d/acpid restart
And your scripts should start logging. Have fun!
For my part, I’ll keep my script running, and see what turns up.



