How to monitor/log power events with nut

For another router running another firmware with apcupsd, I got log events such as:

2022-07-09 09:46:28 -0400  Power failure.
2022-07-09 09:46:29 -0400  Power is back. UPS running on mains.
2022-07-12 05:52:20 -0400  Power failure.
2022-07-12 05:52:26 -0400  Running on UPS batteries.

For my current 22.03.3 router with an APC usbhid-ups directly connected, I had stall issues with apcupsd, so I'm running nut instead. Since nut is modular, I'm not sure whether I would require nut's upsmon or upslog for logging the events to the standard logd (I think upsmon it would make more sense, 'though).

For upsmon or upslog I notice the configuration requires to define a poll interval, but I don't know whether the power events I want to record are pushed by the UPS, or has to be pulled from nut. And I'm not sure if polling the UPS every second would be the proper way to do this.

I've tried the following nut_monitor config:

config upsmon 'upsmon'
	option pollfreq 5
	list defaultnotify SYSLOG

config master
	option upsname BackUPS
	option hostname localhost
	option username upsuser
	option password [upspassword]

And it connects to the UPS:

Wed Apr 12 20:58:00 2023 daemon.err upsmon[17808]:    0.000000  Using power down flag file /var/run/killpower
Wed Apr 12 20:58:00 2023 daemon.err upsmon[17808]:    0.010907  UPS: BackUPS@localhost (master) (power value 1)
Wed Apr 12 20:58:00 2023 daemon.err upsmon[17808]:    0.012702  debug level is '1'
Wed Apr 12 20:58:00 2023 daemon.err upsmon[17808]:    0.031183  Trying to connect to UPS [BackUPS@localhost]
Wed Apr 12 20:58:00 2023 daemon.info upsd[2521]: User upsuser@127.0.0.1 logged into UPS [BackUPS]
Wed Apr 12 20:58:00 2023 daemon.err upsmon[17808]:    0.043286  Logged into UPS BackUPS@localhost

But I don't know if because the power glitches here often last just a couple of seconds, I haven't seen any of the wanted logs. What I'm missing here?

On another thread, I read another user acheived something like this, but using EXEC script (for alerting slaves) instead of SYSLOG. So would I have to do something similar, or is just I'm missing some configurations?

One thing about apcupsd is that it is pretty dead in the water. If I remember right, last upgrade it had on the webpage was of 2016, 7years ago…

I had some issues with it also with my last ups.

The last APC UPS I bought, I bought with a add-on network card and then it runs as a little webbserver by it own and it can send its logs to a logserver.

So if you ask me, the world and APC has run away from apcupsd.

I won't discuss that, except that apcupsd works fine over FreshTomato and over a fork of OpenWrt 18.06, but not on the official OpenWrt 22.03.3. And for the router I want to use this, I could only downgrade to 22.03.0, so I rather don't.

That's why I've messing with nut, but if apcupsd is orphan, nut is not straight forward. i.e. I've figured out several parts, found some issues that has been fixed with the help of this community for future releases, and now I'm scratching my head at the events part.

Well, the thing is that this is OpenWrt forum and not apcupsd forum so what are we supposed to discuss?

But there is problems with apcupsd on raspberry also.

But these kind of packages sit right in between a hardware UPS and a computer running evolving linux kernel. If that link stops evolve one day then it is pretty much a guarantee fact that something will break from one or the other side or both sides as the years move along.

Of course it works with 18.06, they are pretty much the same age. But 18.06 is also a dead fish in the water that no one cares about anymore.

But the easiest way to fix this problem is to have a log server for the ups that is running older linux kernel that works with older packages.

The router is pretty much a router.

Of course there are many ways to do this, but because my routers are the ones running 24/7, I prefer to use it. For my environment I have several choices, either to downgrade router and firmware in order to use apcupsd with OpenWrt, or find another router that allows me to try all the intermediate releases in order to find when it broke, or forget apcupsd and use "Network UPS Tools" --which is what I'm currently aiming at--, or forget OpenWrt and its features, and resign to use a less powerful kernel/firmware.

So please let's focus this thread on nut, as I already said, for apcupsd I already opened another thread, related on what can we do at OpenWrt level, letting aside upstream discussions out of our control.

https://networkupstools.org/support.html
At least find the help for your problem at the actual source that can do something about the problem for your package.

Nut works well with serial but the usbhid drivers lose connection after 5 mins and won't reestablish connection.

So far I've tried nut with two routers and two APC usbhid UPSs, one router with a old OpenWrt fork for a couple of hours, and the other with official 22.03.3 for two weeks. I have found several issues (that already has been improved and shared), but I haven't lost connection with any UPS.

What I haven't found yet is the way to log the surges and brownouts, as I used to do easily with apcupsd:

