A Prometheus exporter for sunspec devices based on pySunSpec2.
Project description
Prometheus pySunSpec2 Exporter
This (unimaginatively named) Prometheus exporter exposes all of the numeric data points exposed by a SunSpec-compliant device. This includes a large number of solar and energy storage systems such as those manufactured by Fronius amongst several hundred others.
This exporter is based on the pySunSpec2 implementation of the SunSpec standard and therefore should support both older and more recent SunSpec-compliant devices.
Quick-start
Install from PyPI using:
$ pip install prometheus_pysunspec2_exporter
The exporter is started using:
$ prometheus_pysunspec2_exporter path/to/config.yml [--address=0.0.0.0] [--port=9502]
The exporter is configured via a YAML configuration file (full documentation below) which looks like:
---
devices:
- tcp: # Also supports 'rtu' (serial) and 'file' (for testing)
ipaddr: 192.168.1.123
slave_id: 1
labels: # Optional extra metric labels
name: inverter
excluded_models: # Optional (accepts numbers or names)
- common
- 122
Metrics
All numeric data points are exported as Prometheus gauge metrics whose names
begin sunspec_*.
Metric names are constructed from the SunSpec-defined model, group and point
names and the unit (if one is defined). For example, a metric named
sunspec_mppt_module_1_DCW_W comes from the 'mppt' model
(160),
from the first instance of the group group 'module' (module_1) and the point
named DCW with the unit W.
Metric help strings are constructed from the documentation in the SunSpec model database and also include documented enumeration and bit field values where applicable.
An additional metric sunspec_up is 1 if data acquisition was successful or 0
otherwise. When data fetching fails, no other metrics for that device will be
included in the scrape.
The following labels are applied:
device_type-- Set to the device type (i.e. one of 'tcp', 'rtu' or 'file')- All device options are assigned to labels (e.g.
ip_addrandslave_idin the example above). - Additional labels specified in the config are also added.
Config Documentation
The configuration format consists of a YAML file defining a map with the key 'devices' set to an array of device specifications:
---
devices:
- <device specification>
- ...
Each device specification is a map containing the following keys:
- One of
tcp,rtuorfile: Specifies how to connect to the device. Required. excluded_models: A list of SunSpec model IDs or names to exclude from the gathered metrics. Optional. Default value:[]labels: A map defining additional labels to add to all metrics relating to this device. Values here override any labels automatically added based on the device connection details.
The tcp, rtu and file values must be a map providing connection details
for the Modbus TCP or RTU device, or dummy SunSpec data
file
to connect to, respectively. A summary of available options, and their defaults
are enumerated below:
# For Modbus TCP
tcp:
ipaddr: '127.0.0.1' # Required (in practice). Hostname or IP.
ipport: 502 # Optional. Port number.
slave_id: 1 # Optional. Modbus slave ID
timeout: null # Optional. Modbus request timeout, seconds.
tls: false # Optional. Use TLS
cafile: None # Optional. TLS CA for remote sunspec device.
insecure_skip_tls_verify: false # Optional. Skip TLS certificate checking.
certfile: null # Optional. TLS client certificate.
keyfile: null # Optional. TLS client private key.
max_count: 125 # Optional. Max number of registers per read
# For Modbus RTU
rtu:
slave_id: <int> # Required. Modbus slave id.
name: <str> # Required. Serial port name (e.g. 'com4' or '/dev/ttyUSB0').
baudrate: 9600 # Optional. Baud rate.
parity: N # Optional. Parity. 'N' = None, 'E' = Even.
timeout: null # Optional. Modbus request timeout, seconds.
# For dummy file-based devices (for test use)
file:
filename: <str> # Required. The file to read
addr: 40002 # Optional. The emulated Modbus start address
[!NOTE]
The supported options map exactly to the constructor arguments of the underlying pySunSpec2 device objects (
SunSpecModbusClientDeviceTCP,SunSpecModbusClientDeviceRTUandFileClientDevice).
See also
This project was inspired by Ramon Buckland's inosion/prometheus-sunspec-exporter implementation which is built on the earlier pySunSpec library, but is not a drop-in replacement. Noteworthy differences between these two exporters include:
- This implementation does have compatible metric names.
- This implementation is built on pySunSpec2 which (apparently) supports some newer SunSpec constructs which the original does not. As such, some newer devices may only be supported by pySunSpec2.
- This implementation supports reading metrics from multiple devices at once.
- This implementation auto-reconnects to devices (e.g. after a network outage).
- This implementation makes no attempts to guess the metric type to use. Everything is always a gauge.
- This implementation doesn't include any data filtering/fix-up functionality.
- This implementation is distributed as a regular Python package on PyPI and not as a Docker file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file prometheus_pysunspec2_exporter-0.0.3.tar.gz.
File metadata
- Download URL: prometheus_pysunspec2_exporter-0.0.3.tar.gz
- Upload date:
- Size: 52.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd2ebbf217d6d8be93c817b301f5e1a74ecbe46ad5d9cb8ad1c6ef0954c18126
|
|
| MD5 |
eafb4e2caaaf78a3b32d67702ba047c5
|
|
| BLAKE2b-256 |
f7cd63c870db3d8695749c79dcc9639e2734136e13befa2f13564f825bace6e5
|
File details
Details for the file prometheus_pysunspec2_exporter-0.0.3-py3-none-any.whl.
File metadata
- Download URL: prometheus_pysunspec2_exporter-0.0.3-py3-none-any.whl
- Upload date:
- Size: 36.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd88c64739985af60a42b3d780f28791d57ee000094100f899a09b5c68ace662
|
|
| MD5 |
ec6c4a09b1b505a7519fda6ee29d65dc
|
|
| BLAKE2b-256 |
e87cbcc6531620f0f86b5b17731a3b85249a74ad0ccc179ac7c219b85c810fae
|