MetricsRegistry#

class openfactory.monitoring.registry.src.metrics_registry.MetricsRegistry(*args, **kwargs)[source]#

Bases: OpenFactoryFastAPIApp

OpenFactory Metrics Registry.

This service acts as a bridge between OpenFactory applications and Prometheus HTTP Service Discovery.

Applications register and deregister Prometheus metrics endpoints through OpenFactory methods. Registered endpoints are persisted in Kafka and materialized into a KSQLDB table.

Prometheus periodically queries the HTTP discovery endpoint to obtain the list of metrics targets to scrape.

By default, the discovery endpoint is exposed at:

/prometheus/targets

This can be overridden using the environment variable PROMETHEUS_SD_ENDPOINT.

The registry itself does not store any state in memory. Kafka and KSQLDB are the source of truth for all registered metrics endpoints.

__init__(*args, **kwargs)[source]#

Initialize the MetricsRegistry.

This constructor forwards all parameters to OpenFactoryFastAPIApp

Environment Variables:
PROMETHEUS_SD_ENDPOINT:

HTTP endpoint exposing the Prometheus HTTP Service Discovery target list.

Default:

/prometheus/targets

Parameters:
  • ksqlClient – KSQL client instance.

  • bootstrap_servers – Kafka bootstrap server address.

  • asset_router_url – Asset Router URL.

  • loglevel – Logging level (e.g., INFO, DEBUG).

  • test_mode – Enables test mode (disables live Kafka/ksql interaction).

See also

OpenFactoryFastAPIApp for full initialization details and environment variable handling.

deregister_target(application_uuid)[source]#

Deregister a Prometheus metrics endpoint

prometheus_targets()[source]#

Return metrics targets using the Prometheus HTTP Service Discovery format.

Prometheus periodically invokes this endpoint to discover metrics endpoints exposed by OpenFactory applications.

Returns:

list[dict] – List of Prometheus target definitions.

Example:

[
  {
    "targets": ["shdr-gateway:4000"],
    "labels": {
       "__metrics_path__": "/metrics"
    }
  }
]
register_target(application_uuid, host, port, path='/metrics')[source]#

Register a Prometheus metrics endpoint