Telegraf client

influxdb, python, telegraf
pip install pytelegraf==0.3.3



Python client for sending metrics to Telegraf inspired by pystatsd

Build Status

Designed to work with Telegraf UDP listener input plugin.

Pytelegraf supports and is tested to function with Telegraf version 0.13 and newer. It may work with older versions too but that is untested.

Pytelegraf outputs InfluxDB line protocol


Need answers? Join pytelegraf on Gitter Gitter

If you find this library useful please let me know

If you have an idea how this library can be improved then open an issue or even better send a pull request :)

How to install

pip install pytelegraf


from telegraf.client import TelegrafClient
client = TelegrafClient(host='localhost', port=8092)

# Records a single value with no tags
client.metric('some_metric', 123)

# Records a three values with different data types
client.metric('some_metric', {'value_a': 100, 'value_b': 100, 'value_c': True})

# Records a single value with one tag
client.metric('some_metric', 123, tags={'server_name': 'my-server'})

Global tags

The client can be initialized with global tags that will be sent with every metric implicitly

This is useful for adding tagging metrics by host or app

client = TelegrafClient(host='localhost', port=8092, tags={'host': 'my-host-001'})

# Records a single value
client.metric('some_metric', 123)

Because client was initialized with tags the metric contains them too so the line that was sent to Telegraf looks like this

some_metric,host=my-host-001 value=123i

Global tags can be overridden by defining them when sending a metric

# Records a single value with host tag
client.metric('some_metric', 123, tags={'host':'another-host-001', 'some_tag':'some_value'})

Will send the following line

some_metric,host=another-host-001,some_tag=some_value value=123i

HTTP Client

The default TelegrafClient uses UDP to send metrics to Telegraf. The HttpClient works similarly, except that it issues requests via an HTTP POST. HTTP introduces non-trivial overhead, so to avoid blocking the main thread, these POSTs are issued in the background.

To use the HttpClient, pytelegraf must be installed like this: pip install pytelegraf[http]. Alternatively, add pytelegraf[http] to requirements.txt.

from telegraf import HttpClient

http_client = HttpClient(host='localhost', port=8186)
http_client.metric('some_metric', 123, tags={'server_name': 'my-server'})

Telegraf configuration for versions 1.3 and higher

Just follow the sample configuration

  service_address = "udp://localhost:8092"
  data_format = "influx"

Telegraf configuration for versions lower than 1.3

Just follow the sample configuration

  service_address = "localhost:8092"
  allowed_pending_messages = 10000
  data_format = "influx"

Using with Django

Define configuration in Django settings

TELEGRAF_HOST = 'localhost'
TELEGRAF_TAGS = {'some-global-tag': 'some-value'}

Then use the client in code

from telegraf.defaults.django import telegraf

telegraf.metric('some-metric', 1)

How to develop

  • Clone or fork this repo
  • Make changes
  • Run tests with python test
  • Submit a pull request


  • bobo333
  • sbi
  • isvinogradov
  • umax