Generic Exporter attach-alert-rules

Attach alert rules from a resource

This guide describes how to provide custom Prometheus alert rules to the Generic Exporter operator using a Juju resource. The charm will:

  • Read the attached resource file (YAML)
  • Write it into an alerts rules directory under /run/<app>-<unit-id>/
  • Expose those rules via the metrics-endpoint relation to Grafana Agent and COS Lite

Requirements

  • Generic Exporter operator deployed and running.
  • (Optional) Grafana Agent and COS Lite are already integrated, as described in the previous how-to.

Prepare an alerts resource

Create a local file alerts.yaml containing one or more Prometheus alerting rules. For example:

groups:
  - name: generic-exporter.rules
    rules:
      - alert: ExporterDown
        expr: up{job="node-exporter"} == 0
        for: 5m
        labels:
          severity: warning
        annotations:
          summary: "Exporter is down on {{ $labels.instance }}"
          description: "The node-exporter exporter has not been scraping successfully for 5 minutes."

Ensure the file is valid YAML and follows Prometheus alert rule syntax.

Attach the resource

Attach the resource to the Generic Exporter application. Assuming the app is called node-exporter:

juju attach-resource node-exporter alerts=./alerts.yaml

The charm will:

  • Fetch the alerts resource
  • Write it to a rules directory, for example:
    /run/node-exporter-0/alerts.yaml
    
  • Notify Grafana Agent via the metrics-endpoint relation so that alerts are reloaded.

Use the dump-alerts action

To verify which rules the charm has loaded, use the dump-alerts action (provided by the charm):

juju run node-exporter/0 dump-alerts --wait

The action prints the effective path on the machine and dumps the alert rules. This is useful for validating that the uploaded resource is being parsed and consumed correctly.

Update or remove alerts

To update alert rules, modify alerts.yaml and re-attach:

juju attach-resource node-exporter alerts=./alerts.yaml

To effectively remove alerts:

  • Attach an empty rules file, or
  • Use a minimal file that defines an empty rule group.

The charm will refresh the rules directory and inform Grafana Agent via its refresh_events configuration.