Collecting custom metrics using python client in a django application

186 views
Skip to first unread message

arijit desai

unread,
Mar 2, 2021, 4:57:42 PM3/2/21
to Prometheus Users
Hi,

I am trying to monitor a Django based application running on docker. I am using django_prometheus library for models and databases but for application level metrics, i aam using python_client. But some how these metrics dont get updated. The counters dont increment and I only see value 0.0 in /metrics page. 

Any help would be appreciated.

Regards,
Arijit

Jiacai Liu

unread,
Mar 3, 2021, 3:17:36 AM3/3/21
to arijit desai, promethe...@googlegroups.com

How did you initialize metric and what kinds of type do you use?

On 2021-03-03T05:57:42+0800 arijit desai <desai...@gmail.com>
writes:
signature.asc

arijit desai

unread,
Mar 3, 2021, 9:32:39 AM3/3/21
to Prometheus Users
So I created a python file named metrics.py and initialized the following metrics.

metrics.py
from prometheus_client import Counter, Histogram

walks_started = Counter('walks_started', 'number of walks started')
walk_distance = Histogram('walk_distance', 'distribution of distance walked')

and in views.py

from .metrics import walk_distance, walks_started

@walk_distance.time()
def request(self):
     walks_started.inc()
     --------

But in /metrics page I see a zero for all the buckets and also for the counter.

Regards,
Arijit
Reply all
Reply to author
Forward
0 new messages