root@oldrouter:~# cat /var/log/apcupsd.events
2022-07-29 16:19:59 -0400  apcupsd 3.14.14 (31 May 2016) debian startup succeeded
2022-08-04 17:48:51 -0400  Power failure.
2022-08-04 17:48:53 -0400  Power is back. UPS running on mains.
2022-08-04 18:19:55 -0400  Power failure.
2022-08-04 18:19:57 -0400  Power is back. UPS running on mains.
2022-08-13 15:27:39 -0400  Power failure.
2022-08-13 15:27:43 -0400  Power is back. UPS running on mains.
2022-08-15 22:11:40 -0400  Power failure.
2022-08-15 22:11:42 -0400  Power is back. UPS running on mains.
2022-08-20 08:37:45 -0400  Power failure.
2022-08-20 08:37:47 -0400  Power is back. UPS running on mains.
2022-09-02 07:18:37 -0400  UPS Self Test switch to battery.
2022-09-02 07:18:45 -0400  UPS Self Test completed: Not supported
2022-09-03 16:15:07 -0400  Power failure.
2022-09-03 16:15:08 -0400  Power is back. UPS running on mains
2022-09-06 14:34:23 -0400  Power failure.
2022-09-06 14:34:25 -0400  Power is back. UPS running on mains
2022-09-17 14:40:42 -0400  Power failure.
2022-09-17 14:40:44 -0400  Power is back. UPS running on mains
2022-09-21 03:57:26 -0400  Power failure.
2022-09-21 03:57:27 -0400  Power is back. UPS running on mains
2022-09-26 04:33:28 -0400  Power failure.
2022-09-26 04:33:30 -0400  Power is back. UPS running on mains
2022-09-26 05:07:15 -0400  Power failure.
2022-09-26 05:07:17 -0400  Power is back. UPS running on mains
2022-09-27 15:42:46 -0400  Power failure.
2022-09-27 15:42:48 -0400  Power is back. UPS running on mains
2022-09-30 18:46:15 -0400  Power failure.
2022-09-30 18:46:16 -0400  Power is back. UPS running on mains
2022-10-06 11:34:16 -0400  Power failure.
2022-10-06 11:34:18 -0400  Power is back. UPS running on mains
2022-10-06 11:49:38 -0400  Power failure.
2022-10-06 11:49:44 -0400  Running on UPS batteries.
2022-10-06 12:12:32 -0400  Reached remaining time percentage limit on batteries.
2022-10-06 12:12:32 -0400  Initiating system shutdown!
2022-10-06 12:12:32 -0400  Unable to create /usr/local/apcupsd/powerfail: ERR=Read-only file system
2022-10-06 12:12:32 -0400  User logins prohibited

I want to do the same with nut, so if somebody can help me with how to do the configuration, I would appreciate it.

Hi Feliciano, I use nut and it logs power events:

Sun Apr 16 17:57:04 2023 daemon.err upsmon[6010]: 1068352.597730	Your UPS is on battery.
Sun Apr 16 17:57:14 2023 daemon.err upsmon[6010]: 1068362.617739	Your UPS is back on line power.

I use luci-app-nut to configure it, on its Monitor tab you have to select "Write to syslog" for the events you want logged, you can also edit the messages to be logged. I use the default poll interval.

Below are the nut packages I install:

nut-common nut-server nut-upsmon nut-upsmon-sendmail-notify nut-upsc nut-upscmd nut-upslog nut-upsrw nut-driver-usbhid-ups

Let me know if you need more info.

Silly me, I haven't noticed the new nut tab when I recenlty installed logmon. Nevertheless, I think the basics are already there:


So do I need to add/customize the events I want to log, or it's supposed to be using the defaults at the moment?

On the other hand, most of the events last 1 second or 2, so if I poll every 5 seconds, probably I will miss most of them. For apcupsd I was thinking the events were pushed from the UPS instead of being polled from the package. So for nut to poll is the way it works?

Not all messages of interest are logged by default, so yes have a look at the Network UPS Tools (Monitor) on luci and add/select more if you want them. Editing the actual messages text is optional and down to personal preference.

The poll frequency is just nut polling the UPS to make sure it's alive, while the power events are sent from the UPS to nut as they happen regardless of the polling frequency.

Below from the usbhid-ups man page:

pollfreq=num
    Set polling frequency, in seconds, to reduce the USB data flow. Between two polling requests, the driver will wait for interrupts (aka UPS notifications), which are data changes returned by the UPS by itself. This mechanism allow to avoid or reduce staleness message, due to the UPS being temporarily overloaded with too much polling requests. The default value is 30 (in seconds).
1 Like

Today I got a "power is back" event, but it didn't log the power failure event (that's odd). Maybe it's something related with the log levels, I'm relaxing the log level filtering to "Error", and keep looking.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.