Skip to content

Prometheus metrics exporter for PLC data #623

@gijzelaerr

Description

@gijzelaerr

Summary

Create a Prometheus exporter that reads PLC values and exposes them as Prometheus metrics, enabling integration with Grafana and modern monitoring stacks.

Background

A very common use case in IIoT (Industrial Internet of Things) is monitoring PLC values in Grafana dashboards. Currently users must build custom scripts to bridge PLC data to Prometheus. A built-in exporter would serve this use case out of the box.

What needs to be done

  • Create a configurable exporter that reads PLC values on a schedule
  • Expose values as Prometheus metrics (gauge, counter as appropriate)
  • Support configuration via YAML file (PLC connection details, metrics definitions)
  • Support multiple PLCs in a single exporter instance
  • Use prometheus_client library for metrics exposition
  • Add as a separate optional extra: pip install python-snap7[prometheus]
  • Add CLI command: snap7 export --config metrics.yaml
  • Handle connection failures gracefully (expose connection status as a metric)
  • Add documentation and example configuration

Example Configuration

plcs:
  - name: plc_line1
    host: 192.168.1.10
    rack: 0
    slot: 1
    metrics:
      - name: motor_speed_rpm
        type: gauge
        area: DB
        db: 1
        offset: 0
        datatype: real
        help: "Motor speed in RPM"
      - name: tank_level_percent
        type: gauge
        area: DB
        db: 1
        offset: 4
        datatype: real
        help: "Tank level percentage"

exporter:
  port: 9400
  poll_interval: 5

Notes

  • This could be a separate package (python-snap7-exporter) or an extra in this repo
  • Should support both pull (HTTP endpoint) and optionally push (Pushgateway) modes
  • Consider also supporting OpenTelemetry metrics as an alternative
  • Labels should include PLC name, IP, and any user-defined labels

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions