---
title: Charmhub | Deploy Canonical Observability Stack Lite using Charmhub - The Open
  Operator Collection
description: Deploy the latest version of Canonical Observability Stack Lite on any
  cloud.
url: https://charmhub.io/cos-lite/docs/how-to/metrics-endpoint
---

##### 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.

[Learn more](https://discourse.charmhub.io/t/discontinuing-new-charmhub-bundle-registrations/15344)

# Canonical Observability Stack Lite

[Canonical Observability](https://charmhub.io/publisher/observability "View all packages from Canonical Observability")
| bundle

* [Canonical Observability](https://charmhub.io/publisher/observability "View all packages from Canonical Observability")
  | bundle

Platform:

stable 26

```
juju deploy cos-lite
```

[Learn to deploy on juju >](https://juju.is/docs/juju/manage-applications)

---

#### Relevant links

* [Homepage](https://github.com/canonical/cos-lite-bundle)

---

#### Contacts

* [Submit a bug](https://github.com/canonical/cos-lite-bundle/issues)

---

Share your thoughts on this charm with the community on discourse.

[Join the discussion](https://discourse.charmhub.io/)

---

[Add docs to a charm](https://juju.is/docs/sdk/add-docs-to-your-charmhub-page)

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`](https://charmhub.io/prometheus-k8s) or [`grafana-agent-k8s`](https://charmhub.io/grafana-agent-k8s).

## [Prerequisites](https://charmhub.io/cos-lite/docs/how-to/metrics-endpoint#p-21634-prerequisites)

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

## [Fetch the Library](https://charmhub.io/cos-lite/docs/how-to/metrics-endpoint#p-21634-fetch-the-library)

Fetch the `prometheus_scrape` library using the `charmcraft` command:

```
charmcraft fetch-lib charms.prometheus_k8s.v0.prometheus_scrape
```

## [Import the Library](https://charmhub.io/cos-lite/docs/how-to/metrics-endpoint#p-21634-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](https://charmhub.io/cos-lite/docs/how-to/metrics-endpoint#p-21634-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](https://charmhub.io/cos-lite/docs/how-to/metrics-endpoint#p-21634-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!

---
