Last active
March 2, 2016 22:01
-
-
Save aeppert/597da8c95a25fc6e29c1 to your computer and use it in GitHub Desktop.
Write sine wave points to Influxdb for testing.
This file contains hidden or 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 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