It is a requirement that counters end with _total which is likely why it is being added for you.
On 14 December 2022 17:50:32 GMT, "[email protected]" <[email protected]> wrote: >Hi, > >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: > > 1. > > 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. > 2. > > 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. > >-- >You received this message because you are subscribed to the Google Groups >"Prometheus Users" group. >To unsubscribe from this group and stop receiving emails from it, send an >email to [email protected]. >To view this discussion on the web visit >https://groups.google.com/d/msgid/prometheus-users/469b7f35-d6ab-4af0-903f-d2821a5f6b60n%40googlegroups.com. -- Sent from my Android device with K-9 Mail. Please excuse my brevity. -- You received this message because you are subscribed to the Google Groups "Prometheus Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/A356CAF0-B077-4B38-B35F-2DE1AD85006E%40Jahingo.com.

