Expose CSV data as Prometheus metrics
How converting CSV or TSV files into Prometheus metrics changes your data, where meaning can be lost, and when to keep the plain CSV instead.
Turning a CSV file into Prometheus metrics means rewriting its rows and columns into the line-based text exposition format that Prometheus scrapes over HTTP. You can do this with a small custom exporter, with node_exporter's textfile collector, or with a ready-made CSV exporter project. The transformation works the same way in each case, and it loses information in specific, predictable ways. This review covers what changes, where meaning can slip, and when the CSV should stay as it is.
Is converting CSV to Prometheus metrics a good fit?
The conversion suits CSV files that hold numeric measurements, are refreshed regularly, and need to be graphed, alerted on, or compared with other metrics. The main benefit is that the data joins your existing monitoring: PromQL queries, alerting rules and dashboards work on it without a separate storage system. The decisive tradeoff is that Prometheus stores only floating-point values tied to a fixed set of labels. Text columns, exact decimals and the row as a complete record do not survive intact. Anything that is not a number must become a label or be dropped.
Plain CSV, a database, or a log tool is the better choice when:
- The data is mostly text or identifiers rather than measurements.
- A column has many unique values, such as user IDs, order numbers or free text, that would have to become labels.
- Exact decimal values matter, as with currency. Samples are stored as 64-bit floats.
- The file is a one-off or historical export, not a value that is current whenever Prometheus scrapes it.
- Readers need the original rows for audit or reconciliation.
What the transformation actually changes
This is a structural conversion of the stored data. It is not a visual or character-level effect: nothing is reversed, mirrored or restyled. In a typical mapping, each numeric column becomes a metric name, the remaining columns become labels, and each row produces one sample per metric. The output is a new text document whose characters and meaning differ from the source.
region,service,requests,error_rate
us-east,checkout,1520,0.012
us-west,checkout,980,0.020
# HELP csv_requests Requests column from the CSV file.
# TYPE csv_requests gauge
csv_requests{region="us-east",service="checkout"} 1520
csv_requests{region="us-west",service="checkout"} 980
# HELP csv_error_rate Error rate column from the CSV file.
# TYPE csv_error_rate gauge
csv_error_rate{region="us-east",service="checkout"} 0.012
csv_error_rate{region="us-west",service="checkout"} 0.02
This mapping was written for this article as an illustration. It is not output captured from a specific tool. The region and service columns become labels, and each numeric column becomes its own metric family. The value 0.020 appears as 0.02 because it is parsed as a number, and the trailing zero means nothing as a float. Both columns are typed as gauges because they are snapshots. A column should be a counter only if its value never decreases, and counter names conventionally end in _total.
Where meaning can be lost or distorted
- Header names: In the classic format, metric names may contain only letters, digits, underscores and colons, and cannot start with a digit. Label names may contain only letters, digits and underscores, and names starting with two underscores are reserved. Headers such as "Error Rate (%)" or "2024 total" therefore have to be rewritten, and that mapping should be documented. Recent Prometheus releases accept a quoted UTF-8 name syntax, but not every client library, exporter or downstream tool supports it, so sanitized names are the safer default.
- Number parsing: Every value must parse as a float. Thousands separators, currency symbols, percent signs and comma decimal separators will fail or be misread unless the converter cleans them explicitly. Empty cells have no natural equivalent. Omitting the sample is usually more honest than writing 0.
- Label values: These can hold any UTF-8 text, but backslashes, double quotes and line breaks must be escaped as \, " and \n.
- CSV parsing: Quoted fields can contain commas, quotes and even line breaks, so a converter that simply splits each line on commas will break on such files. TSV avoids most of these cases, but tabs inside values still need a rule. A byte-order mark at the start of the file can end up attached to the first header name.
- Units: Prometheus conventions favor base units such as seconds and bytes, and ratios from 0 to 1 rather than percentages. You have to decide whether to rescale values or name the unit in the metric.
- Timestamps: A time column in the CSV does not automatically become the sample time. Exposed samples normally take the scrape time, and attaching explicit old timestamps can get samples rejected. For historical data, the documented route is backfilling with promtool from OpenMetrics input.
- Duplicate rows: Two rows with identical label values for the same metric produce a duplicate series, which is invalid. The converter must either aggregate those rows or add a label that tells them apart.
Cardinality needs separate attention. Every unique combination of label values is its own time series, so a column with thousands of distinct values multiplies the series count and the Prometheus server's memory use. Turn a column into a label only when its values form a small, stable set. Descriptive text attributes that belong together can use the info-metric pattern instead: a single gauge with the value 1 that carries the attributes as labels, kept separate from the main measurements.
Choosing how to expose the data
| Approach | How it works | Fits when |
| Custom exporter built with a client library | A small HTTP service reads the CSV and serves metrics on each scrape | The file changes often and you want full control over parsing and naming |
| node_exporter textfile collector | A script converts the CSV into a .prom file in the collector's directory, and node_exporter serves it | node_exporter already runs on the host and a scheduled job produces the CSV |
| Pushgateway | A batch job pushes converted metrics to the gateway, which Prometheus scrapes | Short-lived jobs finish before Prometheus could scrape them; not for general CSV publishing |
| promtool backfill | Historical rows are converted to OpenMetrics and written into TSDB blocks | You are importing past data with its original timestamps |
With the textfile collector, write to a temporary file and rename it into place so the collector never reads a half-written file. With the Pushgateway, pushed metrics stay until they are deleted, so outdated values can linger after the source CSV changes. Third-party CSV exporter projects also exist, but none was evaluated for this review. Before relying on one, check how it handles quoted fields, metric types, name sanitizing and file refresh.
Will the output stay readable and usable after copying or sharing?
Exposition output is ordinary text with no lookalike characters or hidden direction marks, so it copies cleanly in principle. The practical risks are mechanical. The format is line-oriented, so the text can become unparseable if an editor or chat tool rewraps long lines, swaps straight quotes for curly typographic quotes, or changes line endings. Windows-style line endings carried over from a CSV can cause parse errors or stray characters, because a plain line feed is the expected separator. When you share snippets, put them in a code block and check them with promtool check metrics, which validates the format and flags convention problems.
Assistive technology reads the result in its stored order, because the output is plain text and nothing is reordered for display. However, dense lines of braces, quotes and label pairs are hard to follow by ear or at a glance, and the original column layout is gone. Human readers are better served by the CSV or a rendered table, while the metrics serve queries and dashboards. Search is affected too: renamed headers become PromQL identifiers, so anyone searching for an original column name will not find it. No screen reader or specific sharing destination was tested for this review.
Keep the source CSV alongside the metrics whenever the data needs auditing, exact values or human review. Document the header-to-metric mapping, any unit conversions, and which columns were dropped.
Evidence gaps
No specific CSV exporter, version or performance data was supplied, and no tool was tested for this review. The format rules described here come from Prometheus's documented text exposition format and naming conventions. Statements about how editors, chat apps or assistive technologies treat the output are general cautions, not test results. Verify the behavior against the Prometheus version and tools you actually run.