This is a Juju interface layer that enables a charm which provides manual or raw metric scraper job configuration stanzas for Prometheus 2.
The format for the job configuration data can be found in the Prometheus
Configuration Docs. The job configuration will be included as an item
under scrape_configs
largely unchanged, except for two things:
- To ensure uniqueness, the provided job name will have a UUID appended to it.
- Because the CA cert, client cert and key must be written to disk separately
from the config, any
tls_config
sections will have theirca_file
,cert_file
andkey_file
field values replaced with the path to the file where the providedca_cert
,client_cert
andclient_key
data is written respectively.
First, you must define the relation endpoint in your charm's metadata.yaml
:
provides:
prometheus:
interface: prometheus-manual
Next, you must ensure the interface layer is included in your layer.yaml
:
includes:
- interface:prometheus-manual
Then, in your reactive code, add the following, modifying the job data as your charm needs:
from charms.reactive import endpoint_from_flag
@when('endpoint.prometheus.joined',
'tls.ca.available')
def register_prometheus_jobs():
prometheus = endpoint_from_flag('endpoint.prometheus.joined')
tls = endpoint_from_flag('tls.ca.available')
prometheus.register_job(job_name='kubernetes-apiservers',
ca_cert=tls.root_ca_cert,
job_data={
'kubernetes_sd_configs': [{'role': 'endpoints'}],
'scheme': 'https',
'tls_config': {'ca_file': '__ca_file__'}, # placeholder for saved filename
'bearer_token': get_token('system:prometheus'),
})
prometheus.register_job(job_name='kubernetes-nodes',
ca_cert=tls.root_ca_cert,
job_data={
'kubernetes_sd_configs': [{'role': 'node'}],
'scheme': 'https',
'tls_config': {'ca_file': '__ca_file__'}, # placeholder for saved filename
'bearer_token': get_token('system:prometheus'),
})
Maintainer: Cory Johns <Cory.Johns@canonical.com>