-
-
Save tudisco/cce27603217bd01a800f5824aff8d20c to your computer and use it in GitHub Desktop.
Graphite client in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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