Instantly share code, notes, and snippets.

@ThomDietrich / forked from otoolep/
Last active Jun 20, 2018

What would you like to do?
Pump a sine way into a influxdb database
# A little script to send test data to an influxdb installation
# Attention, the non-core library 'requests' is used. You'll need to install it first:
import json
import math
import requests
import sys
from time import sleep
IP = "" # The IP of the machine hosting your influxdb instance
DB = "test" # The database to write to, has to exist
USER = "user" # The influxdb user to authenticate with
PASSWORD = "password123" # The password of that user
TIME = 1 # Delay in seconds between two consecutive updates
STATUS_MOD = 5 # The interval in which the updates count will be printed to your console
n = 0
while True:
for d in range(0, 360):
v = 'sine_wave value=%s' % math.sin(math.radians(d))
## without autentication
#r ="http://%s:8086/write?db=%s" %(IP, DB), data=v)
## with autentication
r ="http://%s:8086/write?db=%s" %(IP, DB), auth=(USER, PASSWORD), data=v)
if r.status_code != 204:
print 'Failed to add point to influxdb (%d) - aborting.' %r.status_code
n += 1
if n % STATUS_MOD == 0:
print '%d points inserted.' % n

This comment has been minimized.

LeDumpier commented Mar 25, 2017

Hi Thom,

I downloaded this Py script but it looks incmplete. I'm no Python programmer but I can see the end to the for loop?

Have I missed something?


This comment has been minimized.

JoKoT3 commented Apr 10, 2017


the end of the loop is implicit, python syntax is based on indentation


This comment has been minimized.

wthomson commented Oct 14, 2017


Your title reads Pump a sine way into a influxdb database.
The word way should be wave.

Bill Thomson


This comment has been minimized.

webtop commented Oct 26, 2017

Thank you, saved me having to write the same thing :)


This comment has been minimized.

ScheissSchiesser commented Jun 20, 2018

Why sleep for so long? Will we break something on the influx side if we try to insert too quickly or something? That seems like a huge problem if so...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment