Python Statsd library for sending statsd messages via the Monasca Agent
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Zuul 298394511e Merge "bump py37 to py38 in tox.ini" 3 weeks ago
doc/source Update hacking for Python3 8 months ago
monascastatsd Clean up 3 years ago
releasenotes/notes [ussuri][goal] Drop python 2.7 support and testing 1 year ago
tests Use unittest.mock instead of mock 5 months ago
.coveragerc Extend tox for monasca-statsd 3 years ago
.gitignore Switch to using stestr 2 years ago
.gitreview OpenDev Migration Patch 1 year ago
.stestr.conf Switch to using stestr 2 years ago
.zuul.yaml Add Python3 wallaby unit tests 2 months ago
CONTRIBUTING.rst Add CONTRIBUTING.rst 6 months ago
LICENSE Clean up the licensing 4 years ago
README.rst change a better title in README.rst 5 months ago
Rakefile Adding python client for statsd messages 6 years ago
lower-constraints.txt Use unittest.mock instead of mock 5 months ago
mkdocs.yml Added a config file for documentation generation using Markdown and 5 years ago
requirements.txt Updated from global requirements 3 years ago
setup.cfg Add py38 package metadata 7 months ago Cleanup py27 support 7 months ago
test-requirements.txt Use unittest.mock instead of mock 5 months ago
tox.ini bump py37 to py38 in tox.ini 2 months ago


Openstack Monasca Statsd


A Monasca-Statsd Python Client.

Quick Start Guide

First install the library with pip or easy_install:

# Install in system python ...
sudo pip install monasca-statsd

# .. or into a virtual env
pip install monasca-statsd

Then start instrumenting your code:

# Import the module.
import monascastatsd as mstatsd

# Create the connection
conn = mstatsd.Connection(host='localhost', port=8125)

# Create the client with optional dimensions
client = mstatsd.Client(connection=conn, dimensions={'env': 'test'})

NOTE: You can also create a client without specifying the connection and it will create the client
with the default connection information for the monasca-agent statsd processor daemon
which uses host='localhost' and port=8125.

client = mstatsd.Client(dimensions={'env': 'test'})

# Increment and decrement a counter.
counter = client.get_counter(name='page.views')

counter += 3

counter -= 3

# Record a gauge 50% of the time.
gauge = client.get_gauge('gauge', dimensions={'env': 'test'})

gauge.send('metric', 123.4, sample_rate=0.5)

# Sample a histogram.
histogram = client.get_histogram('histogram', dimensions={'test': 'True'})

histogram.send('metric', 123.4, dimensions={'color': 'red'})

# Time a function call.
timer = client.get_timer()

def render_page():
    # Render things ...

# Time a block of code.
timer = client.get_timer()

with timer.time('t'):
    # Do stuff

# Add dimensions to any metric.
histogram = client.get_histogram('my_hist')
histogram.send('query.time', 10, dimensions = {'version': '1.0', 'environment': 'dev'})


To suggest a feature, report a bug, or participate in the general discussion, head over to StoryBoard.


See LICENSE file. Code was originally forked from Datadog’s dogstatsd-python, hence the dual license.