Coder Social home page Coder Social logo

apcupsd_voltage_recorder's Introduction

Apcupsd Voltage Recorder

python version UA Size

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

apcupsd_voltage_recorder's People

Contributors

suzhou65 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.