lima-vm / lima-vm/lima

Monitor guest activity using the agent

Open
#835 4 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Go
Stars
21.9k
Forks
957
Avg merge
2d 6h
Merged PRs (30d)
53

Description

### Description

I am looking for a feature, where I can see the CPU usage and RAM usage of an instance. Preferrably disk usage too, if possible.

However, I could not find this to be easilly accessible in QEMU the same way that it is in VirtualBox or Docker or what have you ?

One workaround that I was considering earlier, would be to run a small program in the guest to output such information.

It would not be as accurate ("inside") as quering the hypervisor ("outside"), but it would be "good enough" for my purposes.

----

I made a proof-of-concept, using [`gopsutil`](https://github.com/shirou/gopsutil). What you do you think about the idea ?

```go
package main

import (
"fmt"
"path/filepath"
"time"

"github.com/shirou/gopsutil/v3/cpu"
"github.com/shirou/gopsutil/v3/disk"
"github.com/shirou/gopsutil/v3/host"
"github.com/shirou/gopsutil/v3/mem"
)

func main() {
_, _ = cpu.Percent(1*time.Second, true)
h, _ := host.Info()
p, _ := disk.Partitions(false)

fmt.Printf("Host: %v\n", h.Hostname)

mountpoint := "/"
for _, part := range p {
device, err := filepath.EvalSymlinks(part.Device)
if err != nil {
continue
}
if part.Fstype == "squashfs" { // skip /snap
continue
}
fmt.Printf("%s %s\n", device, part.Mountpoint)
if device == "/dev/vda1" {
mountpoint = part.Mountpoint
}
}

for {
t := time.Now()
c, _ := cpu.Percent(0, false)
v, _ := mem.VirtualMemory()
d, _ := disk.Usage(mountpoint)

fmt.Printf("%v\n", t.Format(time.RFC3339Nano))
fmt.Printf("Cpu: %.2f%%\n", c[0])
fmt.Printf("Mem: %.2f%%\n", v.UsedPercent)
fmt.Printf("Disk: %.2f%%\n", d.UsedPercent)

time.Sleep(1 * time.Second)
}
}
```

Probably would use JSON lines, rather than text. So that it can be parsed, and graphed, on the lima client side.

* https://github.com/afbjorklund/lima-gui/issues/11

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.