Skip to content

Instantly share code, notes, and snippets.

@aeppert
Last active March 2, 2016 22:01
Show Gist options
  • Select an option

  • Save aeppert/597da8c95a25fc6e29c1 to your computer and use it in GitHub Desktop.

Select an option

Save aeppert/597da8c95a25fc6e29c1 to your computer and use it in GitHub Desktop.
Write sine wave points to Influxdb for testing.
#!/usr/bin/python
import argparse
from influxdb import InfluxDBClient
import math
import datetime
import time
USER = 'root'
PASSWORD = 'root'
DBNAME = 'tutorial'
def main(host='localhost', port=8086):
"""
main function to generate the sin wave
"""
now = datetime.datetime.today()
client = InfluxDBClient(host, port, USER, PASSWORD, DBNAME)
client.drop_database(DBNAME)
print("Create database: " + DBNAME)
client.create_database(DBNAME)
client.switch_database(DBNAME)
while True:
for angle in range(0, 360):
point = [{
"measurement": 'sin',
"fields": {
"value": math.sin(math.radians(angle))
}
}]
client.write_points(point)
time.sleep(1)
def parse_args():
parser = argparse.ArgumentParser(
description='example code to play with InfluxDB')
parser.add_argument('--host', type=str, required=False, default='localhost',
help='hostname influxdb http API')
parser.add_argument('--port', type=int, required=False, default=8086,
help='port influxdb http API')
return parser.parse_args()
if __name__ == '__main__':
args = parse_args()
main(host=args.host, port=args.port)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment