Implement tags in python statsd library?

706 Views Asked by At

I am trying to use the tags feature in statsD. But in python statsD there is no feature for tags. But in the documentation they recommended alternatives to implement tags that is statsd-tags.

I have installed both statsd and statsd-tags but still I cant able to make it work. Here is my implemented code:

import statsd
statsd_client = statsd.StatsClient(host="localhost", port=8125)
statsd_client.incr('triggered',20, tags=['production', 'fqdn': 'example.org']) ---> Unexpected Argument
print("Done")

The IDE is throwing unexpected argument error. Am i missing anything here ?

Any help is appreciated. Thanks

2

There are 2 best solutions below

4
On

Maybe you are importing the version of the statsd library without the Tags argument in incr function. You might want to delete that version via pip. Since they use same import name.

0
On

You can use tag as per Influx StatsD tag notation(no need to install statsd-tags)

import statsd
c = statsd.StatsClient('localhost', 8125)
c.incr(f'Gitesh_counter_with_tag, key1={randint(1, 10)}, key2={randint(1, 10)}')

Ref - Influx StatsD

statsd exporter