Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """Tutorial on using the InfluxDB client."""
- import argparse
- from influxdb import InfluxDBClient
- # curl -i -XPOST 'http://localhost:8086/write?db=smog_db' --data-binary 'smog,airQualityIndex=4,sensorId=11 pm10=0.01,pm25=0.02 14340555620000'
- # curl -G 'http://localhost:8086/query?pretty=true' --data-urlencode "db=smog_db" --data-urlencode "q=SELECT * FROM \"smog\""
- # ssh -i pajtong.pem ec2-user@ec2-52-16-76-3.eu-west-1.compute.amazonaws.com
- # scp -i pajtong.pem ec2-user@ec2-52-16-76-3.eu-west-1.compute.amazonaws.com
- # http://ec2-52-16-76-3.eu-west-1.compute.amazonaws.com:3000
- # admin
- # admin
- # curl -i -XPOST 'http://localhost:8086/write?db=smog_db' --data-binary 'smog,airQualityIndex=4,sensorId=11 pm10=0.01,pm25=0.02 14340555620000'
- def main(host='http://ec2-52-16-76-3.eu-west-1.compute.amazonaws.com', port=8086):
- """Instantiate a connection to the InfluxDB."""
- user = ''
- password = ''
- dbname = 'smog_db'
- # dbuser = 'smly'
- # dbuser_password = 'my_secret_password'
- query = 'SELECT * FROM \"smog\"'
- json_body = []
- client = InfluxDBClient(host, port, user, password, dbname)
- # print("Create database: " + dbname)
- # client.create_database(dbname)
- # print("Create a retention policy")
- # client.create_retention_policy('awesome_policy', '3d', 3, default=True)
- # print("Switch user: " + dbuser)
- # client.switch_user(dbuser, dbuser_password)
- # print("Write points: {0}".format(json_body))
- # client.write_points(json_body)
- print("Querying data: " + query)
- result = client.query(query)
- print("Result: {0}".format(result))
- # print("Switch user: " + user)
- # client.switch_user(user, password)
- print("Drop database: " + dbname)
- client.drop_database(dbname)
- def parse_args():
- """Parse the args."""
- parser = argparse.ArgumentParser(
- description='example code to play with InfluxDB')
- parser.add_argument('--host', type=str, required=False,
- default='localhost',
- help='hostname of InfluxDB http API')
- parser.add_argument('--port', type=int, required=False, default=8086,
- help='port of InfluxDB http API')
- return parser.parse_args()
- if __name__ == '__main__':
- args = parse_args()
- main(host=args.host, port=args.port)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement