RoboPLC re-exports Metrics crate which is recommended to expose metrics from the program.


To work with metrics, enable roboplc crate metrics feature.

Working with metrics

The crate provides several kinds of metrics:

  • Counter (an integer value that can only increase)

  • Gauge (a floating point value)

  • Histogram


use roboplc::prelude::*;
use roboplc::metrics::{counter, gauge, histogram};

let mut prev = None;
// a counter
let c1 = counter!("worker::counter");
// a counter with a label
let c2 = counter!("worker::counter", "incr" => "2");
// a gauge
let g = gauge!("worker::value");
// a histogram
let h = histogram!("worker");
for _ in roboplc::time::interval(step) {
    let now = Monotonic::now();
    if let Some(prev) = prev {
        h.record(now.duration_since(prev).as_micros() as f64);

Refer to the Metrics documentation for more details.


Metrics should not be used to export production data. Use a proper fieldbus protocol for that. Metrics are useful for program debugging and monitoring purposes only.

Exporting metrics

The Metrics project provides several ways to expose metrics. RoboPLC re-exports metrics-exporter-prometheus builder:


The above example starts an HTTP server on the default address with bucket time-to-live of 600 seconds. To start the server on a different address, refer to metrics_exporter_prometheus crate documentation.

Viewing metrics

If RoboPLC Manager is used, the metrics can be viewed in its interface. The program metrics must be available on the host at the address http://localhost:9000.


The viewer supports histograms exported as summaries with quantiles only. The metrics can be also viewed in any Prometheus-compatible monitoring system.