public
Description: A very fast & simple Ruby web server
Homepage: http://code.macournoyer.com/thin/
Clone URL: git://github.com/macournoyer/thin.git
Search Repo:
* Add PID and more info from the last request to the Stats adapter
  mostly taken from Rack::ShowException.
macournoyer (author)
Sun Jan 27 19:05:08 -0800 2008
commit  5d29f05e15440c52447a12262de9450adcf8761b
tree    dd19a2b146543d8da0d71f607fe946d98d77f6e8
parent  4151616754e1b88b4e461f3663f7e2a8c6259375
...
1
 
 
2
3
4
...
1
2
3
4
5
6
0
@@ -1,4 +1,6 @@
0
 == 0.6.2 Rambo release
0
+ * Add PID and more info from the last request to the Stats adapter
0
+ mostly taken from Rack::ShowException.
0
  * pid and log files in cluster are no longer required to be relative to the
0
    app directory (chdir option), fixes #24
0
  * Revert to using #each when building response headers under Ruby 1.8,
...
15
16
17
18
19
20
21
...
28
29
30
31
 
32
33
34
35
...
51
52
53
 
 
 
 
 
 
 
54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
56
57
58
...
122
123
124
125
126
127
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
129
130
 
131
132
133
134
...
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
170
171
...
15
16
17
 
18
19
20
...
27
28
29
 
30
31
32
33
34
...
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
...
152
153
154
 
 
 
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
 
177
178
179
180
181
...
195
196
197
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
0
@@ -15,7 +15,6 @@
0
         @requests = 0
0
         @requests_finished = 0
0
         @start_time = Time.now
0
- @last_env = {}
0
       end
0
       
0
       def call(env)
0
@@ -28,7 +27,7 @@
0
       
0
       def log(env)
0
         @requests += 1
0
- @last_env = env
0
+ @last_request = Rack::Request.new(env)
0
         request_started_at = Time.now
0
         
0
         response = yield
0
0
@@ -51,7 +50,38 @@
0
           [body]
0
         ]
0
       end
0
+
0
+ # Taken from Rails
0
+ def distance_of_time_in_words(from_time, to_time = 0, include_seconds = false)
0
+ from_time = from_time.to_time if from_time.respond_to?(:to_time)
0
+ to_time = to_time.to_time if to_time.respond_to?(:to_time)
0
+ distance_in_minutes = (((to_time - from_time).abs)/60).round
0
+ distance_in_seconds = ((to_time - from_time).abs).round
0
 
0
+ case distance_in_minutes
0
+ when 0..1
0
+ return (distance_in_minutes == 0) ? 'less than a minute' : '1 minute' unless include_seconds
0
+ case distance_in_seconds
0
+ when 0..4 then 'less than 5 seconds'
0
+ when 5..9 then 'less than 10 seconds'
0
+ when 10..19 then 'less than 20 seconds'
0
+ when 20..39 then 'half a minute'
0
+ when 40..59 then 'less than a minute'
0
+ else '1 minute'
0
+ end
0
+
0
+ when 2..44 then "#{distance_in_minutes} minutes"
0
+ when 45..89 then 'about 1 hour'
0
+ when 90..1439 then "about #{(distance_in_minutes.to_f / 60.0).round} hours"
0
+ when 1440..2879 then '1 day'
0
+ when 2880..43199 then "#{(distance_in_minutes / 1440).round} days"
0
+ when 43200..86399 then 'about 1 month'
0
+ when 86400..525599 then "#{(distance_in_minutes / 43200).round} months"
0
+ when 525600..1051199 then 'about 1 year'
0
+ else "over #{(distance_in_minutes / 525600).round} years"
0
+ end
0
+ end
0
+
0
 # Taken from Rack::ShowException
0
 # adapted from Django <djangoproject.com>
0
 # Copyright (c) 2005, the Lawrence Journal-World
0
0
@@ -122,12 +152,29 @@
0
 <div id="summary">
0
   <h1>Server stats</h1>
0
   <h2><%= Thin::SERVER %></h2>
