mission_control-servers 0.2.5 → 0.2.8
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.
- checksums.yaml +4 -4
- data/README.md +6 -2
- data/app/controllers/mission_control/servers/dashboards/project_tables_controller.rb +1 -0
- data/app/controllers/mission_control/servers/projects_controller.rb +3 -1
- data/app/controllers/mission_control/servers/scripts_controller.rb +31 -31
- data/app/controllers/mission_control/servers/service_settings_controller.rb +27 -0
- data/app/helpers/mission_control/servers/service_settings_helper.rb +4 -0
- data/app/models/mission_control/servers/project.rb +1 -0
- data/app/models/mission_control/servers/service_setting.rb +5 -0
- data/app/views/mission_control/servers/dashboards/last_seens/show.html.erb +1 -1
- data/app/views/mission_control/servers/dashboards/project_tables/show.html.erb +14 -1
- data/app/views/mission_control/servers/projects/_form.html.erb +1 -1
- data/app/views/mission_control/servers/projects/show.html.erb +6 -1
- data/app/views/mission_control/servers/service_settings/edit.html.erb +23 -0
- data/config/routes.rb +1 -0
- data/db/migrate/20240211190130_create_mission_control_servers_service_settings.rb +11 -0
- data/lib/mission_control/servers/version.rb +1 -1
- metadata +6 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1634257f311403b05c024937a8f0eeb89cac5070505267251ae75c47ba25ff36
|
4
|
+
data.tar.gz: c7fff4907632e22dff943e3699d427968aa3b113044cfc0c3d2cbaccc80e3e42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cc22c21ca4226bfac07425241ca08959e7bb1a8d4e9b72fd1ad222d5939d319050938dce9f15a4af3ce7629bc373dd90e83c4a33d3ba4291cf6f92475961e1e
|
7
|
+
data.tar.gz: 640d6852cb5a85c74089dd1f3c99a7c4f67cf14843a7efd81514e9d23770fb7aa480006e8e5ec1879f4f5021e295b4602bc8ce2b28cee14813aaaccbb85ff501
|
data/README.md
CHANGED
@@ -93,14 +93,18 @@ http://localhost:3000/mission_control-servers/projects?interval=30&dark=true&com
|
|
93
93
|
## Protecting the Dashboard
|
94
94
|
|
95
95
|
You can protect the dashboard by using a constraint. This will allow you to only allow certain users to access
|
96
|
-
the dashboard. However, the ingress still needs to be accessible by the servers which are being monitored.
|
96
|
+
the dashboard. However, the ingress still needs to be accessible by the servers which are being monitored. In
|
97
|
+
order to install the script on the servers, you also have to expose the endpoint for the script.
|
97
98
|
|
98
99
|
```ruby
|
99
100
|
Rails.application.routes.draw do
|
101
|
+
get '/mission_control-servers/projects/:project_id/script', to: 'mission_control/servers/scripts#show'
|
102
|
+
post '/mission_control-servers/projects/:project_id/ingress', to: 'mission_control/servers/ingresses#create'
|
103
|
+
|
100
104
|
constraints AdminConstraint do
|
101
105
|
mount MissionControl::Servers::Engine => "/mission_control-servers"
|
102
106
|
end
|
103
|
-
|
107
|
+
|
104
108
|
end
|
105
109
|
```
|
106
110
|
|
@@ -10,6 +10,8 @@ module MissionControl::Servers
|
|
10
10
|
|
11
11
|
# GET /projects/1
|
12
12
|
def show
|
13
|
+
hostnames = @project.services.pluck(:hostname).uniq
|
14
|
+
@service_settings = @project.service_settings.where(hostname: hostnames)
|
13
15
|
@services = if params[:hostname]
|
14
16
|
@project.services.where(hostname: params[:hostname]).group_by(&:hostname)
|
15
17
|
else
|
@@ -66,7 +68,7 @@ module MissionControl::Servers
|
|
66
68
|
|
67
69
|
# Use callbacks to share common setup or constraints between actions.
|
68
70
|
def set_project
|
69
|
-
@project = Project.find(params[:id])
|
71
|
+
@project = Project.includes(:services, :service_settings).find(params[:id])
|
70
72
|
end
|
71
73
|
|
72
74
|
# Only allow a list of trusted parameters through.
|
@@ -41,43 +41,43 @@ module MissionControl::Servers
|
|
41
41
|
fi
|
42
42
|
|
43
43
|
cat <<'EOF' > metrics.sh
|
44
|
-
|
44
|
+
#!/bin/bash
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
46
|
+
DEBUG=0
|
47
|
+
if [[ "$1" == "--debug" ]]; then
|
48
|
+
DEBUG=1
|
49
|
+
fi
|
50
50
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
51
|
+
debug() {
|
52
|
+
if [[ $DEBUG -eq 1 ]]; then
|
53
|
+
echo "Debug: $1"
|
54
|
+
fi
|
55
|
+
}
|
56
56
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
57
|
+
endpoint="#{project_ingress_url(@project.token)}"
|
58
|
+
cpu_usage=$(vmstat 1 5 | awk 'NR==4 {print 100 - $15}')
|
59
|
+
mem_used=$(free -m | awk '/^Mem:/ {print $3}')
|
60
|
+
mem_free=$(free -m | awk '/^Mem:/ {print $7}')
|
61
|
+
disk_free=$(df -h | awk '$NF=="/"{print $4}')
|
62
|
+
hostname=$(hostname)
|
63
63
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
64
|
+
# Debug outputs
|
65
|
+
debug "CPU Usage: $cpu_usage"
|
66
|
+
debug "Memory Used: $mem_used MB"
|
67
|
+
debug "Memory Free: $mem_free MB"
|
68
|
+
debug "Disk Free: $disk_free"
|
69
|
+
debug "Hostname: $hostname"
|
70
70
|
|
71
|
-
|
72
|
-
|
71
|
+
data=$(printf "service[cpu]=%s&service[mem_used]=%s&service[mem_free]=%s&service[disk_free]=%s&service[hostname]=%s" \
|
72
|
+
"$cpu_usage" "$mem_used" "$mem_free" "$disk_free" "$hostname")
|
73
73
|
|
74
|
-
|
74
|
+
debug "Data being sent: $data"
|
75
75
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
76
|
+
if [[ $DEBUG -eq 1 ]]; then
|
77
|
+
curl -v -X POST "$endpoint" -d "$data"
|
78
|
+
else
|
79
|
+
curl -X POST "$endpoint" -d "$data"
|
80
|
+
fi
|
81
81
|
EOF
|
82
82
|
|
83
83
|
chmod +x metrics.sh
|
@@ -85,7 +85,7 @@ module MissionControl::Servers
|
|
85
85
|
cron_job="* * * * * $(pwd)/metrics.sh"
|
86
86
|
(crontab -l 2>/dev/null | grep -v -F "$cron_job"; echo "$cron_job") | crontab -
|
87
87
|
echo "Sending first request to the server..."
|
88
|
-
$(pwd)/metrics.sh
|
88
|
+
bash $(pwd)/metrics.sh
|
89
89
|
echo
|
90
90
|
echo "████████████████████████████████████████████████████████████████████████████"
|
91
91
|
echo "█ █"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module MissionControl::Servers
|
2
|
+
class ServiceSettingsController < ApplicationController
|
3
|
+
def edit
|
4
|
+
@project = Project.find(params[:project_id])
|
5
|
+
@service_setting = @project.service_settings.find_or_initialize_by(hostname: params[:id])
|
6
|
+
@service_setting.label = params[:id] if @service_setting.new_record?
|
7
|
+
@service_setting.save # To limit having to have a create action
|
8
|
+
end
|
9
|
+
|
10
|
+
def update
|
11
|
+
@project = Project.find(params[:project_id])
|
12
|
+
@service_setting = @project.service_settings.find_by(hostname)
|
13
|
+
@service_setting.update(label)
|
14
|
+
redirect_to projects_path, notice: "Updated Service Settings."
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def hostname
|
20
|
+
params.require(:service_setting).permit(:hostname)
|
21
|
+
end
|
22
|
+
|
23
|
+
def label
|
24
|
+
params.require(:service_setting).permit(:label)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -6,7 +6,7 @@
|
|
6
6
|
<dd class="card-heading">Last Seen</dd>
|
7
7
|
<dt class="connected-chart">
|
8
8
|
<%= @service.created_at.strftime("%Y-%-m-%-d") %><br><br>
|
9
|
-
<%= @service.created_at.strftime("
|
9
|
+
<%= @service.created_at.strftime("%-I:%M:%S %p") %>
|
10
10
|
</dt>
|
11
11
|
</div>
|
12
12
|
<% end %>
|
@@ -12,6 +12,7 @@
|
|
12
12
|
<th scope="col" class="hidden px-3 py-3.5 text-left text-sm font-semibold text-gray-normal lg:table-cell">Memory Used %</th>
|
13
13
|
<th scope="col" class="hidden px-3 py-3.5 text-left text-sm font-semibold text-gray-normal lg:table-cell">Memory Free</th>
|
14
14
|
<th scope="col" class="hidden px-3 py-3.5 text-left text-sm font-semibold text-gray-normal lg:table-cell">Disk Free</th>
|
15
|
+
<th scope="col" class="hidden px-3 py-3.5 text-left text-sm font-semibold text-gray-normal lg:table-cell">Last Seen</th>
|
15
16
|
<th scope="col" class="relative py-3.5 pl-3 pr-4 sm:pr-6">
|
16
17
|
<span class="sr-only">Select</span>
|
17
18
|
</th>
|
@@ -21,14 +22,26 @@
|
|
21
22
|
<% @project.services.group_by(&:hostname).each do |hostname, services| %>
|
22
23
|
<tr>
|
23
24
|
<td class="relative py-4 pl-4 pr-3 text-sm sm:pl-6">
|
24
|
-
<div class="font-medium text-gray-normal"
|
25
|
+
<div class="font-medium text-gray-normal">
|
26
|
+
<% service_setting = @service_settings.find { |s| s.hostname == hostname } %>
|
27
|
+
<% if service_setting %>
|
28
|
+
<%= service_setting.label %>
|
29
|
+
(<%= hostname %>)
|
30
|
+
<% else %>
|
31
|
+
<%= hostname %>
|
32
|
+
<% end %>
|
33
|
+
</div>
|
25
34
|
</td>
|
26
35
|
<td class="px-3 py-3.5 text-sm text-gray-light lg:table-cell"><%= services.last.cpu %>%</td>
|
27
36
|
<td class="hidden px-3 py-3.5 text-sm text-gray-light lg:table-cell"><%= number_to_human_size(services.last.mem_used.to_f * 1.megabyte) %></td>
|
28
37
|
<td class="hidden px-3 py-3.5 text-sm text-gray-light lg:table-cell"><%= services.last.mem_percent %>%</td>
|
29
38
|
<td class="hidden px-3 py-3.5 text-sm text-gray-light lg:table-cell"><%= number_to_human_size(services.last.mem_free.to_f * 1.megabyte) %></td>
|
30
39
|
<td class="hidden px-3 py-3.5 text-sm text-gray-light lg:table-cell"><%= services.last.disk_free %></td>
|
40
|
+
<td class="hidden px-3 py-3.5 text-sm text-gray-light lg:table-cell">
|
41
|
+
<%= services.last.created_at.strftime("%Y-%-m-%-d %-I:%M:%S %p") %>
|
42
|
+
</td>
|
31
43
|
<td class="relative py-3.5 pl-3 pr-4 text-right text-sm font-medium sm:pr-6">
|
44
|
+
<%= link_to "Settings", edit_project_service_setting_path(@project, id: hostname), target: :_top, class: "btn btn-default" %>
|
32
45
|
<%= link_to "Dashboard", project_path(@project, hostname: hostname), target: :_top, class: "btn btn-default" %>
|
33
46
|
<%= link_to "Remove", project_path(@project, hostname: hostname), data: { "turbo-method": :delete, "turbo-confirm": "Are you sure?" }, class: "btn btn-danger" %>
|
34
47
|
</td>
|
@@ -54,7 +54,12 @@
|
|
54
54
|
"data-target": hostname,
|
55
55
|
"data-tabs-target": "link",
|
56
56
|
class: "tab-link flex items-center justify-center #{first_tab_class} #{last_tab_class}" do %>
|
57
|
-
|
57
|
+
<% service_setting = @service_settings.find { |s| s.hostname == hostname } %>
|
58
|
+
<% if service_setting %>
|
59
|
+
<%= service_setting.label %>
|
60
|
+
<% else %>
|
61
|
+
<%= hostname %>
|
62
|
+
<% end %>
|
58
63
|
<% end %>
|
59
64
|
<% end %>
|
60
65
|
</nav>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<div class="lg:flex lg:items-center lg:justify-between">
|
2
|
+
<div class="min-w-0 flex-1"></div>
|
3
|
+
<div class="mt-5 flex lg:ml-4 lg:mt-0">
|
4
|
+
<span class="hidden sm:block">
|
5
|
+
<button data-controller="dark-mode" data-action="click->dark-mode#toggle" class="btn btn-default">Dark Mode</button>
|
6
|
+
</span>
|
7
|
+
</div>
|
8
|
+
</div>
|
9
|
+
|
10
|
+
<div class="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 my-10">
|
11
|
+
<h1 class="text-2xl text-center font-semibold text-gray-normal mb-8">Editing <%= @service_setting.hostname %></h1>
|
12
|
+
<%= form_with(model: [@project, @service_setting], class: "max-w-lg mx-auto my-10") do |form| %>
|
13
|
+
<%= form.hidden_field :hostname %>
|
14
|
+
<div class="mb-4">
|
15
|
+
<%= form.label :label, class: "block text-gray-700 text-sm font-bold mb-2" %>
|
16
|
+
<%= form.text_field :label, class: "shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" %>
|
17
|
+
</div>
|
18
|
+
<div class="flex items-center justify-between">
|
19
|
+
<%= form.submit class: "btn btn-primary btn-block" %>
|
20
|
+
<%= link_to "Cancel", projects_path, class: "text-gray-light px-4 transition duration-150 ease-in-out" %>
|
21
|
+
</div>
|
22
|
+
<% end %>
|
23
|
+
</div>
|
data/config/routes.rb
CHANGED
@@ -0,0 +1,11 @@
|
|
1
|
+
class CreateMissionControlServersServiceSettings < ActiveRecord::Migration[7.1]
|
2
|
+
def change
|
3
|
+
create_table :mission_control_servers_service_settings do |t|
|
4
|
+
t.belongs_to :project, null: false, foreign_key: { to_table: :mission_control_servers_projects }
|
5
|
+
t.string :hostname
|
6
|
+
t.string :label
|
7
|
+
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mission_control-servers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dave Kimura
|
@@ -119,7 +119,9 @@ files:
|
|
119
119
|
- app/controllers/mission_control/servers/ingresses_controller.rb
|
120
120
|
- app/controllers/mission_control/servers/projects_controller.rb
|
121
121
|
- app/controllers/mission_control/servers/scripts_controller.rb
|
122
|
+
- app/controllers/mission_control/servers/service_settings_controller.rb
|
122
123
|
- app/helpers/mission_control/servers/application_helper.rb
|
124
|
+
- app/helpers/mission_control/servers/service_settings_helper.rb
|
123
125
|
- app/javascript/mission_control/servers/application.js
|
124
126
|
- app/javascript/mission_control/servers/controllers/application.js
|
125
127
|
- app/javascript/mission_control/servers/controllers/combo_chart_controller.js
|
@@ -136,6 +138,7 @@ files:
|
|
136
138
|
- app/models/mission_control/servers/application_record.rb
|
137
139
|
- app/models/mission_control/servers/project.rb
|
138
140
|
- app/models/mission_control/servers/service.rb
|
141
|
+
- app/models/mission_control/servers/service_setting.rb
|
139
142
|
- app/views/layouts/mission_control/servers/application.html.erb
|
140
143
|
- app/views/mission_control/servers/dashboards/combo_histories/show.html.erb
|
141
144
|
- app/views/mission_control/servers/dashboards/cpu_histories/show.html.erb
|
@@ -151,11 +154,13 @@ files:
|
|
151
154
|
- app/views/mission_control/servers/projects/index.html.erb
|
152
155
|
- app/views/mission_control/servers/projects/new.html.erb
|
153
156
|
- app/views/mission_control/servers/projects/show.html.erb
|
157
|
+
- app/views/mission_control/servers/service_settings/edit.html.erb
|
154
158
|
- config/importmap.rb
|
155
159
|
- config/routes.rb
|
156
160
|
- config/tailwind.config.js
|
157
161
|
- db/migrate/20240205020304_create_mission_control_servers_projects.rb
|
158
162
|
- db/migrate/20240205031009_create_mission_control_servers_services.rb
|
163
|
+
- db/migrate/20240211190130_create_mission_control_servers_service_settings.rb
|
159
164
|
- lib/mission_control/servers.rb
|
160
165
|
- lib/mission_control/servers/configuration.rb
|
161
166
|
- lib/mission_control/servers/engine.rb
|