feat(proxmox): add LXC container stats endpoint with streaming support

Implement a new API endpoint to retrieve real-time statistics for Proxmox
LXC containers, similar to `docker stats` functionality.

Changes:
- Add `GET /api/v1/proxmox/stats/:node/:vmid` endpoint with HTTP and WebSocket support
- Implement resource polling loop to cache VM metadata every 3 seconds
- Create `LXCStats()` method with streaming (websocket) and single-shot modes
- Format output as: STATUS|CPU%|MEM USAGE/LIMIT|MEM%|NET I/O|BLOCK I/O
- Add `GetResource()` method for efficient VM resource lookup by kind and ID
- Fix task creation bug using correct client reference

Example response:
  running|31.1%|9.6GiB/20GiB|48.87%|4.7GiB/3.3GiB|25GiB/36GiB
This commit is contained in:
yusing
2026-01-25 01:37:13 +08:00
parent c191676565
commit b4646b665f
10 changed files with 477 additions and 11 deletions

View File

@@ -6,7 +6,6 @@ import (
"strings"
"github.com/bytedance/sonic"
"github.com/luthermonson/go-proxmox"
"github.com/yusing/goutils/pool"
)
@@ -19,11 +18,22 @@ type NodeConfig struct {
type Node struct {
name string
id string // likely node/<name>
client *proxmox.Client
client *Client
// statsScriptInitErrs *xsync.Map[int, error]
}
var Nodes = pool.New[*Node]("proxmox_nodes")
func NewNode(client *Client, name, id string) *Node {
return &Node{
name: name,
id: id,
client: client,
// statsScriptInitErrs: xsync.NewMap[int, error](xsync.WithGrowOnly()),
}
}
func AvailableNodeNames() string {
if Nodes.Size() == 0 {
return ""