Skip to content

Instantly share code, notes, and snippets.

@tudisco
Forked from codification/graphite-client.py
Last active July 11, 2016 06:24
Show Gist options
  • Save tudisco/cce27603217bd01a800f5824aff8d20c to your computer and use it in GitHub Desktop.
Save tudisco/cce27603217bd01a800f5824aff8d20c to your computer and use it in GitHub Desktop.
Graphite client in python
import sys
import time
import socket
def now():
return int(time.time())
def collect_metric(name, value, timestamp=None):
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.connect( ("localhost", 2003) )
if timestamp == None:
timestamp = now()
msg = "%s %d %d\n" % (name, value, timestamp)
if sys.version_info[0] >= 3:
sock.send(str.encode(msg))
else:
sock.send(msg)
sock.close()
collect_metric("test.python.udp", 10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment