mission_control-servers 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9e260e5cc3de9e7b0faf2f5a3c07caddfc398802dbdc95a695e667639c39c394
4
- data.tar.gz: 4092d62a7d16bc73d69f504b6c72df2f9360193dd6aec8fd5cd12862c1951d22
3
+ metadata.gz: 528c4f44febc66f16c62945fa9e7bf9cec90f03dd3ad0395418ebb64e1d3369b
4
+ data.tar.gz: cf9ed213169883628541b48679c3d8410b06fee630e2c781a528035555fa7fdf
5
5
  SHA512:
6
- metadata.gz: 55073a06bcfb54e72896f64b1633b9983e394d2cf4f727eb95fa6131b9c32c42f78bd683c1ce27cb81d04f3af956e9e6dab5dd58c0b2ef5b780ef51356714e3c
7
- data.tar.gz: 0ce16cfdce72db053874a5cfa6bed60e785f1a1fb49a8b7ab75dd6facdc9b648ad9765370392b5788aa5d52c2335dc914dd9cb2b6f1ead8fc5f68fcf5bc3b98d
6
+ metadata.gz: 72e1c4ea0a8a93a9fdcb4033d64dd2d92230d333c7475b3218a0386edc91c16c660019ac14b311d37a73bedcb4dc15d95143c4e91a71418212ce0380c26f61f8
7
+ data.tar.gz: 5fd770c81254b978a83c340240dc57445ddb7377e69238a4be2d72be4e1a54236f26038e4f3394cb984ac8a73bc057b9ff1b4fdb1b17182837e1cf97accd4902
@@ -48,8 +48,13 @@ module MissionControl::Servers
48
48
 
49
49
  # DELETE /projects/1
50
50
  def destroy
51
- @project.destroy!
52
- redirect_to projects_url, notice: "Project was successfully destroyed.", status: :see_other
51
+ if params[:hostname]
52
+ @project.services.where(hostname: params[:hostname]).delete_all
53
+ redirect_to project_dashboards_project_table_path(@project.token), notice: "Service was successfully destroyed.", status: :see_other
54
+ else
55
+ @project.destroy!
56
+ redirect_to projects_url, notice: "Project was successfully destroyed.", status: :see_other
57
+ end
53
58
  end
54
59
 
55
60
  private
@@ -29,10 +29,10 @@ module MissionControl::Servers
29
29
  hostname=$(hostname)
30
30
 
31
31
  data="service[cpu]=$cpu_usage"
32
- data+="&service[mem_used]=$mem_used"
33
- data+="&service[mem_free]=$mem_free"
34
- data+="&service[disk_free]=$disk_free"
35
- data+="&service[hostname]=$hostname"
32
+ data="$data&service[mem_used]=$mem_used"
33
+ data="$data&service[mem_free]=$mem_free"
34
+ data="$data&service[disk_free]=$disk_free"
35
+ data="$data&service[hostname]=$hostname"
36
36
 
37
37
  curl -X POST $endpoint -d $data
38
38
  EOF
@@ -2,6 +2,7 @@ module MissionControl::Servers
2
2
  class Service < ApplicationRecord
3
3
  belongs_to :project
4
4
  after_create :trim_old_records
5
+ before_create :set_hostname
5
6
 
6
7
  scope :ordered, -> { order(created_at: :desc) }
7
8
 
@@ -40,6 +41,7 @@ module MissionControl::Servers
40
41
  end
41
42
 
42
43
  def mem_percent
44
+ return 0 if mem_used.to_f + mem_free.to_f == 0.0
43
45
  (mem_used.to_f / (mem_used.to_f + mem_free.to_f) * 100).to_i
44
46
  end
45
47
 
@@ -48,5 +50,9 @@ module MissionControl::Servers
48
50
  def trim_old_records
49
51
  project.services.where(hostname: hostname).where(created_at: ..1.week.ago).delete_all
50
52
  end
53
+
54
+ def set_hostname
55
+ self.hostname ||= "unnamed server"
56
+ end
51
57
  end
52
58
  end
@@ -24,12 +24,13 @@
24
24
  <div class="font-medium text-gray-900"><%= hostname%></div>
