https://github.com/hansmi/prometheus-textformat-merge
Combine multiple Prometheus textformat inputs into one.
https://github.com/hansmi/prometheus-textformat-merge
combine merge node-exporter plaintext prometheus prometheus-exporter textformat
Last synced: 11 months ago
JSON representation
Combine multiple Prometheus textformat inputs into one.
- Host: GitHub
- URL: https://github.com/hansmi/prometheus-textformat-merge
- Owner: hansmi
- License: bsd-3-clause
- Created: 2021-08-19T22:31:54.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2025-07-01T18:48:01.000Z (11 months ago)
- Last Synced: 2025-07-01T19:39:19.824Z (11 months ago)
- Topics: combine, merge, node-exporter, plaintext, prometheus, prometheus-exporter, textformat
- Language: Go
- Homepage:
- Size: 80.1 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Utility to merge Prometheus textformat files
[][releases]
[](https://github.com/hansmi/prometheus-textformat-merge/actions/workflows/release.yaml)
[](https://github.com/hansmi/prometheus-textformat-merge/actions/workflows/ci.yaml)
[](https://pkg.go.dev/github.com/hansmi/prometheus-textformat-merge)
`prometheus-textformat-merge` is a command line program to combine multiple
[Prometheus `textformat`][prom_textformat] inputs.
Prometheus' [node exporter][node_exporter_doc] has a `textfile` collector
reading textformat files in a predetermined directory. When multiple files
contain the same metrics, albeit with different labels, collection fails
(see also [prometheus/node\_exporter#1885][node_exporter_issue1885]).
There are other use cases where combining multiple metrics sources is useful,
e.g. after downloading them from a collector using [cURL][curl].
The following inputs are supported:
* Regular files using the Prometheus text format
* Standard input
* Directories with multiple files with the `--dirs` flag (enumerates `*.prom`
in the given directories by default)
## Example usage
```bash
$ cat >first.prom <<'EOF'
# HELP node_disk_io_time_seconds_total Total seconds spent doing I/Os.
# TYPE node_disk_io_time_seconds_total counter
node_disk_io_time_seconds_total{device="dm-0"} 581.412
node_disk_io_time_seconds_total{device="dm-1"} 483.348
EOF
$ cat >second.prom <<'EOF'
# HELP node_load5 5m load average.
# TYPE node_load5 gauge
node_load5 0.42
EOF
$ prometheus-textformat-merge first.prom second.prom
# HELP node_disk_io_time_seconds_total Total seconds spent doing I/Os.
# TYPE node_disk_io_time_seconds_total counter
node_disk_io_time_seconds_total{device="dm-0"} 581.412
node_disk_io_time_seconds_total{device="dm-1"} 483.348
# HELP node_load5 5m load average.
# TYPE node_load5 gauge
node_load5 0.42
```
Reading from standard input is also supported with the `-` placeholder:
```bash
$ prometheus-textformat-merge --output all.prom first.prom - <<'EOF'
# TYPE node_disk_io_time_seconds_total counter
node_disk_io_time_seconds_total{device="dm-4"} 104.156
node_disk_io_time_seconds_total{device="dm-5"} 0.372
EOF
$ cat all.prom
# HELP node_disk_io_time_seconds_total Total seconds spent doing I/Os.
# TYPE node_disk_io_time_seconds_total counter
node_disk_io_time_seconds_total{device="dm-0"} 581.412
node_disk_io_time_seconds_total{device="dm-1"} 483.348
node_disk_io_time_seconds_total{device="dm-4"} 104.156
node_disk_io_time_seconds_total{device="dm-5"} 0.372
```
Note how the same metric was combined from multiple sources and written to
a file. See the `--help` output for available flags.
## Installation
Pre-built binaries are provided for all [releases][releases]:
* Binary archives (`.tar.gz`)
* Debian/Ubuntu (`.deb`)
* RHEL/Fedora (`.rpm`)
* Microsoft Windows (`*.zip`)
With the source being available it's also possible to produce custom builds
directly using [Go][golang] or [GoReleaser][goreleaser].
[node_exporter_doc]: https://prometheus.io/docs/guides/node-exporter/
[node_exporter_issue1885]: https://github.com/prometheus/node_exporter/issues/1885
[prom_textformat]: https://prometheus.io/docs/instrumenting/exposition_formats/
[curl]: https://curl.se/
[releases]: https://github.com/hansmi/prometheus-textformat-merge/releases/latest
[golang]: https://golang.org/
[goreleaser]: https://goreleaser.com/