Skip to content

Instantly share code, notes, and snippets.

@dragonxtek
Forked from ThomDietrich/sine.py
Last active September 29, 2016 14:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dragonxtek/f7fb410a744fbccd836b25be454e7ba7 to your computer and use it in GitHub Desktop.
Save dragonxtek/f7fb410a744fbccd836b25be454e7ba7 to your computer and use it in GitHub Desktop.
Pump a sine way into a local influxdb cluster
#!/usr/bin/python
import json
import math
import requests
import sys
from time import sleep
IP = "192.168.0.2"
PORT = "8086"
DB = "test"
USER = "user"
PASSWORD = "password123"
TIME = 1
STATUS_MOD = 5
n = 0
while True:
for d in range(0, 360):
v = 'sine_wave value=%s' % math.sin(math.radians(d))
## without autentication
#r = requests.post("http://%s:8086/write?db=%s" %(IP, DB), data=v)
## with autentication
r = requests.post("http://%s:%s/write?db=%s" %(IP, PORT, DB), auth=(USER, PASSWORD), data=v)
if r.status_code != 204:
print 'Failed to add point to influxdb (%d) - aborting.' %r.status_code
sys.exit(1)
n += 1
sleep(TIME)
if n % STATUS_MOD == 0:
print '%d points inserted.' % n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment