Code Monkey home page Code Monkey logo

apc-ups-exporter's Introduction

APC UPS Exporter

CI CodeQL GitHub tag (with filter) GitHub repository size GitHub release downloads GitHub commit activity

This is a Prometheus exporter for the status data reported by APC's Uninterruptible Power Supplies.

The status data is fetched from apcupsd's Network Information Server (NIS), so ensure it is enabled in your apcupsd.conf configuration file.

I test this against my APC Back-UPS 850VA (BE850G2-UK).

๐Ÿ“ฅ Usage

Download the latest release for your platform. There are builds available for Linux and Windows, on 32-bit and 64-bit architectures of x86 and ARM. There are extra Linux builds to accommodate glibc and musl libraries.

The utility does not expect any command-line arguments. There are sensible defaults in place, so it should run without any configuration. However, functionality can be changed using the optional command-line flags below.

  • --nis-address <string>: The Network Information Server's IPv4 address. Defaults to 127.0.0.1.
  • --nis-port <number>: The Network Information Server's TCP port number. Defaults to 3551.
  • --metrics-address <string>: The listening IPv4 address for the Prometheus HTTP metrics server. Defaults to 127.0.0.1.
  • --metrics-port <number>: The listening TCP port number for the Promtheus HTTP metrics server. Defaults to 5000.
  • --metrics-path <string>: The HTTP path to the metrics page. Defaults to /metrics.
  • --metrics-interval <string>: The number of seconds to wait between collecting metrics. Defaults to 15.

These flags can be prefixed with either a single (-) or double (--) hyphen.

Use the --help (-h) flag for more information.

๐Ÿณ Docker

Alternatively, there is a Docker image available for Linux.

The image is based on Ubuntu (ghcr.io/viral32111/apc-ups-exporter:latest-ubuntu) weighing in at roughly 130 MiB. However, there is a variant based on Alpine Linux (ghcr.io/viral32111/apc-ups-exporter:latest-alpine) which is much lighter at roughly 20 MiB.

Run the command below to download the image and create a container. Replace the :latest tag with your desired variant (e.g., :1.1.3-ubuntu, :main-alpine, etc.).

docker container run \
	--name apc-ups-exporter \
	--network host \
	--detach \
	ghcr.io/viral32111/apc-ups-exporter:1

The host's networking stack is often required to connect to the daemon's Network Information Server.

๐Ÿ–ผ๏ธ Examples

Serve metrics at /metrics the default loopback port 5000 using data fetched every 15 seconds from the Network Information Server at 192.168.0.5 on the default port 3551:

$ apc-ups-exporter --nis-address 192.168.0.5
The configured Network Information Server is: 192.168.0.5:3551.

Resetting all metrics...
Starting background metrics collection...
Serving metrics page at http://127.0.0.1:5000/metrics...

Connected to the Network Information Server.
 Fetched status from the Network Information Server.
	Updated the status metric.
	Updated the power metrics.
	Updated the battery metrics.
	Updated the daemon metrics.
 Disconnected from the Network Information Server.
 Waiting 15 seconds for next collection..

๐Ÿ“ฐ Metrics

The following Prometheus metrics are exported:

Status

  • ups_status

Power

  • ups_power_input_expect_voltage
  • ups_power_output_maximum_wattage
  • ups_power_line_voltage
  • ups_power_load_percent

Battery

  • ups_battery_output_actual_voltage
  • ups_battery_time_spent_latest_seconds
  • ups_battery_time_spent_total_seconds
  • ups_battery_remaining_charge_percent
  • ups_battery_remaining_time_minutes

Daemon

  • ups_daemon_remaining_charge_percent
  • ups_daemon_remaining_time_minutes
  • ups_daemon_timeout_minutes
  • ups_daemon_transfer_count
  • ups_daemon_start_timestamp

โš–๏ธ License

Copyright (C) 2022-2023 viral32111.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses.

apc-ups-exporter's People

Contributors

dependabot[bot] avatar viral32111 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

az3

apc-ups-exporter's Issues

Using with BE850G2

Did you have to do any extra config besides default for apcupsd to recognize your BE850G2 ?
I am unable to read any data from BE850G2 with apcaccess.
Yhanks

HTTP JSON API

Extend the project to not only be a Prometheus Metrics Exporter, but also a HTTP JSON API that other applications and services may integrate with, so they do not have to go through apcupsd or directly over USB/serial.

Similar to viral32111/kasa-smart-plug#3.

Replacement Daemon

Rewrite this to not just be a Prometheus Metrics Exporter, but also a drop-in replacement for the ancient apcupsd.

This will likely require rewriting the entire project.

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.