---
title: Charmhub | Deploy Generic Exporter using Charmhub - The Open Operator Collection
description: Deploy the latest version of Generic Exporter on any cloud.
url: https://charmhub.io/generic-exporter/docs/charm-lifecycle
---

# Generic Exporter

[Marcus Boden](https://charmhub.io/publisher/marcusboden "View all packages from Marcus Boden")

* [Marcus Boden](https://charmhub.io/publisher/marcusboden "View all packages from Marcus Boden")

Platform:

26.04

24.04

22.04

20.04

dev/edge 90

```
juju deploy generic-exporter --channel dev/edge
```

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

---

#### Contacts

* [Submit a bug](https://github.com/canonical/generic-exporter-operator/issues)

---

Share your thoughts on this charm with the community on discourse.

[Join the discussion](https://discourse.charmhub.io/)

# Charm lifecycle

This guide outlines how the Generic Exporter operator responds to core Juju events and manages the exporter snap throughout its lifecycle.

## [Install](https://charmhub.io/generic-exporter/docs/charm-lifecycle#p-40634-install)

On `install`:

* Validate that a usable configuration is present:
  + A `snap-name` is provided, and
  + Either `snap-channel` **or** `snap-revision` is set (but not both).
* Initialize the snap manager using `SnapCache`.
* Install the exporter snap:
  + Using the requested **channel** or **revision**.
  + Respecting `snap-classic` when classic confinement is required.
* Apply any JSON snap configuration from `snap-config` using `snap.set()`.

If configuration is missing or invalid (for example, `snap-name` not set), the charm sets:

```
BlockedStatus("Missing required configuration fields: snap-name")
```

and does not proceed with installation.

## [Config-changed](https://charmhub.io/generic-exporter/docs/charm-lifecycle#p-40634-config-changed)

On `config-changed`:

* Re-validate the charm configuration:
  + Reject cases where both `snap-channel` and `snap-revision` are set simultaneously.
  + Parse `snap-config` as JSON; if parsing fails, block with an appropriate message.
* Reapply snap configuration:
  + Call `snap.set()` with the parsed configuration.
  + Call `snap.unset()` if any configuration was unset.
  + On failure, stop the snap and set a `Blocked` status.
* Reapply `snap-plugs` by connecting the requested interfaces.
* Detect a change in the exporter identity:
  + If the configured exporter changes (for example, `snap-name` changed), uninstall the previous snap and clean up its alerts directory.
* Reconcile alert rules:
  + If an `alerts` resource is present, re-read and rewrite rules to `/run/<app-name>-<unit-id>/alerts.yaml`.
* Notify COS integration:
  + Update scrape configuration and alert rules via `COSAgentProvider`, using `config-changed` as a refresh event.

## [Update-status](https://charmhub.io/generic-exporter/docs/charm-lifecycle#p-40634-update-status)

On `update-status`, the charm performs a simple health check against the exporter’s HTTP endpoint:

* Issue a GET request to `http://localhost:<port>/<metrics-path>`.
  + If the request fails or the endpoint is unreachable, set:

  ```
  BlockedStatus("Metrics endpoint not reachable")
  ```
* Ensure that the snap services are active.
* Check that the charm is related to Opentelemetry Collector
  + If the check fails, the charm sets:

  ```
  BlockedStatus("Missing relation: [cos-agent]")
  ```

If every check passes, the charm enters `Active` state. These checks ensure that both the snap and its configuration are functioning as expected.

## [Remove](https://charmhub.io/generic-exporter/docs/charm-lifecycle#p-40634-remove)

On `remove`:

* Stop and remove the exporter snap from the unit.
* Remove the alerts directory and any associated files.

---
