-
Notifications
You must be signed in to change notification settings - Fork 0
/
sine.py
37 lines (30 loc) · 1.11 KB
/
sine.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/python
import json
import math
import requests
import sys
from time import sleep
import os
INFLUX_PROTO = os.getenv('INFLUXDB_PROTO', 'http')
INFLUX_HOST = os.getenv('INFLUXDB_HOST', 'influxdb')
INFLUX_PORT = os.getenv('INFLUXDB_PORT', '8086')
INFLUX_DATABASE = os.getenv('INFLUXDB_DBNAME', 'test_db')
INFLUX_USER = os.getenv('INFLUXDB_USER', 'root')
INFLUX_PASS = os.getenv('INFLUXDB_PASS', 'root')
STATUS_MOD = int(os.getenv('STATUS_INTERVAL' , '10'))
POST_URL = '%s://%s:%s/db/%s/series' % (INFLUX_PROTO, INFLUX_HOST, INFLUX_PORT, INFLUX_DATABASE)
parameters = {'u': INFLUX_USER, 'p': INFLUX_PASS}
print("POST_URL = %s" % POST_URL)
n = 0
while True:
for d in range(0, 360):
v = [{'name': 'sin', 'columns': ['value'], 'points': [[math.sin(math.radians(d))]]}]
#print("%s" % json.dumps(v))
r = requests.post(POST_URL, params=parameters, data=json.dumps(v))
if r.status_code != 200:
print('Failed to add point to influxdb -- aborting.')
sys.exit(1)
n += 1
sleep(1)
if n % STATUS_MOD == 0:
print('%d points inserted.' % n)