Skip to content

Commit 873e5f0

Browse files
committed
Add a bunch of examples
1 parent eefd631 commit 873e5f0

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

docs/images/agent-metadata.png

48.6 KB
Loading

docs/templates/agent-metadata.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,77 @@
44
Agent metadata is in an alpha state and may break or disappear at any time.
55
</blockquote>
66

7+
![agent-metadata](../images/agent-metadata.png)
8+
79
With Agent Metadata, template admin can expose operational metrics from
810
their workspaces to their users. It is a sibling of [Resource Metadata](./resource-metadata.md).
911

1012
See the [Terraform reference](https://registry.terraform.io/providers/coder/coder/latest/docs/resources/agent#metadata).
13+
14+
## Examples
15+
16+
Here are useful agent metadata snippets for Linux agents:
17+
18+
Show users how much CPU they're using:
19+
20+
```hcl
21+
resource "coder_agent" "main" {
22+
os = "linux"
23+
...
24+
metadata {
25+
display_name = "CPU Usage"
26+
key = "cpu"
27+
# calculates CPU usage by summing the "us", "sy" and "id" columns of
28+
# vmstat.
29+
script = <<EOT
30+
vmstat | awk 'FNR==3 {printf "%2.0f%%", $13+$14+$16}'
31+
EOT
32+
interval = 1
33+
timeout = 1
34+
}
35+
36+
metadata {
37+
display_name = "Disk Usage"
38+
key = "cpu"
39+
script = <<EOT
40+
df -h | awk -v mount="/" '$6 == mount { print $5 }'
41+
EOT
42+
interval = 1
43+
timeout = 1
44+
}
45+
46+
metadata {
47+
display_name = "Memory Usage"
48+
key = "mem"
49+
script = <<EOT
50+
free | awk '/^Mem/ { printf("%.0f%%", $4/$2 * 100.0) }'
51+
EOT
52+
interval = 1
53+
timeout = 1
54+
}
55+
56+
metadata {
57+
display_name = "Load Average"
58+
key = "load"
59+
script = <<EOT
60+
awk '{print $1,$2,$3}' /proc/loadavg
61+
>>
62+
interval = 1
63+
timeout = 1
64+
}
65+
}
66+
```
67+
68+
Show users the space used in their `/` volume:
69+
70+
## Utilities
71+
72+
* [vmstat](https://linux.die.net/man/8/vmstat) is available in most Linux
73+
distributions and contains virtual memory, CPU and IO statistics. Running `vmstat`
74+
produces output that looks like:
75+
```
76+
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
77+
r b swpd free buff cache si so bi bo in cs us sy id wa st
78+
0 0 19580 4781680 12133692 217646944 0 2 4 32 1 0 1 1 98 0 0
79+
```
80+

0 commit comments

Comments
 (0)