Is it possible to register custom metrics to be exported via Prometheus? Specifically, we would like to write values specific to the runtime - e.g. TVL, average throughput, etc..

1 Answer 1


Yes, it is possible to register custom metrics to be exported via Prometheus. Prometheus provides a mechanism for registering custom collectors, which can be used to collect metrics from any source.

To register a custom collector, you need to create a new Rust struct that implements the PrometheusCollector trait. This trait defines a number of methods that are used to collect and export metrics.

Once you have created your custom collector, you can register it with Prometheus by calling the register_collector function. This function takes a reference to your custom collector and a name for the collector.

For example, the following code registers a custom collector that collects the TVL and average throughput of a runtime:

struct TvlValueCollector;

impl PrometheusCollector for TvlValueCollector {
    fn collect(&self) -> Vec<MetricFamily> {
        let mut metrics = Vec::new();

        let tvl = runtime.tvl();
        let throughput = runtime.average_throughput();

            "Total value locked",
            vec![Metric::build("value", tvl, "microEth")],
            "Average throughput",
            vec![Metric::build("value", throughput, "microEth/second")],

        return metrics;

fn main() {
    let collector = TvlValueCollector;
    Prometheus::register_collector(collector, "tvl_collector");


This code will register a custom collector called tvl_collector. This collector will collect the TVL and average throughput of the runtime, and export them as Prometheus metrics.

For more information on registering custom collectors, please see the Prometheus documentation: https://prometheus.io/docs/instrumenting/writing_exporters/.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.