On Wednesday, April 8, 2020 at 1:58:01 PM UTC, Brian Brazil wrote:
>
> On Wed, 8 Apr 2020 at 13:40, Vidur <[email protected] <javascript:>> 
> wrote:
>
>> Hi
>> I'm using prometheus simple client for collecting metrics in my system 
>> via a spring boot application
>>
>> void insertBatchJob(String request , String[] labelNames, String[] 
>> labelValues,String counter) throws Exception {
>>         CollectorRegistry registry = new CollectorRegistry();
>>         Gauge inprogressRequests ;
>>         if( !gaugeRegiseryMap.containsKey(request) ) {
>>             inprogressRequests = Gauge.build()
>>                     
>> .name(request).labelNames(labelNames).help(request).register();
>>
>> You shouldn't be registering metrics to the default registry in a typical 
> method. Did you mean to register it to the custom registry you just 
> instantiated?
>


* My use case is something which sets gauge value for a same request in 
fixed interval, so is there no need to register the gauge ?And Gauge are 
created real time with different request values , so i cannot make them 
static.*

>
>>             gaugeRegiseryMap.put(request,inprogressRequests);
>>
>>
> Nor should you need to track what metrics exist, see 
> https://www.robustperception.io/label-lookups-and-the-child
>  
>
>>
>>         }else{
>>             inprogressRequests = gaugeRegiseryMap.get(request);
>>         }
>>         try {
>>             inprogressRequests.labels(labelValues[labelValues.length-4],
>>                     labelValues[labelValues.length-2],
>>                     labelValues[labelValues.length-3],
>>                     
>> labelValues[labelValues.length-1]).set(Double.parseDouble(counter));
>>             registry.register(inprogressRequests);
>>         } finally {
>>
>>
> You shouldn't need a try-finally for this, it should never fail given the 
> above code.
>
> I suspect what you're looking for here is a custom collector by 
> subclassing Collector.
>
> Brian
>  
>
>>
>>             PushGateway pg = new PushGateway("127.0.0.1:9091");
>>             pg.pushAdd(registry, request);
>>         }
>>     }
>>
>>
>> the following code is working ,
>> but when i change inprogressRequests.labels() when i pass the array 
>> containing label values
>> i.e.
>>
>>  void insertBatchJob(String request , String[] labelNames, String[] 
>> labelValues,String counter) throws Exception {
>>         CollectorRegistry registry = new CollectorRegistry();
>>         Gauge inprogressRequests ;
>>         if( !gaugeRegiseryMap.containsKey(request) ) {
>>             inprogressRequests = Gauge.build()
>>                     
>> .name(request).labelNames(labelNames).help(request).register();
>>             gaugeRegiseryMap.put(request,inprogressRequests);
>>         }else{
>>             inprogressRequests = gaugeRegiseryMap.get(request);
>>         }
>>         try {
>>             
>> inprogressRequests..labels(labelValues).set(Double.parseDouble(counter));
>>
>> *Did you check this part where I'm trying to set label values like this ? 
why is this not working but the above one is?* 

>
>>             registry.register(inprogressRequests);
>>         } finally {
>>             PushGateway pg = new PushGateway("127.0.0.1:9091");
>>             pg.pushAdd(registry, request);
>>         }
>>     }
>>
>> the same is giving me errror -
>> Response code from http://127.0.0.1:9091/metrics/job/loop6_2 was 400, 
>> response body: pushed metrics are invalid or inconsistent with existing 
>> metrics: collected metric .
>>
>>
>>
>> This is my first time using prometheus , it will be good if someone can 
>> share light on this.
>>
>> -- 
>> 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] <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/prometheus-users/11440241-e4f6-40a3-9698-e65498d3db3a%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/prometheus-users/11440241-e4f6-40a3-9698-e65498d3db3a%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> -- 
> Brian Brazil
> www.robustperception.io
>

-- 
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/6a132978-c86e-4370-9dc5-51495e2c7956%40googlegroups.com.

Reply via email to