[Nut-upsdev] Re: Bug#343530: nut: logging to rrd database

Alexander V. Inyukhin shurick at sectorb.msk.ru
Sat Dec 17 01:32:52 UTC 2005


On Fri, Dec 16, 2005 at 09:22:49AM +0100, Arnaud Quette wrote:
> 2005/12/15, Alexander V. Inyukhin <shurick at sectorb.msk.ru>:
> 
> > I think it is a good idea to log ups variables to rrd
> > database instead of log file. So, I create standalone
> > rrd logger dervied from upslog nut client.
> > Of course, this could be easily implemented using
> > upsc or upslog clients and a cron script
> > but stanalone application is better for some reasons.
> >
> > Does anybody else need this functionality?
> > Should such a client be included in the nut
> > (with additional librrd dependency) or nut-rrd
> > package or distributed separately?
> 
> 
> interesting point: I'm thinking of some logging improvements, such as:
> - making upslog a real daemon, able to log data from several UPSs,
> - making log asynchronous and smart (ie log only things that have changed),
> - switching by default to a NUT specific logfile (ie upsd.log), instead of
> the syslog default,
> - adding the ability to log to other system, such as RRD...
> 
> So, I'm definitly interested in your work.

Source files of upsrrd daemon and sample init.d script
are attached. Differences from upslog are minimal:
data is recorded by rrd_update using fixed log format,
log format can't be changed from command line,
so option -f and most parts of parser are removed,
invalid values are printed as 'U', and there is
no need for log rotation.
Errors while updating database will be written to syslog.

I intentionally left the rest of parser for
possible modifications of list variables in the future.

To complile daemon sources should be placed into the clients
subdirectory of nut package and appropriate Makefile rules
should be created (based on upslog rules).
Obviously, upsrrd should be linked with -lrrd and requres
librrd2-dev for building and librrd2 for execution.

Sample init.d script has hardcoded daemon command line,
which should be placed into config file.

Database could be created with following command
(I also use rrdcollect and place ups logs there):

rrdtool create /var/lib/rrdcollect/ups.rrd -s 30 \
  DS:bat_charge:GAUGE:75:0:100 DS:line_voltage:GAUGE:75:0:U \
  DS:ups_load:GAUGE:75:0:100 DS:ups_temp:GAUGE:75:U:U \
  DS:line_freq:GAUGE:75:0:U DS:bat_voltage:GAUGE:75:0:U \
  DS:bat_runtime:GAUGE:75:0:U RRA:AVERAGE:0.5:10:210000

I think this daemon with some reasonable defaults
might be appropriate for most users.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: upsrrd.c
Type: text/x-csrc
Size: 8540 bytes
Desc: not available
Url : http://lists.alioth.debian.org/pipermail/nut-upsdev/attachments/20051217/100c4adb/upsrrd.c
-------------- next part --------------
A non-text attachment was scrubbed...
Name: upsrrd.h
Type: text/x-chdr
Size: 359 bytes
Desc: not available
Url : http://lists.alioth.debian.org/pipermail/nut-upsdev/attachments/20051217/100c4adb/upsrrd.h
-------------- next part --------------
#! /bin/sh
#
# skeleton	example file to build /etc/init.d/ scripts.
#		This file should be used to construct scripts for /etc/init.d.
#
#		Written by Miquel van Smoorenburg <miquels at cistron.nl>.
#		Modified for Debian GNU/Linux
#		by Ian Murdock <imurdock at gnu.ai.mit.edu>.
#
# Version:	@(#)skeleton  1.8  03-Mar-1998  miquels at cistron.nl
#
# This file was automatically customized by dh-make on Tue,  3 Sep 2002 14:53:55 +0200

PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/sbin/upsrrd
NAME=upsrrd
DESC=upsrrd

if [ -f /etc/default/upsrrd ]; then
  . /etc/default/upsrrd
fi

test -f $DAEMON || exit 0

set -e

case "$1" in
  start)
	echo -n "Starting $DESC: $NAME"
	start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
		--exec $DAEMON -- -s ups at localhost -l /var/lib/rrdcollect/ups.rrd -u nobody -i 60
	echo "."
	;;
  stop)
	echo -n "Stopping $DESC: $NAME"
	start-stop-daemon --oknodo --stop --quiet --pidfile /var/run/$NAME.pid \
		--exec $DAEMON
	echo "."
	;;
  restart|force-reload)
	#
	#	If the "reload" option is implemented, move the "force-reload"
	#	option to the "reload" entry above. If not, "force-reload" is
	#	just the same as "restart".
	#
	echo -n "Restarting $DESC: $NAME"
	start-stop-daemon --stop --quiet --pidfile --make-pidfile \
		/var/run/$NAME.pid --exec $DAEMON
	sleep 1
	start-stop-daemon --start --quiet --pidfile \
		/var/run/$NAME.pid --exec $DAEMON
	echo "."
	;;
  *)
	N=/etc/init.d/$NAME
	# echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
	echo "Usage: $N {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0


More information about the Nut-upsdev mailing list