On Friday, April 10, 2020 at 10:19:38 AM UTC, Brian Brazil wrote: > > On Fri, 10 Apr 2020 at 10:27, Vidur <[email protected] <javascript:>> > wrote: > >> >> >> On Friday, April 10, 2020 at 7:55:54 AM UTC, Brian Brazil wrote: >>> >>> On Fri, 10 Apr 2020 at 07:10, Vidur <[email protected]> wrote: >>> >>>> >>>> >>>> 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]> 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 ?* >>>> >>> >>> In that case you're doing normal direct instrumentation, so you >>> shouldn't be using the pushgateway. >>> >> >> But all different metrics have different interval which can be changed , >> thats why I'm using pushgateway .Otherwise i have to store those states >> somewhere else and create endpoint in my system for prometheus to pull. >> > > Metrics don't have an interval, events do. The frequency prometheus > samples at is independent of when metrics are updated. > > >> >>> >>>> *And Gauge are created real time with different request values , so i >>>> cannot make them static.* >>>> >>> >>> Metric names in direct instrumentation should never be procedurally >>> generated. Most likely you should be using a label here, not a metric name. >>> >> >> Are you suggessting me to use labels to distinguish between different >> type of metric. >> could you share more info on direct instrumentation & other types. >> > > Use a normal static gauge and expose it out over http. >
But there are dynamic labels for every metric type , so i think keeping a normal static gauge wont solve this problem. > > Brian > > >> >>> Brian >>> >>> >>>>>> 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]. >>>>>> 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 >>>> >>>> <https://groups.google.com/d/msgid/prometheus-users/6a132978-c86e-4370-9dc5-51495e2c7956%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] <javascript:>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/prometheus-users/44269654-2d97-484f-bbb4-dd0096e602cc%40googlegroups.com >> >> <https://groups.google.com/d/msgid/prometheus-users/44269654-2d97-484f-bbb4-dd0096e602cc%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/bea6ddd9-3468-45dc-a912-34572121b86b%40googlegroups.com.

