Apcupsd Voltage Recorder
Recording utility power voltages from apcupsd.
Contents
Usage
Scheduling
Using schedule module for job scheduling, you can found the scheduling setting at configuration file.
Alternative solution is using Linux built-in Cron
function.
Configuration
Store configuration as JSON format file, named config.json
.
You can editing the clean copy, which looks like this:
{
"schedule_config": 10,
"path_and_filename": "apcupsd_voltage_record.csv",
"row_date": 1,
"row_voltage": 11,
"prefix_date":"DATE :",
"prefix_voltage":"LINEV :"
}
schedule_config
setting the execution period.path_and_filename
setting the voltage recording filename and storage path.row_date
reference to row number of datetime.row_voltage
reference to row number of voltage report.prefix_date
delete the prefix at datetime row.prefix_voltage
delete the prefix at voltage row.
Web monitor address
This function need monitor's web address, can be LAN address.
import voltage_recorder
# Web monitor address
upsfstats = "http://192.168.0.1/upsfstats.cgi?host=127.0.0.1"
# Get result
result = voltage_recorder.apcupsd_upsfstats(upsfstats)
Cron mode
Startup script by Linux built-in Cron
function by crontab
configuration.
- Get voltage data from apcaccess
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
*/10 * * * * pi python /python_script/crontab_apcaccess.py
#
- Get voltage data from apcupsd-cgi program
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
*/15 * * * * pi python /python_script/crontab_upsfstats.py
#
Schedule mode
- Get voltage data from apcaccess
user@localhost:~/python_script python schedule_apcaccess.py
- Get voltage data from apcupsd-cgi program
user@localhost:~/python_script python schedule_upsfstats.py
After startup, it will print this:
Scheduled period is 10 minutes.
Pressing CTRL+C to exit voltage monitor.
If you want to terminate the Program, pressing CTRL+C, it will print this:
^C
Thank you for using the voltage monitor.
GoodBye ...
Dependencies
Python version
- Python 3.6 or above
Python module
- sys
- csv
- time
- json
- schedule
- requests
- subprocess
- BeautifulSoup
UPS monitor program
- apcupsd
- apcupsd-cgi