Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitef635f1

Browse files
matifalijohnstcn
andauthored
chore(dogfood): update the dogfood template to add workspace CPU and RAM usage fromcgroup (#7529)
Co-authored-by: Cian Johnston <cian@coder.com>
1 parentdd5b0b2 commitef635f1

File tree

1 file changed

+80
-22
lines changed

1 file changed

+80
-22
lines changed

‎dogfood/main.tf

Lines changed: 80 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -95,48 +95,106 @@ resource "coder_agent" "dev" {
9595

9696
metadata {
9797
display_name="CPU Usage"
98-
key="cpu"
99-
script=<<EOT
100-
vmstat | awk 'FNR==3 {printf "%2.0f%%", $13+$14+$16}'
101-
EOT
102-
interval=1
98+
interval=10
10399
timeout=1
100+
key="0_cpu_usage"
101+
script=<<EOT
102+
#!/bin/bash
103+
# check if we are in cgroup v2 or v1
104+
if [ -e /sys/fs/cgroup/cpu.stat ]; then
105+
# cgroup v2
106+
cusage=$(cat /sys/fs/cgroup/cpu.stat | head -n 1 | awk '{ print $2 }')
107+
else
108+
# cgroup v1
109+
cusage=$(cat /sys/fs/cgroup/cpu,cpuacct/cpuacct.usage)
110+
fi
111+
112+
# get previous usage
113+
if [ -e /tmp/cusage ]; then
114+
cusage_p=$(cat /tmp/cusage)
115+
else
116+
echo $cusage > /tmp/cusage
117+
echo "Unknown"
118+
exit 0
119+
fi
120+
121+
# interval in microseconds should be metadata.interval * 1000000
122+
interval=10000000
123+
ncores=$(nproc)
124+
echo "$cusage $cusage_p $interval $ncores" | awk '{ printf "%2.0f%%\n", (($1 - $2)/$3/$4)*100 }'
125+
126+
EOT
104127
}
105128

106129
metadata {
107-
display_name="Load Average"
108-
key="load"
109-
script="awk '{print $1}' /proc/loadavg"
110-
interval=1
130+
display_name="RAM Usage"
131+
interval=10
111132
timeout=1
133+
key="1_ram_usage"
134+
script=<<EOT
135+
#!/bin/bash
136+
# first check if we are in cgroup v2 or v1
137+
if [ -e /sys/fs/cgroup/memory.stat ]; then
138+
# cgroup v2
139+
echo "`cat /sys/fs/cgroup/memory.current` `cat /sys/fs/cgroup/memory.max`" | awk '{ used=$1/1024/1024/1024; total=$2/1024/1024/1024; printf "%0.2f / %0.2f GB\n", used, total }'
140+
else
141+
# cgroup v1
142+
echo "`cat /sys/fs/cgroup/memory/memory.usage_in_bytes` `cat /sys/fs/cgroup/memory/memory.limit_in_bytes`" | awk '{ used=$1/1024/1024/1024; total=$2/1024/1024/1024; printf "%0.2f / %0.2f GB\n", used, total }'
143+
fi
144+
EOT
112145
}
113146

147+
114148
metadata {
115-
display_name="Disk Usage"
116-
key="disk"
117-
script="df -h | awk '$6 ~ /^\\/$/ { print $5 }'"
118-
interval=1
149+
display_name="CPU Usage (Host)"
150+
key="2_cpu_host"
151+
script=<<EOT
152+
vmstat | awk 'FNR==3 {printf "%2.0f%%", $13+$14+$16}'
153+
EOT
154+
interval=10
119155
timeout=1
120156
}
121157

122158
metadata {
123-
display_name="Memory Usage"
124-
key="mem"
159+
display_name="Memoryand SwapUsage (Host)"
160+
key="3_mem_swap_host"
125161
script=<<EOT
126-
free | awk '/^Mem/ { printf("%.0f%%", $4/$2 * 100.0) }'
127-
EOT
128-
interval=1
162+
mem_usage=`free | awk '/^Mem/ { printf("%.0f%%", $3/$2 * 100.0) }'`
163+
swp_usage=`free | awk '/^Swap/ { printf("%.0f%%", $3/$2 * 100.0) }'`
164+
echo "Memory: $mem_usage, Swap: $swp_usage"
165+
EOT
166+
interval=10
129167
timeout=1
130168
}
131169

170+
metadata {
171+
display_name="Load Average (Host)"
172+
key="4_load_host"
173+
# get load avg scaled by number of cores
174+
script=<<EOT
175+
echo "`cat /proc/loadavg | awk '{ print $1 }'` `nproc`" | awk '{ printf "%0.2f", $1/$2 }'
176+
EOT
177+
interval=10
178+
timeout=1
179+
}
180+
181+
metadata {
182+
display_name="Disk Usage (Host)"
183+
key="5_disk_host"
184+
script=<<EOT
185+
df --output=pcent / | sed -n "2p"
186+
EOT
187+
interval=600
188+
timeout=10#getting disk usage can take a while
189+
}
132190

133191
metadata {
134192
display_name="Word of the Day"
135-
key="word"
193+
key="6_word"
136194
script=<<EOT
137-
curl -o - --silent https://www.merriam-webster.com/word-of-the-day 2>&1 | awk ' $0 ~ "Word of the Day: [A-z]+" { print $5; exit }'
138-
EOT
139-
interval=60
195+
curl -o - --silent https://www.merriam-webster.com/word-of-the-day 2>&1 | awk ' $0 ~ "Word of the Day: [A-z]+" { print $5; exit }'
196+
EOT
197+
interval=86400
140198
timeout=5
141199
}
142200

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp