Skip to content
DevOps AI ToolKit
Newsletter
All prompts
AI for Grafana Difficulty: Intermediate ClaudeChatGPT

Grafana Library Panels Reuse Prompt

Design reusable Grafana library panels shared across many dashboards so one edit propagates everywhere without copy-paste drift.

Target user
Dashboard authors standardizing panels across teams
Difficulty
Intermediate
Tools
Claude, ChatGPT

The prompt

You are a senior observability engineer who builds Grafana library panels — reusable panels stored once and linked into many dashboards so a single edit updates all instances.

I will provide:
- The panels duplicated across dashboards
- The variables those dashboards use
- Who owns the panel and change cadence

Your job:

1. **Identify candidates**: panels repeated verbatim (SLO tiles, node CPU, error-rate graphs) are prime library-panel candidates; one-offs are not.
2. **Create the library panel**: from an existing panel, use "Create library panel", give it a clear name and folder; it stores the panel model with a shared `libraryPanel.uid`.
3. **Parameterize with variables**: keep queries generic using dashboard template variables (`$namespace`, `$datasource`) so the same panel adapts per dashboard.
4. **Reference, don't copy**: dashboards store a lightweight link (`libraryPanel.uid` + name); the body is resolved from the library at render time.
5. **Field config**: standardize units, thresholds, and value mappings inside the library panel so branding/formatting stays consistent.
6. **Governance**: place library panels in a governed folder with RBAC; editing the panel changes every dashboard using it, so restrict who can edit.
7. **Audit usage**: use the API to list which dashboards reference a library panel before changing it.
8. **Version awareness**: schema changes to the panel apply globally on save; test in a staging dashboard first.

Mark DESTRUCTIVE: deleting a library panel in use (unlinks/breaks every dashboard), or editing a widely-used panel's query without checking references.

---

Duplicated panels: [DESCRIBE]
Dashboard variables: [DESCRIBE]
Owner/change cadence: [DESCRIBE]

Why this prompt works

Copy-pasting panels across dashboards guarantees drift: units, thresholds, and queries diverge over time. Library panels centralize the model, but the trap is that one edit propagates everywhere and hardcoded datasource UIDs break portability. This prompt targets true duplicates, parameterizes with variables, and adds a usage audit so global changes are safe.

How to use it

  1. List the panels that are literally duplicated — those are the candidates.
  2. Confirm the variables each dashboard exposes so the panel stays generic.
  3. Audit references before editing a shared panel.
  4. Govern the folder so edit rights are intentional.

Useful commands

# List all library panels
curl -s -H "Authorization: Bearer $TOKEN" \
  http://localhost:3000/api/library-elements?kind=1 | jq '.result.elements[] | {uid,name}'

# Show which dashboards use a library panel (connections)
curl -s -H "Authorization: Bearer $TOKEN" \
  http://localhost:3000/api/library-elements/<uid>/connections | jq

# Get a single library panel model
curl -s -H "Authorization: Bearer $TOKEN" \
  http://localhost:3000/api/library-elements/<uid> | jq '.result.model'

Example config

Dashboard JSON referencing a library panel (body resolved from the library):

{
  "panels": [
    {
      "gridPos": { "h": 8, "w": 12, "x": 0, "y": 0 },
      "id": 4,
      "libraryPanel": {
        "uid": "lib-error-rate",
        "name": "Service Error Rate"
      }
    }
  ],
  "templating": {
    "list": [
      { "name": "datasource", "type": "datasource", "query": "prometheus" },
      { "name": "namespace", "type": "query",
        "query": "label_values(up, namespace)", "datasource": "${datasource}" }
    ]
  }
}

The library panel model itself keeps queries generic:

{
  "type": "timeseries",
  "title": "Service Error Rate",
  "datasource": { "type": "prometheus", "uid": "${datasource}" },
  "targets": [
    { "expr": "sum(rate(http_requests_total{namespace=\"$namespace\",code=~\"5..\"}[5m]))" }
  ],
  "fieldConfig": { "defaults": { "unit": "reqps", "thresholds": {
    "mode": "absolute", "steps": [{ "color": "green" }, { "color": "red", "value": 5 }] } } }
}

Common findings this catches

  • Panel drift → duplicates diverging in units/thresholds.
  • Broken portability → hardcoded datasource UID.
  • Empty panels → panel expects a variable the dashboard lacks.
  • Surprise ripple → edit changed dozens of dashboards.
  • Unsafe deletes → panel removed while still referenced.
  • No ownership → ungoverned folder, anyone can edit.

When to escalate

  • Org-wide standardization of common panels — observability lead.
  • RBAC design for who may edit shared panels — platform/security.
  • Cross-org sharing — export/import strategy.

Related prompts

Newsletter

Free: the DevOps AI Incident-Triage Cheat Sheet

Subscribe and we’ll send you the one-page cheat sheet — plus weekly AI prompts, automation ideas, and tool reviews for infrastructure engineers. One email a week. No spam, unsubscribe anytime.

  • AI Incident-Triage Cheat Sheet (PDF)
  • Access to 2,104 DevOps AI prompts
  • One practical workflow email per week