/betterstack:grafana-importfrom Better Stack
Imports Grafana dashboards from grafana.com templates and translates PromQL queries to ClickHouse for Better Stack. Handles layout extraction, query translation, and chart creation.
Ships in Better Stack. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
# 1. Get summary first (always start here)
node <this skill's directory>/scripts/extract-layout.js --dashboard <ID> --summary
node <this skill's directory>/scripts/extract-layout.js --file <path> --summary
# 2. Extract and build section-by-section
node <this skill's directory>/scripts/extract-layout.js --dashboard <ID> --section 1
# ... build section 1 charts ...
node <this skill's directory>/scripts/extract-layout.js --dashboard <ID> --section 2
# ... build section 2 charts ... and so on
You need the Better Stack dashboard tools (create_dashboard, create_dashboard_chart, update_dashboard) and the query tools sources, query, metric and the source and metrics tools. If your client loads tools on demand, load them before starting.
The extract script is scripts/extract-layout.js in this skill's directory, run with Node.js 18 or newer. If you can't run scripts, read the export yourself and pull out the same fields: sections, panels, their queries, units and template variables.
node scripts/extract-layout.js --dashboard <ID> --summary — see all sections and panel countsmetrics(source_id) to find the available metrics, then metric for each one's tagsSELECT DISTINCT tags FROM {{source}} WHERE name = 'your.first.metric' LIMIT 5 — use exact tag names from real data, never guesscreate_dashboard(source_id, name)templating.list entry, create a Better Stack variable with update_dashboard (its whole variables list) AND reference it in the queries that used $name via an optional [[ ]] clause. Never just omit them. See Template Variable Translation below.node scripts/extract-layout.js --dashboard <ID> --section <n>metrics-query skill)query before creating chartschart-generation + dashboard-builder skills), always pass h: 6 and section: "Name"Query translation checklist:
rate()/irate() to correct merge function, handle sum by/avg by aggregationsstatistics field (Average/Sum/Maximum/Minimum) to correct merge functiona / b) requiring CTEsUse ONLY when explicitly requested (e.g., "import without data", "no metrics available", "blind import"). Never default to this mode — always try the normal workflow first.
When the service has no metric data in Better Stack, you cannot validate queries. Instead:
metrics tool: you can't discover metrics or tags from live datanamespace/metricName → underscore format with suffix (see references/cloudwatch-translation.md)by (label) → label('label') (Prometheus labels keep their names)dimensions → label('snake_case') (CloudWatch tags are snake_case){{time}} only appear where dt is in scope? (pitfall #1)value_columns match the SQL alias exactly? (Mismatch = chart appears empty. Never leave as default ["value"] when SQL uses a descriptive alias.)series_column set when there's a GROUP BY on a tag?unit: "percent", are values 0–1? (divide by 100 if needed)h: 6, section namingKey principle: In no-data mode, the queries may not return results, but they must be structurally correct so they work once data starts flowing. A broken query (wrong column name, bad syntax, missing GROUP BY) is worse than no chart at all.
The extract script shows each panel with its type, queries, and layout info:
- **Panel Title** | chart_type (Grafana: grafana_type) | unit | x:N y:N w:N h:N {settings}
`PromQL expression` → "Legend format"
Or for CloudWatch panels:
- **Panel Title** | chart_type (Grafana: grafana_type) | unit | x:N y:N w:N h:N {settings}
CW: AWS/RDS.CPUUtilization [Average] dims: DBInstanceIdentifier=$dbinstance
Decision tree for each panel:
Check datasource type — Prometheus (has expr) vs CloudWatch (has namespace.metricName):
references/cloudwatch-translation.mdlabel() for tag/label accessCheck panel type — determines chart type:
timeseries / graph → line_chart (default)timeseries with drawStyle: bars → bar_chart with time dimensiontimeseries with stacking: normal → line_chart with stacking: "stack"stat / singlestat → number_chart, single scalar valuegauge / bargauge → gauge_chart or bar_charttable → table_chartpiechart → pie_chartbarchart → bar_chart (category bar, no time dimension)heatmap → heatmap_chartCheck for by (labels) in PromQL or multi-dimension CloudWatch:
Check for instant vs range queries:
instant: true or stat/gauge panel → no {{time}}, scalar result{{time}} AS time and GROUP BY time| PromQL | Line Chart | Gauge/Number |
|---|---|---|
rate(metric[5m]) | avgMerge(rate_avg) | avgMerge(rate_avg) |
irate(metric[5m]) | avgMerge(rate_avg) | argMax(rate, time) from subquery |
metric (gauge) | avgMerge(value_avg) | argMax(value, time) from subquery |
sum(...) / avg(...) | CTE + sum()/avg() | same |
count by (label) | uniqExact(label('label')) | same |
clamp_min(x, 0) | greatest(x, 0) | same |
clamp_max(x, 100) | least(x, 100) | same |
| Function | Computes |
|---|---|
Prometheus irate() | Instant rate from last 2 samples |
ClickHouse avgMerge(rate_avg) | Average rate over entire window |
Use argMax(rate, time) to get the most recent bucket's rate (90-99% match vs Prometheus).
| PromQL | ClickHouse |
|---|---|
avg_over_time(metric[5m]) | avgMerge(value_avg) |
max_over_time(metric[5m]) | maxMerge(value_max) |
min_over_time(metric[5m]) | minMerge(value_min) |
| PromQL | ClickHouse |
|---|---|
metric_a / metric_b | CTE + sumIf(value, name='a') / sumIf(value, name='b') |
metric * 100 | avgMerge(value_avg) * 100 |
1 - metric | 1 - avgMerge(value_avg) |
All metric types (Prometheus, CloudWatch, collector) use label('tag_name') to access tags:
-- Access a tag
label('device') AS series
-- Filter by tag
WHERE label('mode') = 'idle'
-- Group by tag
GROUP BY label('device')
Prometheus labels keep their original names — instance, job, device, mode, cpu, etc. Always verify with a test query.
CloudWatch dimensions are snake_case — DBInstanceIdentifier → db_instance_identifier. See references/cloudwatch-translation.md for the full mapping.
| Grafana token | ClickHouse handling |
|---|---|
$__rate_interval | Ignore — {{time}} handles bucketing |
$__interval | Ignore |
{label="$var"} | [[ AND label('label') = {{var}} ]] (single-value variable) |
{label=~"$var"} | [[ AND match(label('label'), {{var}}) ]] (multi-value variable) |
{job="$job"} | [[ AND label('job') = {{job}} ]] |
Do NOT just omit $var label filters — recreate each as a dashboard variable and reference it with an optional [[ ]] clause. See Template Variable Translation below.
Grafana templating.list variables (the $var selectors at the top) must be recreated as Better Stack dashboard variables — a variable only appears once a query references it, so do BOTH steps.
For each entry in templating.list (skip type: interval → {{time}} handles it; skip datasource/adhoc):
update_dashboard (type reference: dashboard-builder skill → "Dashboard template variables"):
type: query (e.g. label_values(node_cpu_seconds_total, instance)) → multi_select_with_sql (or select_with_sql if multi: false), sql_definition: "label('<label>')" where <label> is the label the variable queries (Prometheus labels keep their names; CloudWatch dimensions → snake_case).type: custom (fixed options) → select_value, default_values: [the option values].type: constant / textbox → string, default_values: [value].$name (or ${name} / [[name]]), as an OPTIONAL [[ ]] clause so charts render with nothing selected (matches Grafana's "All" default):
[[ AND match(label('<label>'), {{name}}) ]][[ AND label('<label>') = {{name}} ]]Name the variable after the Grafana variable's name.
Example — templating.list: [{ name: "instance", type: "query", query: "label_values(node_cpu_seconds_total, instance)", multi: true }], PromQL rate(node_cpu_seconds_total{instance=~"$instance"}[5m]):
update_dashboard(id, variables: [...existing, {name: "instance", variable_type: "multi_select_with_sql", sql_definition: "label('instance')"}]), with existing the variables dashboard returnedSELECT {{time}} AS time, label('instance') AS series, avgMerge(rate_avg) AS "CPU" FROM {{source}} WHERE name = 'node_cpu_seconds_total' [[ AND match(label('instance'), {{instance}}) ]] GROUP BY time, seriesFor CloudWatch panels, read references/cloudwatch-translation.md (in this skill's directory): metric name translation, statistic mapping, the Sum statistic and hidden dimensions, dimension mapping and filters, and metric math.
| Grafana panel | Better Stack chart | Notes |
|---|---|---|
timeseries | line_chart | Default; time-series with {{time}} |
timeseries (drawStyle: bars) | bar_chart | Time-series bars — needs {{time}} |
timeseries (stacking: normal) | line_chart | stacking: "stack" |
graph (legacy) | line_chart | Same as timeseries |
stat | number_chart | Single value, no time |
singlestat (legacy) | number_chart | Same as stat |
gauge | gauge_chart | |
bargauge | gauge_chart | |
table / table-old | table_chart | Set column_units per column + percentage_highlight_columns for ratio cols (see chart-generation skill) |
barchart | bar_chart | Category bar, no time dimension |
piechart | pie_chart | |
heatmap | heatmap_chart |
Skip: text, row, news, dashlist, alertlist, annolist, logs, nodeGraph, traces, flamegraph, canvas, geomap
Grafana barchart → category bar chart (no {{time}}); timeseries with drawStyle bars → time-series bar chart. Configure per the chart-generation skill's Bar Chart Configuration (category bars need x_axis_type: "category" + time_column: "series").
| Grafana unit | Better Stack unit | Notes |
|---|---|---|
bytes, decbytes | B_si | |
bits, decbits | bps | Only if rate; otherwise B_si |
Bps (bytes/sec) | B_si | |
bps (bits/sec) | bps | PromQL * 8 for bytes→bits |
s | s | |
ms | ms | |
us, µs | μs | |
ns | ns | |
percent | percent | Grafana percent = 0–100 input; Better Stack percent = 0–1 input. MUST divide by 100 |
percentunit | percent | Grafana percentunit = 0–1 input — maps directly, no conversion |
short | shortened | |
none | shortened | |
ops, iops | e/s | |
reqps | rps | |
locale | shortened | |
celsius | (custom) | Last resort — use unit: "none", add "°C" in title |
hertz | e/s |
Always prefer predefined units. The table above covers nearly all Grafana units. Never set custom_unit: true when a predefined Better Stack unit exists (e.g., use unit: "B_si", not unit: "bytes" with custom_unit: true; e/s, not /s; B_si/s, not bytes/sec). Custom units lack auto-scaling and produce worse formatting. Only use custom_unit: true, which shows unit as a literal suffix, for truly exotic units like °C where no predefined equivalent exists.
CRITICAL: Grafana percent vs percentunit:
percent → values are 0–100. Better Stack percent expects 0–1. You MUST divide by 100 in the query or values will display as 4000% instead of 40%.percentunit → values are 0–1. Maps directly to Better Stack percent. No conversion needed.Default unit for counts: Connection counts, query counts, transaction counts, and similar integer metrics should use unit: "shortened" for auto-scaling (1.5K, 2.3M). Do NOT leave unit unset on count metrics.
Follow the dashboard-builder skill's naming rules (sentence case, no abbreviations, no units or parentheses in titles). Grafana templates often use "Avg"/"Max"/"Config" and parenthetical units ("Output events bytes rate (bytes/sec)") — always expand/strip at chart-create time.
Read references/chart-patterns.md (in this skill's directory) before you write a panel's query: it has worked PromQL and CloudWatch → ClickHouse translations for line charts (counter rates, sums by label, arithmetic, composite series, bytes to bits) and for gauge and number charts (irate, instant values, uptime, static numbers, Grafana Stat reduceOptions).
height: 6 (ignore Grafana heights)type: "row" panels → section: "Row Title"Then apply the dashboard-layout skill's rules and planning process (rows sum to 12, prefer 3 per row, no full-width charts, no orphan rows, number charts ≤ w:4).
For series_column, value_columns, legend, section organization, pie charts, stacking, and treat_missing_values — see dashboard-builder skill.
Import-specific: Latency — always check the source metric's native unit FIRST with query before applying any conversion. Some metrics are in seconds (→ * 1000, unit: "ms"), others are already in milliseconds. Don't assume.
Macros in nested queries — {{time}}, label(), {{source}} only work directly against {{source}}, not in outer queries. See dashboard-builder skill.
Nested aggregates forbidden → Use CTEs for sum by (label)(rate(...)) patterns.
Uptime/timestamps → Use maxMerge(value_max) not avgMerge(value_avg).
Gauge/number charts need series label → Always include 'Label' AS series. Number charts only display the chart title, so make it descriptive.
Always validate queries — Run query before creating charts. A broken chart wastes more time than validating upfront.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Other plugins' skills for the same job
npx claudepluginhub betterstackhq/claude-plugin --plugin betterstack17 skills in this plugin
/chart-alertsGuide for creating and managing Better Stack chart alerts. Load when asked to set up alerting, create alerts on charts, or configure monitoring thresholds./chart-generationComplete reference for chart types, units, and settings on Better Stack dashboards. Load right before creating charts - after the queries are built with the query skills./chart-stylingBetter Stack chart styling and advanced settings reference - series colors and order, number chart coloring thresholds, heatmap color categories, gauge bounds, y-axis tuning, custom units, and the per-key settings table with cross-setting gotchas. Load when configuring how a chart looks beyond defaults, or when unsure which settings key applies to a chart type./collector-queriesProven metrics queries for Better Stack Collector sources (the source tool's Platform "Collector") - per-host node_* metrics, per-container and per-service container_resources_*, requests and errors by destination, TCP health, and the container-level saturation checks that host averages hide. Load after metrics-query when the source platform is Collector, for health checks, resource questions and service dashboards./connect-betterstackConnect the Better Stack MCP server and check that it works. Use when the user installs the Better Stack plugin or asks to set it up, when a Better Stack request comes in but no Better Stack tools (such as `incidents`, `monitors`, `query`, `documentation`) are available, or when a Better Stack tool fails with "unauthorized", 401 or "needs authentication". Tells the user exactly how to connect in the app they are using (ChatGPT, Codex, Cursor, Antigravity, Claude Code, Claude chat and Cowork, Claude Tag in Slack). Once connected, suggests what to set up next from what the account has, such as Claude investigating every new incident or fixing errors on a schedule. Also use when the user asks what Better Stack can do for them./dashboard-builderGuide for building Better Stack dashboards. Load when asked to create a dashboard or add multiple charts in Better Stack.