Skip to main content

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_addr and slave_id in 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, rtu or file: 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, SunSpecModbusClientDeviceRTU and FileClientDevice).

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.

Metadata

Release files for prometheus-pysunspec2-exporter 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for prometheus-pysunspec2-exporter 0.0.3
File Size Uploaded
prometheus_pysunspec2_exporter-0.0.3.tar.gz 52.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for prometheus-pysunspec2-exporter 0.0.3
File Interpreter ABI Platform
prometheus_pysunspec2_exporter-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 88.4 kB

Release files / prometheus_pysunspec2_exporter-0.0.3.tar.gz

Download URL prometheus_pysunspec2_exporter-0.0.3.tar.gz
Size 52.3 kB
Tags Source
SHA-256 checksum
How to use checksums
dd2ebbf217d6d8be93c817b301f5e1a74ecbe46ad5d9cb8ad1c6ef0954c18126
BLAKE2b-256 checksum
How to use checksums
f7cd63c870db3d8695749c79dcc9639e2734136e13befa2f13564f825bace6e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.3

Release files / prometheus_pysunspec2_exporter-0.0.3-py3-none-any.whl

Download URL prometheus_pysunspec2_exporter-0.0.3-py3-none-any.whl
Size 36.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bd88c64739985af60a42b3d780f28791d57ee000094100f899a09b5c68ace662
BLAKE2b-256 checksum
How to use checksums
e87cbcc6531620f0f86b5b17731a3b85249a74ad0ccc179ac7c219b85c810fae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.3

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page