start adding hoststats
This commit is contained in:
parent
4b9782bb2a
commit
325d87ba27
1
go.mod
1
go.mod
@ -14,6 +14,7 @@ require (
|
||||
|
||||
require (
|
||||
github.com/go-chi/chi/v5 v5.0.12 // indirect
|
||||
github.com/gofrs/uuid/v5 v5.1.0 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
|
2
go.sum
2
go.sum
@ -7,6 +7,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
|
||||
github.com/go-chi/chi/v5 v5.0.12 h1:9euLV5sTrTNTRUU9POmDUvfxyj6LAABLUcEWO+JJb4s=
|
||||
github.com/go-chi/chi/v5 v5.0.12/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
|
||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/gofrs/uuid/v5 v5.1.0 h1:S5rqVKIigghZTCBKPCw0Y+bXkn26K3TB5mvQq2Ix8dk=
|
||||
github.com/gofrs/uuid/v5 v5.1.0/go.mod h1:CDOjlDMVAtN56jqyRUZh58JT31Tiw7/oQyEXZV+9bD8=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||
|
45
lib/host/stats.go
Normal file
45
lib/host/stats.go
Normal file
@ -0,0 +1,45 @@
|
||||
package host
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"libvirt.org/go/libvirtxml"
|
||||
)
|
||||
|
||||
// Stats for hosts with channels to subscribe to
|
||||
|
||||
// HostStats works as a handler that can be subscribed to.
|
||||
// It runs a go routine that sends Stats via a channel
|
||||
// when subscribed to
|
||||
type HostStats struct {
|
||||
h *Host
|
||||
}
|
||||
|
||||
type Stats struct {
|
||||
Memory NodeMemoryInfo
|
||||
VMs []*libvirtxml.Domain
|
||||
StoragePools []*libvirtxml.StoragePool
|
||||
}
|
||||
|
||||
func (hs *HostStats) Subscribe(parent context.Context, pubto <-chan Stats) error {
|
||||
ctx, cancel := context.WithCancel(parent)
|
||||
go func() {
|
||||
defer cancel()
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
break
|
||||
default:
|
||||
hs.update()
|
||||
}
|
||||
}
|
||||
}()
|
||||
return nil
|
||||
}
|
||||
|
||||
// update runs as a goroutine, and updates host stats
|
||||
func (hs *HostStats) update() {
|
||||
hs.h.memoryInfo()
|
||||
hs.h.getStoragePools()
|
||||
hs.h.getDomainInfo()
|
||||
}
|
@ -1,6 +1,14 @@
|
||||
// Package storagepool provides utilities and data structures in relation to storage pools.
|
||||
// This library uses the libvirt and libvirtxml packages from libvirt.org to implement
|
||||
// wrappers on top of the base library
|
||||
package storagepool
|
||||
|
||||
import "libvirt.org/go/libvirt"
|
||||
import (
|
||||
// log "git.staur.ca/stobbsm/simplelog"
|
||||
// "github.com/gofrs/uuid/v5"
|
||||
"libvirt.org/go/libvirt"
|
||||
// "libvirt.org/go/libvirtxml"
|
||||
)
|
||||
|
||||
var StoragePoolStateMap = map[libvirt.StoragePoolState]string{
|
||||
libvirt.STORAGE_POOL_INACTIVE: "inactive",
|
||||
|
Loading…
Reference in New Issue
Block a user