0
- <div id="uptime">
0
- <%= Time.now - @start_time %> uptime
0
- </div>
0
+ <table>
0
+ <tr>
0
+ <th>Uptime</th>
0
+ <td><%= distance_of_time_in_words(@start_time, Time.now) %> (<%= Time.now - @start_time %> sec)</td>
0
+ </tr>
0
+ <tr>
0
+ <th>PID</th>
0
+ <td><%=h Process.pid %></td>
0
+ </tr>
0
+ </table>
0
+
0
+ <% if @last_request %>
0
+ <h3>Jump to:</h3>
0
+ <ul id="quicklinks">
0
+ <li><a href="#get-info">GET</a></li>
0
+ <li><a href="#post-info">POST</a></li>
0
+ <li><a href="#cookie-info">Cookies</a></li>
0
+ <li><a href="#env-info">ENV</a></li>
0
+ </ul>
0
+ <% end %>
0
 </div>
0
 
0
-<div id="requests">
0
+<div id="stats">
0
   <h2>Requests</h2>
0
   <h3>Stats</h3>
0
   <table class="req">
0
0
@@ -148,24 +195,99 @@
0
       <td><%= @last_request_time %> sec</td>
0
     </tr>
0
   </table>
0
- <% if @last_env %>
0
- <h3>Last request</h3>
0
- <table class="req">
0
- <tr>
0
- <th>Variable</th>
0
- <th>Value</th>
0
- </tr>
0
- <tr>
0
- <% @last_env.sort_by { |k, v| k.to_s }.each do |key, val| %>
0
- <tr>
0
- <td><%=h key %></td>
0
- <td class="code"><div><%=h val.inspect %></div></td>
0
- </tr>
0
- <% end %>
0
- </tr>
0
- </table>
0
- <% end %>
0
 </div>
0
+
0
+<% if @last_request %>
0
+ <div id="requestinfo">
0
+ <h2>Last Request information</h2>
0
+
0
+ <h3 id="get-info">GET</h3>
0
+ <% unless @last_request.GET.empty? %>
0
+ <table class="req">
0
+ <thead>
0
+ <tr>
0
+ <th>Variable</th>
0
+ <th>Value</th>
0
+ </tr>
0
+ </thead>
0
+ <tbody>
0
+ <% @last_request.GET.sort_by { |k, v| k.to_s }.each { |key, val| %>
0
+ <tr>
0
+ <td><%=h key %></td>
0
+ <td class="code"><div><%=h val.inspect %></div></td>
0
+ </tr>
0
+ <% } %>
0
+ </tbody>
0
+ </table>
0
+ <% else %>
0
+ <p>No GET data.</p>
0
+ <% end %>
0
+
0
+ <h3 id="post-info">POST</h3>
0
+ <% unless @last_request.POST.empty? %>
0
+ <table class="req">
0
+ <thead>
0
+ <tr>
0
+ <th>Variable</th>
0
+ <th>Value</th>
0
+ </tr>
0
+ </thead>
0
+ <tbody>
0
+ <% @last_request.POST.sort_by { |k, v| k.to_s }.each { |key, val| %>
0
+ <tr>
0
+ <td><%=h key %></td>
0
+ <td class="code"><div><%=h val.inspect %></div></td>
0
+ </tr>
0
+ <% } %>
0
+ </tbody>
0
+ </table>
0
+ <% else %>
0
+ <p>No POST data.</p>
0
+ <% end %>
0
+
0
+
0
+ <h3 id="cookie-info">COOKIES</h3>
0
+ <% unless @last_request.cookies.empty? %>
0
+ <table class="req">
0
+ <thead>
0
+ <tr>
0
+ <th>Variable</th>
0
+ <th>Value</th>
0
+ </tr>
0
+ </thead>
0
+ <tbody>
0
+ <% @last_request.cookies.each { |key, val| %>
0
+ <tr>
0
+ <td><%=h key %></td>
0
+ <td class="code"><div><%=h val.inspect %></div></td>
0
+ </tr>
0
+ <% } %>
0
+ </tbody>
0
+ </table>
0
+ <% else %>
0
+ <p>No cookie data.</p>
0
+ <% end %>
0
+
0
+ <h3 id="env-info">Rack ENV</h3>
0
+ <table class="req">
0
+ <thead>
0
+ <tr>
0
+ <th>Variable</th>
0
+ <th>Value</th>
0
+ </tr>
0
+ </thead>
0
+ <tbody>
0
+ <% @last_request.env.sort_by { |k, v| k.to_s }.each { |key, val| %>
0
+ <tr>
0
+ <td><%=h key %></td>
0
+ <td class="code"><div><%=h val %></div></td>
0
+ </tr>
0
+ <% } %>
0
+ </tbody>
0
+ </table>
0
+
0
+ </div>
0
+<% end %>
0
 
0
 <div id="explanation">
0
   <p>

Comments

    No one has commented yet.