mission_control-servers 0.2.4 → 0.2.6
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc4409da6282e65c894099e85c2386922bf4720cf2501c7f303ae4ab53feec1b
|
4
|
+
data.tar.gz: ba445e16464f045a01623072ab1e67343757d14604ad67f9e199863969984f4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b7e78d6f062679dff60f16360af3aee1edfde5c696dcd3189c39e029039be81916b5856538cdc1af0a9f62f2b928df1ede6b5c06af79a55438739102740687d
|
7
|
+
data.tar.gz: c6596961ef8050eaa270ca7b052c5a588ef2438a9958096ea65ac64bf03f5647a8946031b11c603daba4c21ac3d83667d1f2913ada6f12a68c079e2d1f9539df
|
@@ -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
|
@@ -44,6 +43,17 @@ module MissionControl::Servers
|
|
44
43
|
cat <<'EOF' > metrics.sh
|
45
44
|
#!/bin/bash
|
46
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
|
+
|
47
57
|
endpoint="#{project_ingress_url(@project.token)}"
|
48
58
|
cpu_usage=$(vmstat 1 5 | awk 'NR==4 {print 100 - $15}')
|
49
59
|
mem_used=$(free -m | awk '/^Mem:/ {print $3}')
|
@@ -51,13 +61,23 @@ module MissionControl::Servers
|
|
51
61
|
disk_free=$(df -h | awk '$NF=="/"{print $4}')
|
52
62
|
hostname=$(hostname)
|
53
63
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
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"
|
59
70
|
|
60
|
-
|
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
|
@@ -65,7 +85,7 @@ module MissionControl::Servers
|
|
65
85
|
cron_job="* * * * * $(pwd)/metrics.sh"
|
66
86
|
(crontab -l 2>/dev/null | grep -v -F "$cron_job"; echo "$cron_job") | crontab -
|
67
87
|
echo "Sending first request to the server..."
|
68
|
-
$(pwd)/metrics.sh
|
88
|
+
bash $(pwd)/metrics.sh
|
69
89
|
echo
|
70
90
|
echo "████████████████████████████████████████████████████████████████████████████"
|
71
91
|
echo "█ █"
|
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
|
+
version: 0.2.6
|
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-
|
11
|
+
date: 2024-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|