Example of using multiple labels with client_java:
// Declaration for job counts with labels for status=success|fail and 
type=PDF|HTML|TEXT|RTF"
private static final Counter jobTotals = Counter.build() ... 
labelNames("status", "type") ... ;

// statsData contains the data
String [] statsData = statsLine.split("\\t");

if (statsData[0].contains("true")) {
  jobTotals.labels("success", statsData[1]).inc();
} else {
  // When the job fails there is no valid job type
  jobTotals.labels("fail", "").inc();
}

On Tuesday, February 15, 2022 at 12:23:39 PM UTC William Walsh wrote:

> I have coded a Prometheus client_java collector/exporter for a proprietary 
> server that counts the number of its jobs and observes elapsed times and 
> data lengths. This works fine. But, the requirement now is to expand on 
> that, adding labels to the count of jobs; notionally:
>
> type="PDF|HTML|TEXT|RTF"
> status="fail|success"
>
> Unfortunately, the labels example in 
> https://github.com/prometheus/client_java#labels isn't enough for me to 
> bridge my lack of Prometheus understanding. Is that example indicating that 
> by coding labelNames("method") in the Counter declaration and then 
> calling requests.labels("get").inc() that the get method count is being 
> incremented? If so, that sounds like Prometheus dynamically use that 
> method label to store the count for get or post or any other method name 
> passed, is that correct?
>
> In my experience, as soon as I add labelNames to a Counter declaration 
> like this:
> private static final Counter jobsSuccessful = 
> Counter.build().namespace("curam_xmlserver").name("job_successes").help("Successful
>  
> xmlserver jobs").labelNames("type").register(); 
>
> it breaks the Counter. That is, without labelNames coded I get this 
> output (no activity):
> curl -s http://localhost:8080/metrics | grep job_successes 
> # HELP curam_xmlserver_job_successes_total Successful xmlserver jobs 
> # TYPE curam_xmlserver_job_successes_total counter 
> curam_xmlserver_job_successes_total 0.0 
>
> And after adding labelNames there is no longer the zero counter 
> (curam_xmlserver_job_successes_total 
> 0.0) and the collector doesn't count or observe anything.
>
> Is this a bug that I should create an issue for, or what am I doing wrong, 
> please? This is with release 0.15.0.
>
> Thank you, 
> www
>

-- 
You received this message because you are subscribed to the Google Groups 
"Prometheus Developers" 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-developers/e09be4b7-fc29-4aa3-bfd1-acdf2ce2a238n%40googlegroups.com.

Reply via email to