Export Prometheus data to CSV
How to turn Prometheus query results into CSV or TSV, what the conversion changes, and when a CSV export suits your purpose.
Prometheus has no built-in CSV export. Getting metrics into a spreadsheet or another tool means taking JSON query results, or raw data blocks, and flattening them into rows and columns. This review explains what that conversion changes, which routes are available, and where CSV helps or gets in the way. It draws on documented Prometheus behavior and general data-handling principles. It does not include tool benchmarks or test results, because none were available.
Is a CSV export the right choice?
CSV works well when you need a fixed snapshot of a few series for a spreadsheet, a report, or a tool that cannot query Prometheus directly. Its main benefit is portability: almost any analysis tool can read delimited text.
The main tradeoff is structure. Prometheus identifies each series by a flexible set of labels. A CSV file forces those labels into fixed columns or a single packed string. It also drops metric metadata such as type and help text, and it freezes the data at the moment of export.
Other formats are better in some cases:
- Keep the PromQL query text itself if others need current data. They can re-run the query instead of passing around a stale file.
- Keep the native JSON response if another program will consume it. JSON preserves label sets exactly and avoids CSV quoting problems.
- Use a dashboard or the Prometheus query interface for exploration. Use CSV only when the analysis has to happen elsewhere.
What the conversion actually changes
This is a structural change of format. It does not change individual characters or how text looks. The Prometheus HTTP API returns JSON in which each series has a metric object (its labels) and one or more samples. Range queries return a matrix, where each series has a list of values. Instant queries return a vector, where each series has a single value. Each sample is a pair: a Unix timestamp in seconds, which may include a fractional part, and the sample value encoded as a string.
Converting to CSV or TSV makes the following changes to the stored data:
- Nested label objects become columns or a delimited text field. Series with different label sets do not fit one header row cleanly.
- Sample values stay text in the file, so the importing application decides how to read them. Special values such as NaN, +Inf and -Inf may be treated as text, errors or blanks depending on the destination.
- Timestamps stay as epoch seconds unless you convert them. A conversion step can introduce time zone mistakes.
- A range query evaluates the expression at each step. Its output is therefore resampled data, not the raw samples stored in Prometheus. To get raw samples, run an instant query with a range selector, such as a metric name followed by [1h].
- Counters exported as-is show cumulative totals, including resets. Exporting rate() or increase() is often more useful if the reader cares about change over time.
Common export routes
| Route | What you get | Main tradeoff |
| Grafana panel inspector (Data tab, CSV download) | The data as the panel shows it, optionally with panel transformations applied | Results reflect the panel's interval and transformations, which may differ from the underlying samples |
| HTTP API query plus a script or jq | Exactly the series and time range you request | You must handle flattening, quoting, headers and range limits yourself |
| promtool tsdb dump | Raw series data read directly from TSDB blocks | Requires access to the data directory; the output is not CSV and needs post-processing |
A scripted example with the HTTP API and jq
The following example requests a range query and saves the JSON. Set PROMETHEUS_URL to your server's base address and adjust the query, time range and step.
curl -s "$PROMETHEUS_URL/api/v1/query_range" \
--data-urlencode 'query=rate(http_requests_total[5m])' \
--data-urlencode 'start=2026-10-30T00:00:00Z' \
--data-urlencode 'end=2026-10-31T00:00:00Z' \
--data-urlencode 'step=60s' > result.json
The next command flattens the JSON into long format: one row per sample, with each series' labels packed into a single column. Long format avoids the problem of series having different label sets. Replace @csv with @tsv for tab-separated output. For an instant query, use .value in place of .values[].
jq -r '
["series","timestamp","value"],
(.data.result[]
| (.metric | to_entries | map("\(.key)=\(.value)") | join(";")) as $s
| .values[] | [$s, .[0], .[1]])
| @csv' result.json > result.csv
Several limits apply to the API route:
- Prometheus rejects range queries that would return more than 11,000 points per series. For long periods, use a larger step or split the export into several requests.
- Queries over many series can be slow and can strain the server. Narrow the query with label matchers before exporting.
- The API does not reach beyond the server's retention period. Older data has to come from long-term storage, if you have it configured.
Will the file stay readable and usable after sharing?
CSV and TSV are plain text, so they copy, diff and version cleanly. Most of the risk comes from how the receiving application interprets the file:
- Quoting: label values can contain commas, quotes or tabs. Use a proper encoder, such as jq's @csv or @tsv or a CSV library, rather than joining strings by hand.
- Locale: in locales that use a comma as the decimal separator, spreadsheet applications may misread dot decimals or split columns incorrectly. Explicitly importing the file with the delimiter and number format set is safer than opening it by double-click.
- Formula injection: a label value beginning with =, +, - or @ may be evaluated as a formula when the file is opened in a spreadsheet. Sanitize such values if the file will be shared outside your team.
- Pasting: whether pasted CSV or TSV lands in separate cells depends on the destination application. Check your target tool rather than assuming one result applies everywhere.
- Accessibility: a long-format table with a clear header row is generally easier to navigate with a screen reader than a wide table with hundreds of label-derived column names. No assistive-technology testing was available for this review, so check with the tools your readers use.
Gaps in this review
This review did not compare third-party export tools, measure export performance, or examine any tool's privacy or data-retention practices. If you consider a hosted converter, check its documentation before uploading metrics. Label values can reveal hostnames, customer identifiers or internal service names.