Code Monkey home page Code Monkey logo

django-redis-metrics's Introduction

Django Redis Metrics

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
  • currently no grouping of Metrics
  • no timing

In addition, there are some built-in default views and templates for viewing metrics and charts backed by google charts.

Requirements

The only requirement for this app is redis-py and Django 1.4 or above.

Installation

TODO: eventually, pip install django-redis-metrics. For now, add the redis_metrics directory on your python path.

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

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)

There are also gauge's.

from redis_metrics import gauge

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

# Update the gague
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 gagues 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'}}
]

Todo

Tests. OMG there are NO tests!!!?!:exclamation:?!11one1 :grimacing:

django-redis-metrics's People

Contributors

bradmontgomery avatar toastdriven avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.