forked from unbit/uwsgi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuwsgisubscribers.ru
96 lines (86 loc) · 2.72 KB
/
uwsgisubscribers.ru
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
require 'sinatra'
require 'socket'
require 'json'
module USubscribers
def self.uwsgi_get_stats(server)
parts = server.split(':')
if parts.length > 1
s = TCPSocket.open(parts[0], parts[1])
else
s = UNIXSocket.open(server)
end
return JSON.parse(s.read())
end
end
template = <<eof
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title><%=@title%></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="unbit">
<link href="https://unbit.github.com/bootstrap/css/bootstrap.css" rel="stylesheet">
<style>
body {
padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
}
</style>
<link href="https://unbit.github.com/bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
</head>
<body>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="#"><%=@title%></a>
</div>
</div>
</div>
<% for server in @servers.keys %>
<div class="container">
<hr/>
<h1>SubscriptionServer: <%=server%></h1>
<hr/>
<div class="row">
<% for pool in @servers[server] %>
<div class="span6">
<h3><%=pool['key']%> (<%=pool['hits']%> hits)</h3>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>node</th><th>load</th><th>requests</th>
<th>last check</th>
<th>fail count</th>
</tr>
</thead>
<% for node in pool['nodes'] %>
<tr>
<td><%=node['name']%></td><td><%=node['load']%></td><td><%=node['requests']%></td>
<td><%=Time.at(node['last_check']).strftime("%d-%m-%Y %H:%M:%S")%></td>
<td><%=node['failcnt']%></td>
</tr>
<% end %>
</table>
</div>
<% end %>
</div>
</div>
<% end %>
<script src="https://unbit.github.com/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="https://unbit.github.com/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
</body>
</html>
eof
get '/' do
@servers = {}
for server in ENV['U_SERVERS'].split(',')
stats = USubscribers::uwsgi_get_stats(server)
if stats
@servers[server] = stats['subscriptions']
end
end
@title = 'uWSGI subscriptions viewer'
erb template
end
run Sinatra::Application