diff --git a/docker-compose.yml b/docker-compose.yml index d5da3fe..83a1b75 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,7 +14,7 @@ x-influxdb-api-key: &influxdb-api-key .env.influxdb x-influxdb-client-env: &influxdb-client-env INFLUX_BUCKET: ${INFLUX_BUCKET:-place} - INFLUX_HOST: ${INFLUX_HOST:-http://influxdb:9999} + INFLUX_HOST: ${INFLUX_HOST:-http://influxdb:8086} INFLUX_ORG: ${INFLUX_ORG:-PlaceOS} x-mqtt-client-env: diff --git a/src/controllers/root.cr b/src/controllers/root.cr index 191ad6f..13f7a36 100644 --- a/src/controllers/root.cr +++ b/src/controllers/root.cr @@ -1,3 +1,4 @@ +require "http/client" require "./application" require "placeos-models/version" @@ -30,6 +31,9 @@ module PlaceOS::Source::Api Promise.defer { check_resource?("postgres") { pg_healthcheck } }, + Promise.defer { + check_resource?("influx") { influx_healthcheck } + }, ).then(&.all?).get end @@ -66,6 +70,22 @@ module PlaceOS::Source::Api end end + def self.influx_healthcheck : Bool + influx_host = INFLUX_HOST + return false if influx_host.nil? + + begin + HTTP::Client.new(URI.parse(influx_host)) do |client| + client.connect_timeout = 5.seconds + client.read_timeout = 5.seconds + response = client.get("/health") + response.status_code == 200 + end + rescue + false + end + end + private class_getter redis : Redis do StatusEvents.new_redis end