-
-
Save dragonxtek/f7fb410a744fbccd836b25be454e7ba7 to your computer and use it in GitHub Desktop.
Pump a sine way into a local influxdb cluster
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
#!/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