Skip to content

Commit 675a115

Browse files
committed
Add status page
1 parent bf53bfa commit 675a115

File tree

6 files changed

+78
-1
lines changed

6 files changed

+78
-1
lines changed

app/controllers/status_controller.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Shows the various statistics under /stats.
2+
class StatusController < ApplicationController
3+
4+
def index
5+
authorize! :read_instance_state, nil
6+
@sandbox_queue_length = Submission.to_be_reprocessed.count
7+
@unprocessed_submissions_count = Submission.where(processed: false).count
8+
@submissions_count = Submission.where(created_at: Time.current.all_day).count
9+
@submissions_count_week = Submission.where(created_at: Time.current.all_week).count
10+
@sandboxes = RemoteSandbox.all
11+
end
12+
13+
end

app/models/ability.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ def initialize(user)
2323
end
2424
can :access_pghero
2525
can :read_vm_log, Submission
26+
can :read_instance_state
2627
else
28+
cannot :read_instance_state
2729
can :read, :all
2830

2931
cannot :access_pghero

app/models/remote_sandbox.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,16 @@ def capacity
107107
rescue
108108
nil
109109
end
110-
@capacity || 1
110+
@capacity || 0
111+
end
112+
113+
def busy_instances
114+
@busy_instances ||= begin
115+
get_status['busy_instances']
116+
rescue
117+
nil
118+
end
119+
@busy_instances || 0
111120
end
112121

113122
private

app/views/layouts/_navigation.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<% if current_user.administrator? %>
1515
<li class="nav-item"><%= navigation_link 'Users', users_path %></li>
1616
<li class="nav-item"><%= navigation_link 'Course templates', course_templates_path %></li>
17+
<li class="nav-item"><%= navigation_link 'Status', status_index_path %></li>
1718
<% end %>
1819
<% end %>
1920
</ul>

app/views/status/index.html.erb

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<h1>Status</h1>
2+
3+
<p>
4+
Here is some adminsitrative information about this instance.
5+
</p>
6+
7+
<h2>Submissions</h2>
8+
9+
<table class="table">
10+
<tbody>
11+
<tr>
12+
<th scope="row">Submission queue </th scope="row">
13+
<td><%= @sandbox_queue_length %></td>
14+
</tr>
15+
<tr>
16+
<th scope="row">Submissions, processing not complete</th>
17+
<td><%= @unprocessed_submissions_count %></td>
18+
</tr>
19+
<tr>
20+
<th scope="row">Submissions today</th>
21+
<td><%= @submissions_count %></td>
22+
</tr>
23+
<tr>
24+
<th scope="row">Submissions this week</th>
25+
<td><%= @submissions_count_week %></td>
26+
</tr>
27+
</tbody>
28+
</table>
29+
30+
31+
<h2>Sandboxes</h2>
32+
33+
<table class="table">
34+
<thead>
35+
<tr>
36+
<th>Name</th>
37+
<th>Busy instances</th>
38+
<th>Capacity</th>
39+
</tr>
40+
</thead>
41+
<tbody>
42+
<% @sandboxes.each do |sandbox| %>
43+
<tr>
44+
<td><%= sandbox.baseurl %></td>
45+
<td><%= sandbox.busy_instances %></td>
46+
<td><%= sandbox.capacity %></td>
47+
</tr>
48+
<% end %>
49+
</tbody>
50+
</table>

config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@
286286

287287
resource :feedback_replies, only: [:create]
288288

289+
resources :status, only: [:index]
290+
289291
if SiteSetting.value('pghero_enabled')
290292
constraints CanAccessPgHero do
291293
mount PgHero::Engine, at: 'pghero'

0 commit comments

Comments
 (0)