Skip to content

Instantly share code, notes, and snippets.

@dragonxtek dragonxtek/sine.py forked from ThomDietrich/sine.py
Last active Sep 29, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.