# Prometheus and Grafana

## Prometheus configuration

Add the exporter as a scrape target:

```
scrape_configs:
  - job_name: "duplicacy"
    static_configs:
      - targets: ["duplicacy-exporter:9750"]
        labels:
          instance: "my-server"
```

## Example alerting rule

```
groups:
  - name: duplicacy
    rules:
      - alert: DuplicacyBackupFailed
        expr: duplicacy_backup_last_exit_code != 0
        for: 5m
        labels:
          severity: warning
        annotations:
          summary: "Duplicacy backup failed for {{ $labels.snapshot_id }}"

      - alert: DuplicacyBackupStale
        expr: time() - duplicacy_backup_last_success_timestamp_seconds > 86400
        for: 1h
        labels:
          severity: critical
        annotations:
          summary: "No successful Duplicacy backup in 24h for {{ $labels.snapshot_id }}"

      # Duplicacy exits 0 even when it could not read some files, so a backup
      # with holes looks like a success unless you watch this count.
      - alert: DuplicacyBackupSkippedFiles
        expr: duplicacy_backup_last_files_skipped > 0 or duplicacy_backup_last_directories_skipped > 0
        labels:
          severity: warning
        annotations:
          summary: "Duplicacy backup {{ $labels.snapshot_id }} left out {{ $value }} entries (access errors)"
```

## Grafana dashboard

A ready-to-import dashboard is included in [`dashboard.json`](<https://github.com/GeiserX/duplicacy-exporter/blob/main/dashboard.json>) and published on [Grafana.com (\#25089)](<https://grafana.com/grafana/dashboards/25089>).

Import it in Grafana via **Dashboards → Import → Upload JSON file** or use the dashboard ID `25089`.
