Skip to content

hansmi/prometheus-textformat-merge

Repository files navigation

Utility to merge Prometheus textformat files

Latest release Release workflow CI workflow Go reference

prometheus-textformat-merge is a command line program to combine multiple Prometheus textformat inputs.

Prometheus' node exporter 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).

There are other use cases where combining multiple metrics sources is useful, e.g. after downloading them from a collector using 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

$ 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:

$ 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:

  • 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 or GoReleaser.

About

Combine multiple Prometheus textformat inputs into one.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors 2

  •  
  •