Skip to main content

django-redis-metrics is a Django application for tracking application metrics backed by Redis.

Project description

Django Redis Metrics

Build Status https://pypip.in/d/django-redis-metrics/badge.png

This app is inspired by Frank Wiles django-app-metrics. It allows you to define various named metrics (such as ‘New User Signups’, ‘Downloads’) and record when they happen.

However, this app is stripped of all but the bare-bones features offered by the Redis backend in django-app-metrics. Major differences are:

  • only backed by Redis

  • does not require Celery

  • no timing

Additionally, there are some built-in views and templates that include charts (backed by the Google Charts API) for metrics.

License

This code is distributed under the terms of the MIT license. See the LICENSE.txt file.

Requirements

This app works with Django 1.4, 1.5, and 1.6 and only requires redis-py.

If you’d like to run the tests, install the packages listed in requirements/test.txt.

Installation

To install the current version, run pip install django-redis-metrics.

You can also install the development version with pip install -e git://github.com/bradmontgomery/django-redis-metrics.git#egg=redis_metrics-dev

To use the built-in views, add redis_metrics to your INSTALLED_APPS, and include the following in your Root URLconf:

url(r'^metrics/', include('redis_metrics.urls')),

Then, to view your metrics, visit the /metrics/ url, (i.e. run the development server and go to http://127.0.0.1:8000/metrics/)

Settings

  • REDIS_METRICS_HOST - Hostname of redis server, defaults to ‘localhost’

  • REDIS_METRICS_PORT - redis port, defaults to ‘6379’

  • REDIS_METRICS_DB - redis database number to use, defaults to 0

  • REDIS_METRICS_PASSWORD - redis database password to use, defaults to None

  • REDIS_METRICS_SOCKET_TIMEOUT - redis database socket timeout, defaults to None

  • REDIS_METRICS_SOCKET_CONNECTION_POOL - redis database socket connection pool, defaults to None

Usage

Use the metric shortcut to start recording metrics.

from redis_metrics import metric

# Increment the metric by one
metric('new-user-signup')

# Increment the metric by some other number
metric('new-user-signup', 4)

Metrics can also be categorized. To record a metric and add it to a category, specify a category keyword parameter

# Increment the metric, and add it to a category
metric('new-user-signup', category="User Metrics")

Metrics can also expire after a specified number of seconds

# The 'foo' metric will expire in 5 minutes
metric('foo', expire=300)

There are also gauge’s.

from redis_metrics import gauge

# Create a gauge
gauge('total-downloads', 0)

# Update the gauge
gauge('total-downloads', 9999)

There’s also an R class which is a lightweight wrapper around redis. You can use it directly to set metrics or gauges and to retrieve data.

>>> from redis_metrics.models import R
>>> r = R()
>>> r.metric('new-user-signup')
>>> r.get_metric('new-user-signup')
{'day': '29', 'month': '29', 'week': '29', 'year': '29'}

# list the slugs you've used to create metrics
>>> r.metric_slugs()
set(['new-user-signup', 'user-logins'])

# Get metrics for multiple slugs
>>> r.get_metrics(['new-user-signup', 'user-logins'])
[
    {'new-user-signup':
        {'day': '7', 'month': '7', 'week': '7', 'year': '7'}},
    {'user-logins':
        {'day': '29', 'month': '29', 'week': '29', 'year': '29'}}
]

Contributing

Feel free to submit bug reports or pull requests on the github repo.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-redis-metrics-0.7.2.tar.gz (32.3 kB view details)

Uploaded Source

File details

Details for the file django-redis-metrics-0.7.2.tar.gz.

File metadata

File hashes

Hashes for django-redis-metrics-0.7.2.tar.gz
Algorithm Hash digest
SHA256 db84aa0964d668345d3b4bbb4d88193a9452e84cff5b9e893ca0c06b6a31f174
MD5 69b68d10dbfdf8a0939cb9d6d8e52692
BLAKE2b-256 af1667199b0dfdd07275535ddb6de5bdb8989ecd59f3ab6e8c0fd00ffbf80d97

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page