I am exposing two counter metrics from my spring boot application. The metrics are getting generated and the counters increase by 1 when the requests succeed. I am facing 2 issues - 1) The name of the counter is getting appended by "_total" even though I did not add that and I don't want it to be added, 2) The last label ends with an open ','. I want to remove this last ','. Here is my code:
public class PrometheusUtility {
private PrometheusUtility(){
}
static CollectorRegistry registry = CollectorRegistry.defaultRegistry;
static final Counter counter = Counter.build().name("http_request").help("help").labelNames("method","status","api", "component").register(registry);
static final Counter dsCounter = Counter.build().name("http_downstream_request").help("Records the downstream request count").labelNames("method","status","api", "component", "downstream").register(registry);
public static void incrementCounter(String method, String status, String apiName, String component){
counter.labels(method,status,apiName,component).inc();
}
public static void incrementDownstreamCounter(String method, String status, String apiName, String component, String downstream){
dsCounter.labels(method,status,apiName,component, downstream).inc();
}
}
I am calling these functions from the business class:
PrometheusUtility.incrementCounter("Post", String.valueOf(HttpStatus.SC_OK), "newMail", "mx");
PrometheusUtility.incrementDownstreamCounter("Post", String.valueOf(HttpStatus.SC_OK), "newMail", "mx", "mwi");
The pom.xml has this dependency added
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_spring_boot</artifactId>
<version>0.16.0</version>
</dependency>
The output I am checking in the browser where my application is up and running (not in Prometheus):
http_request_total{method="Post",status="200",api="newMail",component="mx",} 1.0
http_downstream_request_total{method="Post",status="200",api="newMail",component="mx",downstream="mwi",} 1.0
Issue:
Both metric names are getting an additional "_total" appended to it. I don't want this to be added by default. It should be same as the name I have put in the Utility class.
Both metrics have an open ',' or comma at the end. Ideally this should not be there. A metric does not have an open comma at the end. Not sure why it's adding this comma. I have specified the correct number of labels at the creation time of the counter and populating the labels correctly for incrementing. Not sure where this comma is coming from.
Please let me know how I could fix these issues.