---
title: Charmhub | Deploy Grafana using Charmhub - The Open Operator Collection
description: Deploy the latest version of Grafana as a Kubernetes Operator on any
  cloud.
url: https://charmhub.io/grafana-k8s/libraries/grafana_info
---

# Grafana

[Canonical Observability](https://charmhub.io/publisher/observability "View all packages from Canonical Observability")

* [Canonical Observability](https://charmhub.io/publisher/observability "View all packages from Canonical Observability")

Platform:

12.4/stable tf-12.4.3-2-g8187475

```
juju deploy grafana-k8s --channel 12.4/stable --trust
```

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

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

## charms.grafana\_k8s.v0.grafana\_info

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

    Fetch library

    ```
    charmcraft fetch-lib charms.grafana_k8s.v0.grafana_info
    ```

    [Download grafana\_info.py](https://charmhub.io/grafana-k8s/libraries/grafana_info/download)
  + *Last updated* 04 Mar 2025
  + *Revision* Library version 0.1

grafana\_metadata.

This library implements endpoint wrappers for the grafana-metadata interface. The grafana-metadata interface is used to
transfer information about an instance of Grafana, such as how to access and uniquely identify it. Typically, this is
useful for charms that operate a Grafana instance to give other applications access to its API.

##### Usage

###### Requirer

GrafanaMetadataRequirer is a wrapper for pulling data from the grafana-metadata interface. To use it in your charm:

* observe the relation-changed event for this relation wherever your charm needs to use this data (this endpoint wrapper
  DOES NOT automatically observe any events)
* wherever you need access to the data, call `GrafanaMetadataRequirer(...).get_data()`

An example implementation is:

```
class FooCharm(CharmBase):
    def __init__(self, framework):
        super().__init__(framework)

        grafana_mnetadata = GrafanaMetadataRequirer(self.model.relations, "grafana-metadata")

        self.framework.observe(self.on["grafana-metadata"].relation_changed, self._on_grafana_metadata_changed)

    def _on_grafana_metadata_changed(self):
        data = grafana_mnetadata.get_data()
        ...
```

Where you also add relation to your `charmcraft.yaml` or `metadata.yaml` (note that GrafanaMetadataRequirer is designed
for relating to a single application and must be used with limit=1 as shown below):

```
requires:
  grafana-metadata:
    limit: 1
    interface: grafana_metadata
```

###### Provider

GrafanaMetadataProvider is a wrapper for publishing data to charms related using the grafana-metadata interface. Note
that `GrafanaMetadataProvider` *does not* manage any events, but instead provides a `publish` method for sending data to
all related applications. Triggering `publish` appropriately is left to the charm author, although generally you want
to do this at least during the `relation_joined` and `leader_elected` events. An example implementation is:

```
class FooCharm(CharmBase):
    def __init__(self, framework):
        super().__init__(framework)
        self.grafana_metadata = GrafanaMetadataProvider(
            relations=self.model.relations,
            relation_name="grafana-metadata",
            app=self.app,
        )

        self.framework.observe(self.on.leader_elected, self.do_something_to_publish)
        self.framework.observe(self._charm.on["grafana-metadata"].relation_joined, self.do_something_to_publish)
        self.framework.observe(self.on.some_event_that_changes_grafana_metadata, self.do_something_to_publish)

    def do_something_to_publish(self, e):
        self.grafana_metadata.publish(...)
```

Where you also add the following to your `charmcraft.yaml` or `metadata.yaml`:

```
provides:
  grafana-metadata:
    interface: grafana_metadata
```

---

Index

* [class GrafanaMetadataAppData](https://charmhub.io/grafana-k8s/libraries/grafana_info#grafanametadataappdata)
* [class GrafanaMetadataRequirer](https://charmhub.io/grafana-k8s/libraries/grafana_info#grafanametadatarequirer)
* + [def \_\_init\_\_(
    self,
    relation\_mapping,
    relation\_name)](https://charmhub.io/grafana-k8s/libraries/grafana_info#grafanametadatarequirer-__init__)
* + [def relations(
    self)](https://charmhub.io/grafana-k8s/libraries/grafana_info#grafanametadatarequirer-relations)
* + [def get\_data(
    self)](https://charmhub.io/grafana-k8s/libraries/grafana_info#grafanametadatarequirer-get_data)
* [class GrafanaMetadataProvider](https://charmhub.io/grafana-k8s/libraries/grafana_info#grafanametadataprovider)
* + [def \_\_init\_\_(
    self,
    relation\_mapping,
    app,
    relation\_name)](https://charmhub.io/grafana-k8s/libraries/grafana_info#grafanametadataprovider-__init__)
* + [def relations(
    self)](https://charmhub.io/grafana-k8s/libraries/grafana_info#grafanametadataprovider-relations)
* + [def publish(
    self,
    grafana\_uid,
    direct\_url,
    ingress\_url)](https://charmhub.io/grafana-k8s/libraries/grafana_info#grafanametadataprovider-publish)

#### class GrafanaMetadataAppData

Description

Data model for the grafana-metadata interface. None

#### class GrafanaMetadataRequirer

Description

Endpoint wrapper for the requirer side of the grafana-metadata relation. None

Methods

GrafanaMetadataRequirer.
\_\_init\_\_(

*self*

,
relation\_mapping: RelationMapping

,
relation\_name: str
)

Initialize the GrafanaMetadataRequirer object.

Arguments

relation\_mapping

The RelationMapping of a charm (typically `self.model.relations` from within a charm
object).

relation\_name

The name of the wrapped relation.

Description

This object is for accessing data from relations that use the grafana-metadata interface. It **does not**
autonomously handle the events associated with that relation. It is up to the charm using this object to
observe those events as they see fit. Typically, that charm should observe this relation's relation-changed
event.

This object is for interacting with a relation that has limit=1 set in charmcraft.yaml. In particular, the
get\_data method will raise if more than one related application is available.

GrafanaMetadataRequirer.
relations(

*self*
)

Description

Return the relation instances for applications related to us on the monitored relation. None

GrafanaMetadataRequirer.
get\_data(

*self*
)

Return data for at most one related application, raising if more than one is available.

Description

Useful for charms that always expect exactly one related application. It is recommended that those charms also
set limit=1 for that relation in charmcraft.yaml. Returns None if no data is available (either because no
applications are related to us, or because the related application has not sent data).

#### class GrafanaMetadataProvider

Description

The provider side of the grafana-metadata relation. None

Methods

GrafanaMetadataProvider.
\_\_init\_\_(

*self*

,
relation\_mapping: RelationMapping

,
app: Application

,
relation\_name: str
)

Initialize the GrafanaMetadataProvider object.

Arguments

relation\_mapping

The RelationMapping of a charm (typically `self.model.relations` from within a charm object).

app

This application.

relation\_name

The name of the relation.

Description

This object is for serializing and sending data to a relation that uses the grafana-metadata interface - it does
not automatically observe any events for that relation. It is up to the charm using this to call publish when
it is appropriate to do so, typically on at least the charm's leader\_elected event and this relation's
relation\_joined event.

GrafanaMetadataProvider.
relations(

*self*
)

Description

Return the applications related to us under the monitored relation. None

GrafanaMetadataProvider.
publish(

*self*

,
grafana\_uid: str

,
direct\_url: AnyHttpUrl

,
ingress\_url
)

Post grafana-metadata to all related applications.

Arguments

grafana\_uid

The UID of this Grafana instance.

direct\_url

The cluster-internal URL at which this application can be reached. Typically, this is a
Kubernetes FQDN like name.namespace.svc.cluster.local for connecting to the prometheus api
from inside the cluster, with scheme.

ingress\_url

The non-internal URL at which this application can be reached. Typically, this is an ingress
URL.

Description

This method writes to the relation's app data bag, and thus should never be called by a unit that is not the
leader otherwise ops will raise an exception.
