Skip to content

Commit cb4242f

Browse files
authored
feat: [PPT-2230] Added influx health check (#58)
1 parent 81784a6 commit cb4242f

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ x-influxdb-api-key: &influxdb-api-key .env.influxdb
1414
x-influxdb-client-env:
1515
&influxdb-client-env
1616
INFLUX_BUCKET: ${INFLUX_BUCKET:-place}
17-
INFLUX_HOST: ${INFLUX_HOST:-http://influxdb:9999}
17+
INFLUX_HOST: ${INFLUX_HOST:-http://influxdb:8086}
1818
INFLUX_ORG: ${INFLUX_ORG:-PlaceOS}
1919

2020
x-mqtt-client-env:

src/controllers/root.cr

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require "http/client"
12
require "./application"
23

34
require "placeos-models/version"
@@ -30,6 +31,9 @@ module PlaceOS::Source::Api
3031
Promise.defer {
3132
check_resource?("postgres") { pg_healthcheck }
3233
},
34+
Promise.defer {
35+
check_resource?("influx") { influx_healthcheck }
36+
},
3337
).then(&.all?).get
3438
end
3539

@@ -66,6 +70,22 @@ module PlaceOS::Source::Api
6670
end
6771
end
6872

73+
def self.influx_healthcheck : Bool
74+
influx_host = INFLUX_HOST
75+
return false if influx_host.nil?
76+
77+
begin
78+
HTTP::Client.new(URI.parse(influx_host)) do |client|
79+
client.connect_timeout = 5.seconds
80+
client.read_timeout = 5.seconds
81+
response = client.get("/health")
82+
response.status_code == 200
83+
end
84+
rescue
85+
false
86+
end
87+
end
88+
6989
private class_getter redis : Redis do
7090
StatusEvents.new_redis
7191
end

0 commit comments

Comments
 (0)