Skip to content

Instantly share code, notes, and snippets.

@codification
Last active April 29, 2019 17:21
Show Gist options
  • Save codification/1538841 to your computer and use it in GitHub Desktop.
Save codification/1538841 to your computer and use it in GitHub Desktop.
Graphite client in python
import time
import socket
def collect_metric(name, value, timestamp):
sock = socket.socket()
sock.connect( ("localhost", 2003) )
sock.send("%s %d %d\n" % (name, value, timestamp))
sock.close()
def now():
return int(time.time())
collect_metric("metric.name", 42, now())
@chenyin
Copy link

chenyin commented Mar 28, 2013

now should be "return int(time.time())"

@codification
Copy link
Author

Quite correct!

@mgara
Copy link

mgara commented Jul 20, 2016

sock.send("%s %d %d\n" % (name, value, timestamp)) should be
sock.send("%s %f %d\n" % (name, value, timestamp)) i was using this script in my Django app and then i figure out that i'm loosing precision ... i was storing 0.0 instead of 0.52 and 0.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment