Skip to content

feat(cli): add coder stat command #8005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 48 commits into from
Jun 20, 2023
Merged

feat(cli): add coder stat command #8005

merged 48 commits into from
Jun 20, 2023

Conversation

johnstcn
Copy link
Member

@johnstcn johnstcn commented Jun 13, 2023

Adds a coder stat command that emits resource information about the current workspace host or container.

$ coder stat
HOST CPU        HOST MEMORY     HOME DISK         CONTAINER CPU   CONTAINER MEMORY  
7.5/64.0 cores  246.5/251.4 GB  1225.8/3050.4 GB  0.1/64.0 cores  4.6/15.4 GB   

$ coder stat cpu
0.7/8.0 cores

$ coder stat cpu --host
0.1/16.0 cores

$ coder stat disk --path $HOME --prefix Ti
0.3/0.9 TiB

$ coder stat disk --path $HOME 
308.3/926.4 GiB

Usage in agent metadata:

  metadata {
    display_name = "Host CPU"
    interval     = 1
    timeout      = 1
    key          = "0_host_cpu"
    script       = "coder stat cpu --host"
  }

  metadata {
    display_name = "Host Memory"
    interval     = 1
    timeout      = 1
    key          = "1_host_mem"
    script       = "coder stat mem --host"
  }

  metadata {
    display_name = "Home Disk"
    interval     = 1
    timeout      = 1
    key          = "2_home_disk"
    script       = "coder stat disk --path $${HOME}"
  }

  metadata {
    display_name = "Container CPU"
    interval     = 1
    timeout      = 1
    key          = "3_container_cpu"
    script       = "coder stat cpu"
  }

  metadata {
    display_name = "Container Memory"
    interval     = 1
    timeout      = 1
    key          = "4_container_cpu"
    script       = "coder stat mem"
  }

What this looks like in practice:

image

Also updated docs and sample docker/kubernetes templates with example usage.

Open question: would it make sense to break the stat command into individual sub-commands (coder stat cpu, coder stat container_mem)?

Partially repairs Fixes #7076

@johnstcn johnstcn self-assigned this Jun 13, 2023
Copy link
Member

@ammario ammario left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • In the style of v1, I think we should show percentages alongside the resource values
  • To make room for percentages and reduce noise, I think we should show at most 3 levels of precision

So 246.5/251.4 GB would be 246 / 251 GB (90%)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy that you split a lot of this logic into its own package.

@bpmct
Copy link
Member

bpmct commented Jun 14, 2023

This is AWESOME! How does coder stat work if run on a VM?

@johnstcn
Copy link
Member Author

johnstcn commented Jun 14, 2023

In the style of v1, I think we should show percentages alongside the resource values
To make room for percentages and reduce noise, I think we should show at most 3 levels of precision
So 246.5/251.4 GB would be 246 / 251 GB (90%)

  1. Isn't that 0 levels of precision?
  2. For quantities that are genenerally in the region of 10^1 - 10^2 (such as cores), such precision isn't really useful. For example, 2/8 cores (36%).

I'm in favour of percentages, agree with limiting precision up to a point.

@johnstcn
Copy link
Member Author

This is AWESOME! How does coder stat work if run on a VM?

There's no difference from its perspective between running in a VM and running on a real piece of metal.

@ammario
Copy link
Member

ammario commented Jun 14, 2023

2. For quantities that are genenerally in the region of 10^1 - 10^2 (such as cores), such precision isn't really useful. For example, 2/8 cores (36%).

Precision may not be the right word, I guess I just mean the number of numbers shown. 2.23 223 or 22.3 would all be fine.

@matifali
Copy link
Member

  1. For quantities that are genenerally in the region of 10^1 - 10^2 (such as cores), such precision isn't really useful. For example, 2/8 cores (36%).

Precision may not be the right word, I guess I just mean the number of numbers shown. 2.23 223 or 22.3 would all be fine.

The number of significant figures. I agree with showing 3 at max. for cores that can be limited to 2.

Comment on lines +50 to +56
// If the unit prefixes of the used and total values are different,
// display the used value's prefix to avoid confusion.
if usedPrefix != totalPrefix || totalDisplay == "" {
_, _ = sb.WriteString(" ")
_, _ = sb.WriteString(usedPrefix)
_, _ = sb.WriteString(r.Unit)
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

review: this means you will see output like 16.7 mcores/64 cores (0%) or 1 B/100 TB (0%). I investigated scaling to use the same units, but this was non-trivial.

@johnstcn johnstcn requested a review from ammario June 15, 2023 15:30
@ammario ammario dismissed their stale review June 15, 2023 16:10

I don't have enough time today to give the code a good review

@mtojek mtojek self-requested a review June 19, 2023 11:03
Copy link
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job!

@bpmct
Copy link
Member

bpmct commented Jun 19, 2023

Partially repairs #7076

Is there more to be done after this PR?

@ammario ammario removed their request for review June 19, 2023 19:21
@johnstcn
Copy link
Member Author

Partially repairs #7076

Is there more to be done after this PR?

I was originally intending to update the templates and documentation separately, but eneded up doing it here. So, no.

@mtojek
Copy link
Member

mtojek commented Jun 20, 2023

I synced with @johnstcn today. I'm going to merge this PR.

@mtojek mtojek merged commit d6f8bd7 into main Jun 20, 2023
@mtojek mtojek deleted the cj/coder-stat branch June 20, 2023 09:16
@github-actions github-actions bot locked and limited conversation to collaborators Jun 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

agent metadata: add coder stat to identify Kubernetes cgroup usage
6 participants