---
title: Charmhub | Deploy Prometheus Pushgateway Charmed Operator using Charmhub -
  The Open Operator Collection
description: Deploy the latest version of Prometheus Pushgateway Charmed Operator
  as a Kubernetes Operator on any cloud.
url: https://charmhub.io/prometheus-pushgateway-k8s/libraries/pushgateway
---

# Prometheus Pushgateway Charmed Operator

[Simon Aronsson](https://charmhub.io/publisher/0x12b "View all packages from Simon Aronsson")

* [Simon Aronsson](https://charmhub.io/publisher/0x12b "View all packages from Simon Aronsson")

Platform:

1.11/stable rev31-1-gebc6427

```
juju deploy prometheus-pushgateway-k8s --channel 1.11/stable
```

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

[Toggle side navigation](https://charmhub.io/prometheus-pushgateway-k8s/libraries/pushgateway#drawer)

## charms.prometheus\_pushgateway\_k8s.v0.pushgateway

* [*Docstrings*Docstrings](https://charmhub.io/prometheus-pushgateway-k8s/libraries/pushgateway)
  [*Code*Source code](https://charmhub.io/prometheus-pushgateway-k8s/libraries/pushgateway/source-code)
* + Download

    Fetch library

    ```
    charmcraft fetch-lib charms.prometheus_pushgateway_k8s.v0.pushgateway
    ```

    [Download pushgateway.py](https://charmhub.io/prometheus-pushgateway-k8s/libraries/pushgateway/download)
  + *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](https://charmhub.io/prometheus-pushgateway-k8s/libraries/pushgateway#prometheuspushgatewayprovider)
* + [def \_\_init\_\_(
    self,
    charm,
    relation\_name,
    endpoint)](https://charmhub.io/prometheus-pushgateway-k8s/libraries/pushgateway#prometheuspushgatewayprovider-__init__)
* + [def update\_endpoint(
    self,
    endpoint)](https://charmhub.io/prometheus-pushgateway-k8s/libraries/pushgateway#prometheuspushgatewayprovider-update_endpoint)
* [class PrometheusPushgatewayRequirer](https://charmhub.io/prometheus-pushgateway-k8s/libraries/pushgateway#prometheuspushgatewayrequirer)
* + [def \_\_init\_\_(
    self,
    charm,
    relation\_name)](https://charmhub.io/prometheus-pushgateway-k8s/libraries/pushgateway#prometheuspushgatewayrequirer-__init__)
* + [def is\_ready(
    self)](https://charmhub.io/prometheus-pushgateway-k8s/libraries/pushgateway#prometheuspushgatewayrequirer-is_ready)
* + [def send\_metric(
    self,
    name,
    value,
    ignore\_error,
    verify\_ssl,
    job\_name)](https://charmhub.io/prometheus-pushgateway-k8s/libraries/pushgateway#prometheuspushgatewayrequirer-send_metric)

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

charm

a `CharmBase` object that manages this object. Typically,
this is `self` in the instantiating class.

relation\_name

the name of the relation (whatever was used
in the `requires` section in `metadata.yaml` for the `pushgateway` interface.

endpoint

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

charm

a `CharmBase` object that manages this object. Typically,
this is `self` in the instantiating class.

relation\_name

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

name

the name of the metric.

value

the value of the metric.

ignore\_error

raise or not error while performing the request.

verify\_ssl

verify ssl certificate in the request.

job\_name

name of the job for the current metric.
