forked from criteo/consul-templaterb
-
Notifications
You must be signed in to change notification settings - Fork 1
/
services.html.erb
134 lines (130 loc) · 4.91 KB
/
services.html.erb
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<%
# This template can be configure the following way with environment variables
# Environment variables to filter services/instances
# SERVICES_TAG_FILTER: basic tag filter for service (default HTTP)
require 'base64'
require 'json'
require 'date'
services_tag_filter = ENV['SERVICES_TAG_FILTER']
def status_to_class(status)
if status == 'passing'
'success'
elsif status == 'warning'
'warning'
elsif status == 'critical'
'danger'
else
'info'
end
end
def compute_node_status(snode)
state = 'passing'
return state unless snode['Checks']
snode['Checks'].each do |c|
case c['Status']
when 'critical'
return 'critical'
when 'warning'
state = 'warning'
end
end
state
end
def compute_service_status(snodes)
passing = 0
warning = 0
critical = 0
sum = 0
snodes.each do |snode|
st = compute_node_status(snode)
sum += 1
case st
when 'passing'
passing += 1
when 'warning'
warning += 1
else
critical += 1
end
end
[passing, warning, critical, sum]
end
%><%= render_file('common/header.html.erb', title: 'Services') %>
<nav>
<ul>
<li><a href="#datacenters">DataCenters</a></li>
<li><a href="#list_services">List of services</a></li>
<li><a href="#services">Services with instances</a></li>
</ul>
</nav>
<div class="container-fluid">
<div class="row">
<nav id="list_services" class="col-2">
<ul>
<%
all_services = services(tag: services_tag_filter)
all_services.each do |service_name, tags|
%>
<li><a title="<%= tags.sort.join(', ') %>" href="#service_<%= service_name %>"><%= service_name %></a></li>
<% end %>
</ul>
</nav>
<main class="col-10">
<h1 id="datacenters">List of all datacenters</h1>
<ul>
<% datacenters.each do |dc| %>
<li id="dc_<%=dc %>%"><%= dc %> with <%= services(dc:dc).keys.count %> services, <%= nodes(dc:dc).count %> nodes</li>
<% end %>
</ul>
<h1 id="services">List all services instances sorted by node name</h1>
<% services.each do |service_name, tags|
service_group = service(service_name)
nodes_sorted = service_group.sort {|a,b| a['Node']['Node'] <=> b['Node']['Node'] }
passing, warning, critical, sum = compute_service_status(nodes_sorted)
service_state = 'passing'
service_state = 'warning' if warning > 0
service_state = 'critical' if critical > 0
%>
<div class="service <%= service_state %>" id="service_<%= service_name %>">
<h2 class="text-<%= status_to_class(service_state) %>" title="<%= tags.join(', ') %>"><%= service_name %><a class="qlink" href="#service_<%= service_name %>">🔗</a></h2>
<% if sum > 0
%><div class="progress">
<div title="<%= "#{passing} / #{sum}" %>" class="progress-bar bg-success" role="progressbar" style="width:<%= (100.0 * passing / sum).round(2) %>%" aria-valuenow="<%= passing %>" aria-valuemin="0" aria-valuemax="<%= sum %>"></div>
<div title="<%= "#{warning} / #{sum}" %>" class="progress-bar bg-warning" role="progressbar" style="width:<%= (100.0 * warning / sum).round(2) %>%" aria-valuenow="<%= warning %>" aria-valuemin="0" aria-valuemax="<%= sum %>"></div>
<div title="<%= "#{critical} / #{sum}" %>" class="progress-bar bg-danger" role="progressbar" style="width:<%= (100.0 * critical / sum).round(2) %>%" aria-valuenow="<%= critical %>" aria-valuemin="0" aria-valuemax="<%= sum %>"></div>
</div>
<% end %>
<div class="list-group">
<% nodes_sorted.each do |snode|
tags = snode['Service']['Tags'].sort
addr = snode.service_address
port_num = snode['Service']['Port'].to_i
port = port_num && port_num > 0 ? ":#{port_num}" : ''
url = if tags.include? 'https'
"https://#{addr}#{port}"
elsif tags.include? 'http'
"http://#{addr}#{port}"
elsif tags.include? 'ftp'
"ftp://#{addr}#{port}"
else
nil
end
%><div class="list-group-item check"><a <%= url ? "href=\"#{url}\"" : nil %>><%=
snode['Node']['Node'] %><%= port %></a>
<span class="tags"><%
snode['Service']['Tags'].sort.each do |t|
%><span class="badge badge-pill"><%= t %></span><%
end
%></span>
<span class="float-right statuses"><%
snode['Checks'].each do |c| %> <span title="<%= c['Name']%>" class="badge badge-pill badge-<%= status_to_class(c['Status']) %>"><%= c['Status']
%></span><% end if snode['Checks'] %></span></div>
<% end %>
</div>
</div>
<% end
%>
</main>
</div>
</div>
<%= render_file 'common/footer.html.erb' %>