Skip to content

Instantly share code, notes, and snippets.

@mr337
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mr337/baf4c36039a896df490a to your computer and use it in GitHub Desktop.
Save mr337/baf4c36039a896df490a to your computer and use it in GitHub Desktop.
Import test data into openTSD
import urllib
import urllib2
import json
import time
from random import randint
#microsecond precision must be in 13 digit format, no period
t_old = '{:0<13}'.format(''.join(str(time.time()).split('.')))
while True:
t = '{:0<13}'.format(''.join(str(time.time()).split('.')))
jdata = json.dumps({ "metric": 'sys.cpu.test', "timestamp": t, "value": randint(500,900), "tags": { "host": "web03", "dc": "lga" } })
if t == t_old:
continue
t_old = t
f = urllib2.urlopen('http://127.0.0.1:4242/api/put', jdata)
print 'Posted entry for t={}'.format(t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment