-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhealthdemo.rb
63 lines (54 loc) · 1.01 KB
/
healthdemo.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require 'date'
require 'json'
require 'net/http'
require 'sinatra/base'
require 'socket'
class HealthDemo < Sinatra::Application
@host = Socket.gethostname
def self.live_info
live = {}
live['live'] = File.exist?('/tmp/live')
live['hostname'] = @host
live['timestamp'] = Time.now.iso8601
live
end
def self.ready_info
ready = {}
ready['ready'] = File.exist?('/tmp/ready')
ready['hostname'] = @host
ready['timestamp'] = Time.now.iso8601
ready
end
get '/' do
content_type :text
"Hello world\n"
end
get '/env' do
tmp = {}
ENV.map do |k,v|
tmp[k] = v
end
content_type :json
tmp.to_json
end
get '/health/live' do
tmp = HealthDemo.live_info
content_type :json
if(tmp['live'])
status 200
else
status 503
end
tmp.to_json
end
get '/health/ready' do
tmp = HealthDemo.ready_info
content_type :json
if(tmp['ready'])
status 200
else
status 503
end
tmp.to_json
end
end