Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A port of my counters gem - easily track counters for your systems

branch: master
README.textile

PyCounters

A port of counters to Python.

Easily record system performance counters from anywhere in your codebase. The output from this Python port and the original Ruby version are identical, enabling perfect interoperability between both.

Examples

Record counters in-memory:

from counters import MemoryCounters
counters = MemoryCounters()
counters.ping("crawler.alive")

Record counters to Redis:

from counters import RedisCounters
# Use default configuration: host='localhost', port=6379, db=0
counters = RedisCounters(rootkey='counters')

# Configure Redis yourself:
rinstance = redis.Redis('192.168.1.1')
counters = RedisCounters(redis=rinstance, rootkey='counters')

# Use the returned object

counters.ping("crawler.alive")
counters.hit("crawler.urls.crawled")
counters.magnitude("crawler.bytes.in", 20912)

Since all counters are stored under a single Redis Hash, you should pass the default root you want, although the default of counters should work in most cases.

Records counters to a file:

from counters import FileCounters
# Either pass a path or an instance of a file object
counters = FileCounters("path/to/logfile.log")
counters.latency("crawler.processing", 12) # Expects a number of seconds, possibly float
Something went wrong with that request. Please try again.