Models

class mmstats.models.BaseMmStats(path='/tmp', filename='{CMD}-{PID}-{TID}.mmstats', label_prefix=None)[source]

Stats models should inherit from this

Optionally given a filename or label_prefix, create an MmStats instance

Both filename and path support the following variable substiutions:

  • {CMD} - name of application (os.path.basename(sys.argv[0]))
  • {PID} - process’s PID (os.getpid())
  • {TID} - thread ID (tries to get it via the SYS_gettid syscall but fallsback to the Python/pthread ID or 0 for truly broken platforms)

This class is not threadsafe, so you should include both {PID} and {TID} in your filename to ensure the mmaped files don’t collide.

flush(async=False)[source]

Flush mmapped file to disk

remove()[source]

Close and remove mmap file - No further stats updates will work

class mmstats.models.FieldState(field)[source]

Holds field state for each Field instance

class mmstats.models.MmStats(path='/tmp', filename='{CMD}-{PID}-{TID}.mmstats', label_prefix=None)[source]

Mmstats default model base class

Just subclass, add your own fields, and instantiate:

>>> from mmstats.models import MmStats
>>> from mmstats.fields import CounterField
>>> class MyStats(MmStats):
...     errors = CounterField()
...
>>> stats = MyStats()
>>> stats.errors.inc()
>>> stats.errors.value
1L

Project Versions

Previous topic

API

Next topic

Model Fields

This Page