Canonical Observability Stack Lite
- Canonical Observability | bundle
Channel | Revision | Published |
---|---|---|
latest/stable | 11 | 21 Oct 2022 |
latest/candidate | 10 | 21 Oct 2022 |
latest/beta | 9 | 21 Oct 2022 |
latest/edge | 18 | 20 Jun 2023 |
1.0/stable | 16 | 21 Oct 2022 |
1.0/candidate | 14 | 21 Oct 2022 |
1.0/beta | 13 | 21 Oct 2022 |
1.0/edge | 12 | 21 Oct 2022 |
juju deploy cos-lite --channel edge
Deploy Kubernetes operators easily with Juju, the Universal Operator Lifecycle Manager. Need a Kubernetes cluster? Install MicroK8s to create a full CNCF-certified Kubernetes system in under 60 seconds.
Platform:
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!