Prometheus Pushgateway Charmed Operator
- By Simon Aronsson
Channel | Revision | Published | Runs on |
---|---|---|---|
latest/stable | 16 | 04 Jun 2024 | |
latest/candidate | 16 | 04 Jun 2024 | |
latest/beta | 16 | 22 May 2024 | |
latest/edge | 16 | 03 May 2024 |
juju deploy prometheus-pushgateway-k8s
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:
charms.prometheus_pushgateway_k8s.v0.pushgateway
-
- Last updated 12 Dec 2023
- Revision Library version 0.2
Interface library for the Prometheus Pushgateway.
This library wraps a relation endpoint using the pushgwateway
interface
and exposes an API for forwarding metrics to Prometheus.
Getting Started
Provider side of the relation
This side of the relation is to be used by Prometheus Pushgateway Charm or any other charm that provides the same service.
To get started using the library, you just need to fetch the library using charmcraft
.
cd some-charm
charmcraft fetch-lib charms.prometheus_pushgateway_k8s.v0.pushgateway
In the metadata.yaml
of the charm, add the following:
provides:
push-endpoint:
interface: pushgateway
In the source of your charm, first import the interface:
from charms.prometheus_pushgateway_k8s.v0.pushgateway import PrometheusPushgatewayProvider
Instantiate the object in your charm's __init__
, like so:
from charms.prometheus_pushgateway_k8s.v0.pushgateway import PrometheusPushgatewayRequirer
from ops.charm import CharmBase
class PrometheusPushgatewayK8SOperatorCharm(CharmBase):
def __init__(...):
...
self.pushgateway_provider = PrometheusPushgatewayProvider(
self, "push-endpoint", self._endpoint
)
The relation name when instantiating PrometheusPushgatewayProvider defaults to push-endpoint
,
you can pass a different one if used other name in metadata.yaml
.
Requierer side of the relation
To get started using the library, you just need to fetch the library using charmcraft
.
cd some-charm
charmcraft fetch-lib charms.prometheus_pushgateway_k8s.v0.pushgateway
In the metadata.yaml
of the charm, add the following:
requires:
pushgateway:
interface: pushgateway
In the source of your charm, first import the interface:
from charms.prometheus_pushgateway_k8s.v0.pushgateway import PrometheusPushgatewayRequirer
Instantiate the object in your charm's __init__
, like so:
from charms.prometheus_pushgateway_k8s.v0.pushgateway import PrometheusPushgatewayRequirer
from ops.charm import CharmBase
class MyCharm(CharmBase):
def __init__(...):
...
self.pushgateway_requirer = PrometheusPushgatewayRequirer(self)
The relation name when instantiating PrometheusPushgatewayRequirer defaults to pushgateway
,
you can pass a different one if used other name in metadata.yaml
.
At any moment you can use the Pushgateway Requirer to send a metric (validating that the requirer is ready), passing its name and value:
if self.pushgateway_requirer.is_ready():
self.pushgateway_requirer.send_metric("test_metric", 3.141592)
The requirer is ready when the relation to the Prometheus Pushgateway is properly established.
The send_metric
call will just end quietly if the metric was sent succesfully, or will raise
an exception if something is wrong (that error should be logged or informed to the operator).
Index
class PrometheusPushgatewayProvider
Provider side for the Prometheus Pushgateway.
Description
This class is to be used by the Prometheus Pushgateway charm, please use the PrometheusPushgatewayRequirer class if you're bulding a charm and want to use this library to integrate with the Prometheus Pushgateway.
Methods
PrometheusPushgatewayProvider. __init__( self , charm: CharmBase , relation_name: str , endpoint: str )
Construct the interface for the Prometheus Pushgateway Provider side of the relation.
Arguments
a CharmBase
object that manages this object. Typically,
this is self
in the instantiating class.
the name of the relation (whatever was used
in the requires
section in metadata.yaml
for the pushgateway
interface.
the endpoint that Prometheus Pushgateway expose to consumers, for instance: "https://pushgateway-0.pushgateway-endpoints.clite.svc.cluster.local:9091" or "http://10.1.38.86:9091"
PrometheusPushgatewayProvider. update_endpoint( self , endpoint: str )
Description
Update endpoint in relation data. None
class PrometheusPushgatewayRequirer
Description
Requirer side for the Prometheus Pushgateway. None
Methods
PrometheusPushgatewayRequirer. __init__( self , charm: CharmBase , relation_name: str )
Construct the interface for the Prometheus Pushgateway.
Arguments
a CharmBase
object that manages this object. Typically,
this is self
in the instantiating class.
the name of the relation (whatever was used
in the requires
section in metadata.yaml
for
the pushgateway
interface.
PrometheusPushgatewayRequirer. is_ready( self )
Description
Return if the service is ready to send metrics. None
PrometheusPushgatewayRequirer. send_metric( self , name: str , value , ignore_error: bool , verify_ssl: bool , job_name: str )
Send a metric to the Pushgateway.
Arguments
the name of the metric.
the value of the metric.
raise or not error while performing the request.
verify ssl certificate in the request.
name of the job for the current metric.