25
25
  </td>
26
26
  <td class="px-3 py-3.5 text-sm text-gray-500 lg:table-cell"><%= services.last.cpu %>%</td>
27
- <td class="hidden px-3 py-3.5 text-sm text-gray-500 lg:table-cell"><%= number_to_human_size(services.last.mem_used * 1.megabyte) %></td>
27
+ <td class="hidden px-3 py-3.5 text-sm text-gray-500 lg:table-cell"><%= number_to_human_size(services.last.mem_used.to_f * 1.megabyte) %></td>
28
28
  <td class="hidden px-3 py-3.5 text-sm text-gray-500 lg:table-cell"><%= services.last.mem_percent %>%</td>
29
- <td class="hidden px-3 py-3.5 text-sm text-gray-500 lg:table-cell"><%= number_to_human_size(services.last.mem_free * 1.megabyte) %></td>
29
+ <td class="hidden px-3 py-3.5 text-sm text-gray-500 lg:table-cell"><%= number_to_human_size(services.last.mem_free.to_f * 1.megabyte) %></td>
30
30
  <td class="hidden px-3 py-3.5 text-sm text-gray-500 lg:table-cell"><%= services.last.disk_free %></td>
31
31
  <td class="relative py-3.5 pl-3 pr-4 text-right text-sm font-medium sm:pr-6">
32
32
  <%= link_to "Dashboard", project_path(@project, hostname: hostname), target: :_top, class: "inline-flex items-center rounded-md bg-white px-2.5 py-1.5 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-30 disabled:hover:bg-white" %>
33
+ <%= link_to "Remove", project_path(@project, hostname: hostname), data: { "turbo-method": :delete, "turbo-confirm": "Are you sure?" }, class: "inline-flex items-center rounded-md bg-white px-2.5 py-1.5 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-30 disabled:hover:bg-white" %>
33
34
  </td>
34
35
  </tr>
35
36
  <% end %>
@@ -22,5 +22,6 @@
22
22
 
23
23
  <div class="flex items-center justify-between">
24
24
  <%= form.submit class: "bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline" %>
25
+ <%= link_to "Cancel", project, class: "text-blue-600 px-4 hover:text-blue-800 transition duration-150 ease-in-out" %>
25
26
  </div>
26
27
  <% end %>
@@ -1,10 +1,9 @@
1
- <h1>Editing project</h1>
1
+ <div class="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 my-10">
2
+ <h1 class="text-2xl text-center font-semibold text-gray-900 mb-8">Editing project</h1>
2
3
 
3
- <%= render "form", project: @project %>
4
+ <%= render "form", project: @project %>
4
5
 
5
- <br>
6
-
7
- <div>
8
- <%= link_to "Show this project", @project %> |
9
- <%= link_to "Back to projects", projects_path %>
6
+ <div class="text-center mt-6">
7
+ <%= link_to "Back to projects", projects_path, class: "text-blue-600 px-4 hover:text-blue-800 transition duration-150 ease-in-out" %>
8
+ </div>
10
9
  </div>
@@ -20,6 +20,7 @@
20
20
  <td class="whitespace-nowrap text-2xl font-bold tracking-tight text-gray-900 sm:text-3xl"><%= project.title %></td>
21
21
  <td class="relative whitespace-nowrap py-4 pl-3 pr-4 text-right text-sm font-medium sm:pr-6 lg:pr-8">
22
22
  <%= link_to "Dashboards", project, target: :_top, class: "rounded-md bg-indigo-50 px-2.5 py-1.5 text-sm font-semibold text-indigo-600 shadow-sm hover:bg-indigo-100" %>
23
+ <%= link_to "Remove", project, data: { "turbo-method": :delete, "turbo-confirm": "Are you sure?" }, class: "inline-flex items-center rounded-md bg-white px-2.5 py-1.5 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-30 disabled:hover:bg-white" %>
23
24
  </td>
24
25
  </tr>
25
26
  <tr>
@@ -1,5 +1,5 @@
1
1
  module MissionControl
2
2
  module Servers
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mission_control-servers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Kimura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-07 00:00:00.000000000 Z
11
+ date: 2024-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails