mission_control-servers 0.2.4 → 0.2.5

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: 07defb87c30b22a7001663636eb16b9840b17f335681bb029915e8aa7a093874
4
- data.tar.gz: 1d9ce1269f6b5d445c7defa11c536f8d0fdc4fc87ec6fa084c7aa999baacbed3
3
+ metadata.gz: 5eef0e07ac8fee585155c704088b7cbfcbf9736440ee11af15bd780ce5077664
4
+ data.tar.gz: f219f8ee1ddcfbed49ee3f80c0493bab20d433173a4863e6fba4abbca367e713
5
5
  SHA512:
6
- metadata.gz: 4b2ee33384343c673dff194caf62bf23da4b44dcc4bf0a6a24e1921c1f55474272ee7c1e455f1d58271df3024876bf1bcc62e5f0a31b0b0247feed22564a3f17
7
- data.tar.gz: 5d1a4036a7286d36dc7e98c92e12ee890499f8bc1c14be8969680f6d9f4dba592c6fc6fb0941f53de4ec043b12ec937ddbc981c5689129136396be9e5868c477
6
+ metadata.gz: 062a231db01dff3d63e7b342dabb170184ec5c9ac0421f3f86f3c9981250c54ccd2a7746854abdc6697c2f1241b8eda3d198c68fe8a158f47a8674e5a31bc6cb
7
+ data.tar.gz: 060a236e9e8d5651175f328c790fc38fc02689ae01ad7cfb353fd7e589ba9fe35252e54335073dfc4366779f1668e1a446da36a37b862b44cbca5a415606350c
@@ -4,10 +4,9 @@ module MissionControl::Servers
4
4
  before_action :set_project
5
5
 
6
6
  def create
7
- head :unprocessable_entity and return unless @project
8
7
  ingress = @project.services.new(ingress_params)
9
8
 
10
- if ingress.save!
9
+ if ingress.save
11
10
  head :ok
12
11
  else
13
12
  head :unprocessable_entity
@@ -17,7 +16,7 @@ module MissionControl::Servers
17
16
  private
18
17
  # Use callbacks to share common setup or constraints between actions.
19
18
  def set_project
20
- @project = Project.find_by(token: params[:project_id])
19
+ @project = Project.find_by!(token: params[:project_id])
21
20
  end
22
21
 
23
22
  def ingress_params
@@ -3,7 +3,6 @@ module MissionControl::Servers
3
3
  before_action :set_project
4
4
 
5
5
  def show
6
- head :not_found and return unless @project
7
6
  response.content_type = 'text/plain'
8
7
 
9
8
  # Render the script directly or from a file
@@ -13,7 +12,7 @@ module MissionControl::Servers
13
12
  private
14
13
  # Use callbacks to share common setup or constraints between actions.
15
14
  def set_project
16
- @project = Project.find_by(token: params[:project_id])
15
+ @project = Project.find_by!(token: params[:project_id])
17
16
  end
18
17
 
19
18
  def script_content
@@ -42,22 +41,43 @@ module MissionControl::Servers
42
41
  fi
43
42
 
44
43
  cat <<'EOF' > metrics.sh
45
- #!/bin/bash
46
-
47
- endpoint="#{project_ingress_url(@project.token)}"
48
- cpu_usage=$(vmstat 1 5 | awk 'NR==4 {print 100 - $15}')
49
- mem_used=$(free -m | awk '/^Mem:/ {print $3}')
50
- mem_free=$(free -m | awk '/^Mem:/ {print $7}')
51
- disk_free=$(df -h | awk '$NF=="/"{print $4}')
52
- hostname=$(hostname)
53
-
54
- data="service[cpu]=$cpu_usage"
55
- data="$data&service[mem_used]=$mem_used"
56
- data="$data&service[mem_free]=$mem_free"
57
- data="$data&service[disk_free]=$disk_free"
58
- data="$data&service[hostname]=$hostname"
59
-
60
- curl -X POST $endpoint -d $data
44
+ #!/bin/bash
45
+
46
+ DEBUG=0
47
+ if [[ "$1" == "--debug" ]]; then
48
+ DEBUG=1
49
+ fi
50
+
51
+ debug() {
52
+ if [[ $DEBUG -eq 1 ]]; then
53
+ echo "Debug: $1"
54
+ fi
55
+ }
56
+
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
+
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
+
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
+
74
+ debug "Data being sent: $data"
75
+
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
61
81
  EOF
62
82
 
63
83
  chmod +x metrics.sh
@@ -1,5 +1,5 @@
1
1
  module MissionControl
2
2
  module Servers
3
- VERSION = "0.2.4"
3
+ VERSION = "0.2.5"
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.2.4
4
+ version: 0.2.5
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-10 00:00:00.000000000 Z
11
+ date: 2024-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails