Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending statsD metrics with tags from python client

I'm trying to send metrics to graphite from my python app through statsD, I'm using this client (which I understand is most common).

But I can't figure out how to send metrics with tags.

I've tried this syntax (from here):

c.incr('foo.bar,tag1=val')

And also this (got the idea from here):

c.incr('foo.bar;tag1=val')

But nothing seem to work.

Did anyone succeeded sending statsd metrics from python with tags?

Thanks

like image 568
Tzvika Mordoch Avatar asked Jan 01 '26 05:01

Tzvika Mordoch


1 Answers

UPDATE:

It seems all you need to do now is to install:

pip install statsd-telegraf

See here

Works as expected


To send tags from python statsD you need to install this fork:

https://pypi.org/project/statsd-telegraf/

But, two important notes:

  1. Do NOT install from PyPI alone, it has an unfixed bug
    BAD: pip install statsd-tags

After installing from PyPI, Install directly from GitHub, using the correct username (In the PyPI link above, the wrong link is shown)

    GOOD: pip install statsd-tags
          pip install -e git+https://github.com/Granitosaurus/statsd-telegraf#egg=statsd-telegraf
  1. The documentation in PyPI of how to use the tags is wrong.

Tags should be a dict. For example:

    import statsd
    c = statsd.StatsClient('localhost', 8125, prefix='foo')
    c.incr('bar', tags = {"key1": "value1", "key2":"value2"})
like image 190
user3689574 Avatar answered Jan 02 '26 17:01

user3689574



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!