Hi Martin,
Are you using any particular metrics framework in Python, or simply looking for a way to send metrics from Python code? In the latter case it's actually very simple:
- import time
- import socket
-
-
- def send_metric(proxy_socket, metric_name, metric_value, source, timestamp=None, point_tags=None):
- timestamp = timestamp or int(time.time())
- tags = ' ' + ' '.join("%s=\"%s\"" % (k, v) for (k, v) in point_tags.iteritems()) if point_tags else ''
- proxy_socket.send("%s %d %d source=%s%s\n" % (metric_name, metric_value, timestamp, source, tags))
-
-
- s = socket.socket()
- s.connect(("localhost", 2878))
- send_metric(s, "metric.name", 1, "metric.source")
- send_metric(s, "metric.name", 2, "metric.source", point_tags={"dc": "west1", "env": "prod"})
- s.close()
If you are using an existing metrics framework, chances are that it can send data in Graphite or OpenTSDB format which are natively supported by our proxy - but if it's not the case, please let us know and we'll see what we can do!
-Vasily
1 of 1 people found this helpful