aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBlaise Thompson <blaise@untzag.com>2020-10-30 12:14:50 -0500
committerBlaise Thompson <blaise@untzag.com>2020-10-30 12:14:50 -0500
commit80b2b07555febdfd05454b14cf1fe5543730593a (patch)
treef30fee4c3f9fefd742a719f285e506c9560a5867
parentd3e6cae7ea36b695835c4b1f98a0a91c7e5c6ec2 (diff)
initial candidate for production
-rw-r--r--docker-compose.yml9
-rw-r--r--write-influx/write_influx.py9
2 files changed, 13 insertions, 5 deletions
diff --git a/docker-compose.yml b/docker-compose.yml
index 46c7863..9444ddd 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -6,11 +6,11 @@ services:
ports:
- 1883:1883
db:
- image: influxdb
+ build: ./influxdb
ports:
- 8086:8086
volumes:
- - ./db:/var/lin/influxdb
+ - influxdb:/var/lib/influxdb
write-influx:
build: ./write-influx
depends_on:
@@ -23,4 +23,7 @@ services:
depends_on:
- broker
- db
- - write-influx \ No newline at end of file
+ - write-influx
+
+volumes:
+ influxdb: \ No newline at end of file
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.