We've discontinued the registration of new Bundles

New Bundle registrations are no longer accepted. Existing bundles remain functional. We recommend using the Juju Terraform Provider for new deployments.

Canonical Observability Stack Lite

Canonical Observability Publisher | bundle

Platform:

Ubuntu
Channel Revision Published
latest/stable 26 20 Jun 2025
latest/candidate 25 20 Jun 2025
latest/beta 24 20 Jun 2025
latest/edge 23 20 Jun 2025
juju deploy cos-lite --channel edge

Integrating with the metrics endpoint interface allows you to, through a minimal amount of code, enable your charm to get scraped by a charm like prometheus-k8s or grafana-agent-k8s.

Prerequisites

  • A charm with a workload that exposes a metrics endpoint.
  • A Juju deployment with COS Lite deployed.

Fetch the Library

Fetch the prometheus_scrape library using the charmcraft command:

charmcraft fetch-lib charms.prometheus_k8s.v0.prometheus_scrape

Import the Library

At the top of your charm’s src/charm.py source file, add an import of the charm library you just imported.

from charms.prometheus_k8s.v0.prometheus_scrape import MetricsEndpointProvider

Using the constructor

In the __init__ function of your charm class, instantiate the MetricsEndpointProvider. In its simplest form, where the workload exposes its metrics endpoint over port 80, with the path /metrics.

class ScrapableCharm:
    # ...
    def __init__(self, *args):
        # ...
        self.metrics_endpoint = MetricsEndpointProvider(self)

To override the default targets or the metrics path, you may then supply them as additional arguments while doing the instantiation.

class ScrapableCharm:
    # ...
    def __init__(self, *args):
        # ...
        self.metrics_endpoint_provider = MetricsEndpointProvider(
                self,                                  
                jobs=[{
                    "metrics_path": "/my/strange/metrics/path",
                    "static_configs": [{"targets": ["*:8080"]}],
                }])

Declaring the relation

As a last step, you need to declare the relation in your charms metadata.yaml file.

provides:
  metrics-endpoint:
    interface: prometheus_scrape

Congratulations! You will now be able to add an integration between your charm and a scraper! :tada:


Help improve this document in the forum (guidelines). Last updated 1 year, 10 months ago.