django-prometheus icon indicating copy to clipboard operation
django-prometheus copied to clipboard

Redis Cache Not Exposing Metrics

Open fxfitz opened this issue 5 years ago • 5 comments

I cannot get django-prometheus to expose any metrics around the cache.

I have it configured like so:

CACHES = {
    'default': {
        'BACKEND': 'django_prometheus.cache.backends.redis.RedisCache',
        'LOCATION': [
            'redis://{}:{}/1'.format(REDIS['host'], REDIS['port']),
        ],
        'OPTIONS': {
            'CLIENT_CLASS': 'django_redis.client.DefaultClient',
            'CONNECTION_POOL_KWARGS': {
                'max_connections': 100,
            },
            'SOCKET_CONNECT_TIMEOUT': 5,
            'SOCKET_TIMEOUT': 10,
        },
    },
}

However, whenever I look at /metrics, I don't see any metrics with the word cache in it, even though the cache appears to be working just fine.

All other metrics for http views and the database appears to be working just fine.

fxfitz avatar Oct 16 '18 16:10 fxfitz

Can you confirm you're using django-prometheus>=1.0.15?

Can you confirm that the cache is being used? If nothing is using the cache the metrics may not be created.

@TheOldMop any ideas?

korfuri avatar Oct 23 '18 09:10 korfuri

Yes, I can confirm that.

$ docker exec -ti c073 pip freeze | grep django
django-celery-results==1.0.1
django-netfields==0.9.0
django-prometheus==1.0.15
django-redis==4.9.0
django-redis-cache==1.7.1
django-storages==1.7.1
pytest-django==3.4.3

Our apps are using the cache extensively, but just to be sure:

 $ docker exec -ti c073 python manage.py shell
Python 3.6.5 (default, May  5 2018, 03:05:30)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.core.cache import cache
>>> cache.set('zomg', 'heeeeey')
True
>>> cache.get('zomg')
'heeeeey'

Still no cache metrics after.

fxfitz avatar Oct 23 '18 13:10 fxfitz

@korfuri I can check it in this weekends

TheOldMop avatar Oct 23 '18 18:10 TheOldMop

Maybe you have problem with multiple processes collecting? https://github.com/korfuri/django-prometheus/blob/master/documentation/exports.md. When i run test app with your config and your version in single process setup everything work fine.

TheOldMop avatar Oct 29 '18 19:10 TheOldMop