Last active
January 22, 2018 09:06
-
-
Save aewallin/906b5bc5b756c67be14cb9ab7e6e49dc to your computer and use it in GitHub Desktop.
This file contains 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
# write data to InfluxDB database | |
# tags and fields (measurement data) as python dicts | |
import influxdb | |
host = 'my.influxdb.server' | |
port = 8086 | |
dbname = 'my_db' | |
def write_dicts(measurement, tagDict, fieldDict): | |
myclient = influxdb.InfluxDBClient(host=host, port=port, database=dbname) | |
data = {} | |
p={} | |
p['measurement']=measurement | |
p['tags']=tagDict | |
p['fields']=fieldDict | |
data['points']=[p] | |
lines = influxdb.line_protocol.make_lines(data) | |
print "----" | |
print lines | |
print "----" | |
myclient.write( data , params={'db':dbname, 'precision':'s'} ) | |
if __name__ == "__main__": | |
# example for testing | |
tagDict={'tag1':'yes', 'tag2':'green'} | |
fieldDict={'val1':22.33, 'val2':-42.42} | |
write_dicts('my_measure', tagDict, fieldDict) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment