Skip to content

canonical/interface-prometheus-manual

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Interface prometheus-manual

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 their ca_file, cert_file and key_file field values replaced with the path to the file where the provided ca_cert, client_cert and client_key data is written respectively.

Example Usage

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'),
                            })

Reference

Contact Information

Maintainer: Cory Johns <Cory.Johns@canonical.com>

About

Interface layer for register manual scrape job configuration stanzas with Prometheus 2

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%