Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ public class TextFormat {
*/
public final static String CONTENT_TYPE_OPENMETRICS_100 = "application/openmetrics-text; version=1.0.0; charset=utf-8";

/**
* A property to be passed via the command line (-D...="true") to allow old-style pre OpenMetrics counter names,
* in other words invalid counter names (not ending with the suffix "_total")
*
* @since 0.10.1
*/
private final static String ALLOW_INVALID_COUNTER_NAMES = "io.prometheus.allowInvalidCounterNames";

/**
* Return the content type that should be used for a given Accept HTTP header.
*
Expand Down Expand Up @@ -64,6 +72,10 @@ public static void writeFormat(String contentType, Writer writer, Enumeration<Co
* Write out the text version 0.0.4 of the given MetricFamilySamples.
*/
public static void write004(Writer writer, Enumeration<Collector.MetricFamilySamples> mfs) throws IOException {
// true in case ALLOW_INVALID_COUNTER_NAMES property is present and is true (ignoring case),
// false in all other cases (including missing value)
boolean allowInvalidCounterNames
= Boolean.parseBoolean(System.getProperties().getProperty(ALLOW_INVALID_COUNTER_NAMES));
Map<String, Collector.MetricFamilySamples> omFamilies = new TreeMap<String, Collector.MetricFamilySamples>();
/* See http://prometheus.io/docs/instrumenting/exposition_formats/
* for the output format specification. */
Expand All @@ -72,7 +84,7 @@ public static void write004(Writer writer, Enumeration<Collector.MetricFamilySam
String name = metricFamilySamples.name;
writer.write("# HELP ");
writer.write(name);
if (metricFamilySamples.type == Collector.Type.COUNTER) {
if (metricFamilySamples.type == Collector.Type.COUNTER && !allowInvalidCounterNames) {
writer.write("_total");
}
if (metricFamilySamples.type == Collector.Type.INFO) {
Expand All @@ -84,7 +96,7 @@ public static void write004(Writer writer, Enumeration<Collector.MetricFamilySam

writer.write("# TYPE ");
writer.write(name);
if (metricFamilySamples.type == Collector.Type.COUNTER) {
if (metricFamilySamples.type == Collector.Type.COUNTER && !allowInvalidCounterNames) {
writer.write("_total");
}
if (metricFamilySamples.type == Collector.Type.INFO) {
Expand Down