diff options
author | Blaise Thompson <blaise@untzag.com> | 2020-10-30 12:14:50 -0500 |
---|---|---|
committer | Blaise Thompson <blaise@untzag.com> | 2020-10-30 12:14:50 -0500 |
commit | 80b2b07555febdfd05454b14cf1fe5543730593a (patch) | |
tree | f30fee4c3f9fefd742a719f285e506c9560a5867 /write-influx | |
parent | d3e6cae7ea36b695835c4b1f98a0a91c7e5c6ec2 (diff) |
initial candidate for production
Diffstat (limited to 'write-influx')
-rw-r--r-- | write-influx/write_influx.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/write-influx/write_influx.py b/write-influx/write_influx.py index 17b4ce7..4beae4e 100644 --- a/write-influx/write_influx.py +++ b/write-influx/write_influx.py @@ -61,7 +61,12 @@ def on_message(client, userdata, msg): influx_client = InfluxDBClient("db", 8086, 'root', 'root', "homie") + influx_client.create_database("homie") +try: + influx_client.create_retention_policy(name="two-years", database="homie", duration="18000h", default=True, replication=1) +except: + pass def write_point(measurement, tags, fields): @@ -70,7 +75,7 @@ def write_point(measurement, tags, fields): json["tags"] = tags json["fields"] = fields try: - influx_client.write_points([json]) + influx_client.write_points([json], retention_policy="two-years") except Exception as e: print(e) print(json) @@ -81,7 +86,7 @@ client = mqtt.Client() client.on_connect = on_connect client.on_message = on_message -client.connect("broker", 1883, 60) +client.connect("mosquitto.chem.wisc.edu", 1883, 60) # Blocking call that processes network traffic, dispatches callbacks and # handles reconnecting. |