promtoolfmt is made for linting and formating prometheus metrics in text-based format.
promtoolfmt remove any duplicate metric/comment, performs a linting pass on metrics and format them using expfmt.
Usage of promtoolfmt:
-silent
Silent or quiet mode.
-version
Show version.
$ cat testdata/metrics-test.prom | promtoolfmt
# HELP test_metric_info A metric with a constant '1' value labeled by testlabel.
# TYPE test_metric_info gauge
test_metric_info{testlabel="testvalue1"} 1
test_metric_info{testlabel="testvalue2"} 1
# HELP test_metric_duplicate_info A metric with a constant '1' value labeled by testlabel.
# TYPE test_metric_duplicate_info gauge
test_metric_duplicate_info{testlabel="testvalue1"} 1
# HELP test_metric_with_spaces_info A metric with a constant '1' value labeled by testlabel.
# TYPE test_metric_with_spaces_info gauge
test_metric_with_spaces_info{testlabel="testvalue1",testanotherlabel="testanothervalue1"} 1
test_metric_with_spaces_info{testlabel="testvalue2",testanotherlabel="testanothervalue2"} 1
Use this mode to get exit code only (suppress any output/error)
$ cat testdata/metrics-test.prom | promtoolfmt -silent
$ cat testdata/invalid-metrics-no-help-text.prom | promtoolfmt
test_metric_info no help text
$ cat testdata/invalid-metrics-float-value.prom | promtoolfmt
error while linting: text format parsing error in line 4: expected float as value, got "1m"