Hi Chris,

Thank you for your reply. Kindly see comments highlighted in yellow. Please 
advice me the changes required inside the function.

Appreciate your help.

from prometheus_client import start_http_server, Gauge
import random
from random import randrange

#Latency_Time = Gauge('consumer_gauge_seconds', 'Time spent in consuming 
message') # This code works without label

Latency_Time = Gauge('consumer_gauge_seconds', 'Time spent in consuming 
message', labelnames=['partition'])
# Latency_Time.labels(1).set(2300) # Thanks. It works here.


@Latency_Time.track_inprogress()
def latency_request(partition, latency):
    Latency_Time.labels(partition).set(latency) # Same code doesn't works 
here. Kindly help

#   Latency_Time.labels('partition', '1').set(latency). # I know there is 
something wrong here.. I'm not able to figure out what !
# # Latency_Time.set(latency) # This code works without label

if __name__ == '__main__':
    start_http_server(17500)
    while True:
        latency_request(random.randrange(1, 12), random.randrange(1900, 
2150))


Error ::

/Users/rahulsinha/anaconda3/envs/envpy37/bin/python 
/Users/rahulsinha/PycharmProjects/pythonProject/venv/prom_py1.py
Traceback (most recent call last):
  File "/Users/rahulsinha/PycharmProjects/pythonProject/venv/prom_py1.py", 
line 10, in <module>
    @Latency_Time.track_inprogress()
  File 
"/Users/rahulsinha/anaconda3/envs/envpy37/lib/python3.7/site-packages/prometheus_client/metrics.py",
 
line 377, in track_inprogress
    self._raise_if_not_observable()
  File 
"/Users/rahulsinha/anaconda3/envs/envpy37/lib/python3.7/site-packages/prometheus_client/metrics.py",
 
line 66, in _raise_if_not_observable
    raise ValueError('%s metric is missing label values' % str(self._type))
ValueError: gauge metric is missing label values




Thank You.

Regards,
Rahul Sinha

On Saturday, 5 June 2021 at 03:33:08 UTC+8 [email protected] wrote:

> Hello,
>
> Which labelname a labelvalue is assigned to is based on the order of
> the arguments, so you do not need to re-specify 'partition' when
> setting the labels. Just Latency_Time.labels('1').set(latency) should
> work for you.
>
> Cheers,
>
> Chris
>
> On Wed, Jun 2, 2021 at 4:59 PM Rahul Sinha <[email protected]> wrote:
> >
> > Code ::
> >
> > from prometheus_client import start_http_server, Gauge
> > import random
> > from random import randrange
> >
> > #Latency_Time = Gauge('consumer_gauge_seconds', 'Time spent in consuming 
> message') # This code works without label
> > Latency_Time = Gauge('consumer_gauge_seconds', 'Time spent in consuming 
> message', labelnames=['partition'])
> >
> > @Latency_Time.track_inprogress()
> > def latency_request(latency):
> > Latency_Time.labels('partition', '1').set(latency). # I know there is 
> something wrong here.. I'm not able to figure out what !
> > # Latency_Time.set(latency) # This code works without label
> >
> > if __name__ == '__main__':
> > start_http_server(17500)
> > while True:
> > latency_request(random.randrange(1900, 2150))
> >
> > On Wednesday, 2 June 2021 at 17:04:04 UTC+8 Rahul Sinha wrote:
> >>
> >> Code ::
> >>
> >> from prometheus_client import start_http_server, Gauge
> >> import random
> >> from random import randrange
> >>
> >> #Latency_Time = Gauge('consumer_gauge_seconds', 'Time spent in 
> consuming message')
> >> Latency_Time = Gauge('consumer_gauge_seconds', 'Time spent in consuming 
> message', labelnames=['partition'])
> >>
> >> @Latency_Time.track_inprogress()
> >> def latency_request(latency):
> >> Latency_Time.labels('partition', '1').set(latency)
> >> # Latency_Time.set(latency)
> >>
> >> if __name__ == '__main__':
> >> start_http_server(17500)
> >> while True:
> >> latency_request(random.randrange(1900, 2150))
> >>
> >>
> >> Error Message::
> >>
> >> /Users/rahulsinha/anaconda3/envs/envpy37/bin/python 
> /Users/rahulsinha/PycharmProjects/pythonProject/prom_pythonclient.py
> >> Traceback (most recent call last):
> >> File 
> "/Users/rahulsinha/PycharmProjects/pythonProject/prom_pythonclient.py", 
> line 8, in <module>
> >> @Latency_Time.track_inprogress()
> >> File 
> "/Users/rahulsinha/anaconda3/envs/envpy37/lib/python3.7/site-packages/prometheus_client/metrics.py",
>  
> line 377, in track_inprogress
> >> self._raise_if_not_observable()
> >> File 
> "/Users/rahulsinha/anaconda3/envs/envpy37/lib/python3.7/site-packages/prometheus_client/metrics.py",
>  
> line 66, in _raise_if_not_observable
> >> raise ValueError('%s metric is missing label values' % str(self._type))
> >> ValueError: gauge metric is missing label values
> >>
> >> Process finished with exit code 1
> >
> > --
> > 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/2e844b18-8671-4f20-bc4d-721f432d703an%40googlegroups.com
> .
>

-- 
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/6c2d7a54-a3f7-4fb1-a630-4323bc0c7a2cn%40googlegroups.com.

Reply via email to