Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 20 additions & 0 deletions src/controllers/root.cr
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require "http/client"
require "./application"

require "placeos-models/version"
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
Loading