Skip to content

Instantly share code, notes, and snippets.

@william-p
Created November 14, 2013 09:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save william-p/c200a8b122bc7954790b to your computer and use it in GitHub Desktop.
Save william-p/c200a8b122bc7954790b to your computer and use it in GitHub Desktop.
from influxdb import InfluxDBClient
db = "logs"
client = InfluxDBClient("localhost", 8086, "root", "root", db)
try:
client.delete_database(db)
except:
pass
client.create_database(db)
client.add_database_user("root", "root")
nb = 10
for i in xrange(0, nb):
json_body = [{
"points": [
['FR:VSS:ILD:DC', 0, 200],
['CA:BHS:OVH:DC', 0, 200],
['FR:SHB:FRE:A9M', 0, 200],
['all', 0, 200]
],
"name": "hosta",
"columns": ["source", "state", "msg"]
}]
client.write_points(json_body)
query = "select * from hosta"
result = client.query(query)
points = result[0]['points']
print("\nTest1:")
print(" + Query: '%s'" % query)
print(" + Nb points: %s" % len(points))
query = "select * from hosta where source == 'all'"
result = client.query(query)
points = result[0]['points']
print("\nTest2:")
print(" + Query: '%s'" % query)
print(" + Nb points: %s" % len(points))
query = "select * from hosta where source == 'all' limit 5"
result = client.query(query)
points = result[0]['points']
print("\nTest3:")
print(" + Query: '%s'" % query)
print(" + Nb points: %s" % len(points))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment