[collectd] collectd: apcups.c update
Anthony Gialluca
tonyabg at charter.net
Mon May 22 14:53:16 CEST 2006
Hi all,
I've cleaned up the apcups.c code considerably following the
recommendations of
Florian octo Forster. I have committed back to the apcups branch:
1. (major) Code no longer calls exit() when it encounters an error. It
will send an appropriate error via syslog instead.
2. Adopted the code recommended by Octo (thx) It was considerably cleaner
and easier to understand. Not to mention the plugin size is smaller. A win
all around ;-) I rearranged some, though.
3. Fixed the indentation. I believe I see what is recommended by octo....
Hopefully, it is now similar to the other plugins.
4. On a failure to connect apcups will log the initial failure via syslog. It will
only log another failure after the integer apcConnStatus rolls over. This should prevent
apcups from overloading syslog.
Questions:
1. TODO: Keep the socket open, if possible.
I can open socket in module init, but without a corresponding module
uninit there is no place to gracefully close the socket. The only options
that I see are:
a. open and close the socket to apcupsd every 10 secs. (STEP) in
do_apc_status() as it currently is.
b. Open the socket in apcups_init() and let the program exit() deal with
it. This seems messy.
c. Is there a module uninit() that I'm unaware of ? Is this something reasonable
to pursue ? Or would it mean a major effort to create/enable such a thing ?
2. FIXME: Rename DSes to be more generic and follow established
conventions ?
The current DSes are named for the values returned by apcupsd (see
below). I choose them to
so that they would be easy to associate one with the other. Which is
better ?
An example of using APCMAIN and the output from a Smart-UPS:
%gcc -DAPCMAIN -o apcups src/apcups.c
% ./apcups
net_recv = "APC : 001,052,1232"
net_recv = "DATE : Sun May 21 16:17:08 EDT 2006"
net_recv = "HOSTNAME : tycho"
net_recv = "RELEASE : 3.12.2"
net_recv = "VERSION : 3.12.2 (18 January 2006) redhat"
net_recv = "UPSNAME : UPS_IDEN"
net_recv = "CABLE : APC Cable 940-0024C"
net_recv = "MODEL : SMART-UPS 1000"
net_recv = "UPSMODE : Stand Alone"
net_recv = "STARTTIME: Sat May 20 09:45:49 EDT 2006"
net_recv = "STATUS : ONLINE "
net_recv = "LINEV : 120.9 Volts"
Found property: name = LINEV ; value = 120.900002;
net_recv = "LOADPCT : 27.0 Percent Load Capacity"
Found property: name = LOADPCT ; value = 27.000000;
net_recv = "BCHARGE : 100.0 Percent"
Found property: name = BCHARGE ; value = 100.000000;
net_recv = "TIMELEFT : 60.0 Minutes"
Found property: name = TIMELEFT ; value = 60.000000;
net_recv = "MBATTCHG : 10 Percent"
net_recv = "MINTIMEL : 5 Minutes"
net_recv = "MAXTIME : 0 Seconds"
net_recv = "MAXLINEV : 122.8 Volts"
net_recv = "MINLINEV : 120.2 Volts"
net_recv = "OUTPUTV : 120.9 Volts"
Found property: name = OUTPUTV ; value = 120.900002;
net_recv = "SENSE : High"
net_recv = "DWAKE : 000 Seconds"
net_recv = "DSHUTD : 020 Seconds"
net_recv = "DLOWBATT : 02 Minutes"
net_recv = "LOTRANS : 103.0 Volts"
net_recv = "HITRANS : 132.0 Volts"
net_recv = "RETPCT : 000.0 Percent"
net_recv = "ITEMP : 27.4 C Internal"
Found property: name = ITEMP ; value = 27.400000;
net_recv = "ALARMDEL : 5 seconds"
net_recv = "BATTV : 27.5 Volts"
Found property: name = BATTV ; value = 27.500000;
net_recv = "LINEFREQ : 60.0 Hz"
Found property: name = LINEFREQ ; value = 60.000000;
net_recv = "LASTXFER : Automatic or explicit self test"
net_recv = "NUMXFERS : 0"
net_recv = "TONBATT : 0 seconds"
net_recv = "CUMONBATT: 0 seconds"
net_recv = "XOFFBATT : N/A"
net_recv = "SELFTEST : NO"
net_recv = "STESTI : 336"
net_recv = "STATFLAG : 0x07000008 Status Flag"
net_recv = "DIPSW : 0x00 Dip Switch"
net_recv = "REG1 : 0x00 Register 1"
net_recv = "REG2 : 0x00 Register 2"
net_recv = "REG3 : 0x00 Register 3"
net_recv = "MANDATE : 03/14/96"
net_recv = "SERIALNO : S96058699119"
net_recv = "BATTDATE : 10/05/06"
net_recv = "NOMOUTV : 115"
net_recv = "NOMBATTV : 24.0"
net_recv = "EXTBATTS : 0"
net_recv = "FIRMWARE : 60.8.D"
net_recv = "APCMODEL : IWD"
net_recv = "END APC : Sun May 21 16:17:22 EDT 2006"
In conclusion, it should be far more polished now. Please examine it and
comment
freely. As before, any errors are mine.
Thanks in advance,
Tony
--
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Anthony B Gialluca tonyabg [at] charter [dot] net
"Welcome to my house! Enter freely. Go safely, and leave something of
the happiness you bring!"
Dracula's greeting to Jonathan Harker: Bram Stoker, Dracula
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3245 bytes
Desc: S/MIME Cryptographic Signature
Url : http://mailman.verplant.org/pipermail/collectd/attachments/20060522/5490ca07/smime.bin
More information about the collectd
mailing list