health_status 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/public/js/main.js ADDED
@@ -0,0 +1,245 @@
1
+ $(function () {
2
+ $("div[rel='tooltip']").tooltip();
3
+
4
+ $("#timezones").on('shown', function() {
5
+ var modal_scrollpos = $("#timezones li.active:first").position().top - 250;
6
+ $("#timezones .modal-body").scrollTop(modal_scrollpos);
7
+ });
8
+
9
+ $("#timezones").on('hide', function() {
10
+ $("#timezones .modal-body").scrollTop(0);
11
+ });
12
+
13
+ $.cookie("timezone", $("#timezones li.active").data("timezone"));
14
+
15
+ $("#timezones li").click(function () {
16
+ $.cookie("timezone", $(this).data("timezone"));
17
+ });
18
+
19
+ $("div.service-accordion").on('show', function(event) {
20
+ if ($(event.target).hasClass('service-accordion')) {
21
+ $(this).find("div.application-row").each(function (i, e) {
22
+ $(e).addClass("shown-row");
23
+ update_row(i, e);
24
+ });
25
+ $(this).find("div.application-accordion.in").find("div.metric-row").each(function (i, e) {
26
+ $(e).addClass("shown-row");
27
+ update_row(i, e);
28
+ });
29
+ }
30
+ });
31
+
32
+ $("div.application-accordion").on('show', function(event) {
33
+ if ($(event.target).hasClass('application-accordion')) {
34
+ $(this).find("div.metric-row").each(function (i, e) {
35
+ $(e).addClass("shown-row");
36
+ update_row(i, e);
37
+ });
38
+ }
39
+ });
40
+
41
+ $("div.service-accordion").on('hidden', function(event) {
42
+ if ($(event.target).hasClass('service-accordion')) {
43
+ $(this).find("div.application-row").each(function () {
44
+ $(this).removeClass("shown-row");
45
+ });
46
+ $(this).find("div.application-accordion.in").find("div.metric-row").each(function () {
47
+ $(this).removeClass("shown-row");
48
+ });
49
+ }
50
+ });
51
+
52
+ $("div.application-accordion").on('hidden', function(event) {
53
+ if ($(event.target).hasClass('application-accordion')) {
54
+ $(this).find("div.metric-row").each(function () {
55
+ $(this).removeClass("shown-row");
56
+ });
57
+ }
58
+ });
59
+
60
+ $("#refresh").click(refresh_rows);
61
+
62
+ refresh_rows();
63
+
64
+ setInterval(refresh_rows, 60000);
65
+
66
+ function refresh_rows () {
67
+ var url = "/api/v2/";
68
+ $.getJSON(url, function(json) {
69
+ var get_ids = [];
70
+ for (var i = 0; i < json.length; i++) {
71
+ var service = json[i];
72
+ append_service($("#main-container"), service, "/api/v2", get_ids);
73
+ }
74
+
75
+ var old_ids = $("#main-container").data("ids");
76
+ if (old_ids) {
77
+ for (var i = 0; i < old_ids.length; i++) {
78
+ if (get_ids.indexOf(old_ids[i]) == -1) {
79
+ $(old_ids[i]).remove();
80
+ $(old_ids[i]+"-accordion").remove();
81
+ }
82
+ }
83
+ }
84
+
85
+ $("#main-container").data("ids", get_ids);
86
+ force_update_visible();
87
+ });
88
+ }
89
+
90
+ function append_service (main, service, url, get_ids) {
91
+ var service_row = $("#service-"+service.id);
92
+ get_ids.push("#service-"+service.id);
93
+ if (service_row.length == 0) {
94
+ service_row = $("#service-ID").clone().attr("id", "service-"+service.id).removeClass("hide");
95
+ service_row.data("url", url + "/" + encodeURIComponent(service.name));
96
+ service_row.find("div.alert").data("title", service.name).tooltip();
97
+ service_row.find("a.accordion-toggle").data("parent", "#service-"+service.id);
98
+ service_row.find("a.accordion-toggle").attr("href", "#service-"+service.id+"-accordion");
99
+ service_row.find("a.accordion-toggle strong").text(service.name);
100
+ main.append(service_row);
101
+ }
102
+ append_applications_accordion(main, service, service_row.data("url"), get_ids);
103
+ }
104
+
105
+ function append_applications_accordion (main, service, url, get_ids) {
106
+ var app_accordion = $("#service-"+service.id+"-accordion");
107
+ if (app_accordion.length == 0) {
108
+ app_accordion = $("#service-ID-accordion").clone(true).attr("id", "service-"+service.id+"-accordion").removeClass("hide");
109
+ main.append(app_accordion);
110
+ }
111
+ for (var i = 0; i < service.applications.length; i++) {
112
+ append_application(app_accordion, service.applications[i], url, get_ids);
113
+ }
114
+ }
115
+
116
+ function append_application (app_accordion, application, url, get_ids) {
117
+ var app_row = $("#application-"+application.id);
118
+ get_ids.push("#application-"+application.id);
119
+ if (app_row.length == 0) {
120
+ app_row = $("#application-ID").clone().attr("id", "application-"+application.id).removeClass("hide");
121
+ app_row.data("url", url + "/" + encodeURIComponent(application.name));
122
+ app_row.find("div.alert").data("title", application.name).tooltip();
123
+ app_row.find("a.accordion-toggle").data("parent", "#application-"+application.id);
124
+ app_row.find("a.accordion-toggle").attr("href", "#application-"+application.id+"-accordion");
125
+ app_row.find("a.accordion-toggle strong").text(application.name);
126
+ app_accordion.append(app_row);
127
+ if (app_accordion.hasClass("in")) {
128
+ app_row.addClass("shown-row");
129
+ }
130
+ }
131
+ append_metrics_accordion(app_accordion, application, app_row.data("url"), get_ids);
132
+ }
133
+
134
+ function append_metrics_accordion (app_accordion, application, url, get_ids) {
135
+ var metric_accordion = $("#application-"+application.id+"-accordion");
136
+ if (metric_accordion.length == 0) {
137
+ metric_accordion = $("#application-ID-accordion").clone(true).attr("id", "application-"+application.id+"-accordion").removeClass("hide");
138
+ app_accordion.append(metric_accordion);
139
+ }
140
+ for (var i = 0; i < application.metrics.length; i++) {
141
+ append_metric(metric_accordion, application.metrics[i], url, get_ids);
142
+ }
143
+ }
144
+
145
+ function append_metric (metric_accordion, metric, url, get_ids) {
146
+ var metric_row = $("#metric-"+metric.id);
147
+ get_ids.push("#metric-"+metric.id);
148
+ if (metric_row.length == 0) {
149
+ metric_row = $("#metric-ID").clone().attr("id", "metric-"+metric.id).removeClass("hide");
150
+ metric_row.data("url", url + "/" + encodeURIComponent(metric.name));
151
+ metric_row.find("div.alert").data("title", metric.name).tooltip();
152
+ metric_row.find("div.alert").text(metric.name);
153
+ metric_accordion.append(metric_row);
154
+ if (metric_accordion.hasClass("in")) {
155
+ metric_row.addClass("shown-row");
156
+ }
157
+ }
158
+ }
159
+
160
+ function force_update_visible () {
161
+ console.log("force_update_visible");
162
+ $("div.container div.shown-row").each(force_update_row);
163
+ }
164
+ function update_visible () {
165
+ console.log("update_visible");
166
+ $("div.container div.shown-row").each(update_row);
167
+ }
168
+
169
+ function force_update_row (index, element) {
170
+ $(element).data("refresh_time", 0);
171
+ update_row(index, element);
172
+ }
173
+
174
+ function update_row (index, element) {
175
+ var row = $(element);
176
+ var refresh_time = row.data("refresh_time") === undefined ? 0 : row.data("refresh_time");
177
+ var now = Math.round(+new Date()/1000);
178
+ if (refresh_time < now - 60) {
179
+ row.data("refresh_time", now);
180
+ console.log("update " + row.attr("id") + " time: " + row.data("refresh_time"));
181
+ var url = row.data("url") + "?timezone=" + encodeURIComponent($.cookie("timezone"));
182
+ var title = row.find(".alert");
183
+ var hours = row.find(".status-hourly span");
184
+ var days = row.find(".status-daily span");
185
+ $.getJSON(url, function(json) {
186
+ title.each(function (){
187
+ $(this).removeClass("alert-success alert-error alert-info").addClass(titleClass(json.current_status));
188
+ });
189
+
190
+ for (var i = 0; i < 25; i++) {
191
+ var data = json.hourly_status[24-i];
192
+ var span = $(hours.get(i));
193
+ span.text(parse_hour(data.datetime));
194
+ span.removeClass("label-success label-warning label-important").addClass(labelClass(data.status));
195
+ }
196
+
197
+ for (var i = 0; i < 8; i++) {
198
+ var data = json.daily_status[7-i];
199
+ var span = $(days.get(i));
200
+ span.text(parse_date(data.datetime));
201
+ span.removeClass("label-success label-warning label-important").addClass(labelClass(data.status));
202
+ }
203
+ });
204
+ } else {
205
+ console.log("skip update " + row.attr("id") + " time: " + refresh_time + " now: " + now);
206
+ }
207
+ }
208
+
209
+ function titleClass (status) {
210
+ switch (status) {
211
+ case 1:
212
+ return "alert-success"; break;
213
+ case 2:
214
+ return ""; break;
215
+ case 3:
216
+ return "alert-error"; break;
217
+ default:
218
+ return "alert-info"; break;
219
+ }
220
+ }
221
+
222
+ function labelClass (status) {
223
+ switch (status) {
224
+ case 1:
225
+ return "label-success"; break;
226
+ case 2:
227
+ return "label-warning"; break;
228
+ case 3:
229
+ return "label-important"; break;
230
+ default:
231
+ return ""; break;
232
+ }
233
+ }
234
+
235
+ function parse_hour (datetime) {
236
+ var m = datetime.match(/^\d{4}-\d{2}-\d{2}T(\d{2}):\d{2}:\d{2}/);
237
+ return m[1];
238
+ }
239
+
240
+ function parse_date (datetime) {
241
+ var m = datetime.match(/^\d{4}-(\d{2})-(\d{2})T\d{2}:\d{2}:\d{2}/);
242
+ return m[1] + "/" + m[2];
243
+ }
244
+
245
+ });
data/views/index.erb ADDED
@@ -0,0 +1,123 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>HealthStatus</title>
6
+ <!-- Le styles -->
7
+ <link href="css/bootstrap.css" rel="stylesheet">
8
+ <link href="css/main.css" rel="stylesheet">
9
+
10
+ <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
11
+ <!--[if lt IE 9]>
12
+ <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
13
+ <![endif]-->
14
+ </head>
15
+
16
+ <body>
17
+
18
+ <div class="navbar navbar-fixed-top">
19
+ <div class="navbar-inner">
20
+ <div class="brand muted"><a href="/">HealthStatus</a></div>
21
+ <ul class="nav">
22
+ <li><button id="refresh" class="btn btn-link"><i class="icon-refresh"></i>Refresh</button></li>
23
+ </ul>
24
+ <ul class="nav pull-right">
25
+ <li class="active"><a href="#timezones" data-toggle="modal"><%= @timezone %></a></li>
26
+ </ul>
27
+ </div>
28
+ </div>
29
+
30
+ <div id="main-container" class="container">
31
+ </div> <!-- /container -->
32
+
33
+ <div>
34
+ <div class="row service-row shown-row hide" id="service-ID">
35
+ <div class="span2 status-title">
36
+ <div class="alert alert-info" rel="tooltip" data-placement="right">
37
+ <a class="accordion-toggle alert alert-info" data-toggle="collapse" data-parent="#service-ID" href="#service-ID-accordion">
38
+ <strong></strong>
39
+ </a>
40
+ </div>
41
+ </div>
42
+ <div class="span6 status-hourly">
43
+ <% 25.times { %>
44
+ <span class="label">00</span>
45
+ <% } %>
46
+ </div>
47
+ <div class="span4 status-daily">
48
+ <% 8.times { %>
49
+ <span class="label">00/00</span>
50
+ <% } %>
51
+ </div>
52
+ </div>
53
+
54
+ <div class="service-accordion accordion-body collapse hide" id="service-ID-accordion"></div>
55
+ <div class="row application-row hide" id="application-ID">
56
+ <div class="span2 status-title">
57
+ <div class="alert alert-info" style="margin-left:10px" rel="tooltip" data-placement="right">
58
+ <a class="accordion-toggle alert alert-info" data-toggle="collapse" data-parent="#application-ID" href="#application-ID-accordion">
59
+ <strong></strong>
60
+ </a>
61
+ </div>
62
+ </div>
63
+ <div class="span6 status-hourly">
64
+ <% 25.times { %>
65
+ <span class="label">00</span>
66
+ <% } %>
67
+ </div>
68
+ <div class="span4 status-daily">
69
+ <% 8.times { %>
70
+ <span class="label">00/00</span>
71
+ <% } %>
72
+ </div>
73
+ </div>
74
+
75
+ <div class="application-accordion accordion-body collapse hide" id="application-ID-accordion"></div>
76
+ <div class="row metric-row hide" id="metric-ID">
77
+ <div class="span2 status-title">
78
+ <div class="alert alert-info" style="margin-left:20px" rel="tooltip" data-placement="right">
79
+ </div>
80
+ </div>
81
+ <div class="span6 status-hourly">
82
+ <% 25.times { %>
83
+ <span class="label">00</span>
84
+ <% } %>
85
+ </div>
86
+ <div class="span4 status-daily">
87
+ <% 8.times { %>
88
+ <span class="label">00/00</span>
89
+ <% } %>
90
+ </div>
91
+ </div>
92
+ </div>
93
+
94
+ <div id="timezones" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="aaa" aria-hiden="true">
95
+ <div class="modal-header">
96
+ Choose Time Zone
97
+ </div>
98
+ <div class="modal-body">
99
+ <ul class="nav nav-pills nav-stacked">
100
+ <% @zones.each { |k, v| %>
101
+ <li <%= 'class="active"' if v["string"] == @timezone %> data-timezone="<%= v["string"] %>">
102
+ <a href="/?timezone=<%= v["encode"] %>"><%= k %></a>
103
+ </li>
104
+ <% } %>
105
+ </ul>
106
+ </div>
107
+ <div class="modal-footer">
108
+
109
+ </div>
110
+ </div>
111
+
112
+ <!-- Le javascript
113
+ ================================================== -->
114
+ <!-- Placed at the end of the document so the pages load faster -->
115
+ <script src="js/jquery.js"></script>
116
+ <script src="js/jquery.cookie.js"></script>
117
+ <script src="js/bootstrap.js"></script>
118
+ <script src="js/main.js"></script>
119
+
120
+ </body>
121
+ </html>
122
+
123
+
metadata ADDED
@@ -0,0 +1,217 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: health_status
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ryosuke IWANAGA
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sinatra
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: sinatra-contrib
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: activerecord
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: sinatra-activerecord
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: sqlite3
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: vegas
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: bundler
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '1.3'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: '1.3'
126
+ - !ruby/object:Gem::Dependency
127
+ name: tapp
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: rake
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ description: Health status API server
159
+ email:
160
+ - riywo.jp@gmail.com
161
+ executables:
162
+ - health_status_server
163
+ extensions: []
164
+ extra_rdoc_files: []
165
+ files:
166
+ - .gitignore
167
+ - Gemfile
168
+ - LICENSE.txt
169
+ - README.md
170
+ - Rakefile
171
+ - bin/health_status_server
172
+ - db/migrate/20121130030246_health_status_migration.rb
173
+ - db/migrate/20121204050629_remove_datetime.rb
174
+ - db/migrate/20121204171946_add_service_metric.rb
175
+ - health_status.gemspec
176
+ - lib/health_status.rb
177
+ - lib/health_status/app.rb
178
+ - lib/health_status/model.rb
179
+ - lib/health_status/version.rb
180
+ - lib/health_status/web.rb
181
+ - public/css/bootstrap.css
182
+ - public/css/bootstrap.min.css
183
+ - public/css/main.css
184
+ - public/img/glyphicons-halflings-white.png
185
+ - public/img/glyphicons-halflings.png
186
+ - public/js/bootstrap.js
187
+ - public/js/bootstrap.min.js
188
+ - public/js/jquery.cookie.js
189
+ - public/js/jquery.js
190
+ - public/js/main.js
191
+ - views/index.erb
192
+ homepage: https://github.com/riywo/health_status
193
+ licenses:
194
+ - MIT
195
+ post_install_message:
196
+ rdoc_options: []
197
+ require_paths:
198
+ - lib
199
+ required_ruby_version: !ruby/object:Gem::Requirement
200
+ none: false
201
+ requirements:
202
+ - - ! '>='
203
+ - !ruby/object:Gem::Version
204
+ version: '0'
205
+ required_rubygems_version: !ruby/object:Gem::Requirement
206
+ none: false
207
+ requirements:
208
+ - - ! '>='
209
+ - !ruby/object:Gem::Version
210
+ version: '0'
211
+ requirements: []
212
+ rubyforge_project:
213
+ rubygems_version: 1.8.23
214
+ signing_key:
215
+ specification_version: 3
216
+ summary: API server to store and visualize applications' health status
217
+ test_files: []