f-37: prometheus: add vms
All checks were successful
Pre Release Workflow / set-release-target (push) Successful in 1s
Pre Release Workflow / build (agent, amd64, linux) (push) Successful in 1m35s
Pre Release Workflow / build (metadata, amd64, linux) (push) Successful in 1m31s
Pre Release Workflow / upload-scripts (run-dnsmasq-in-netns.sh) (push) Successful in 8s
Pre Release Workflow / prerelease (push) Successful in 10s

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-08-14 01:00:00 +02:00
commit 8d04472ec1
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
2 changed files with 36 additions and 3 deletions

View file

@ -17,6 +17,7 @@ type AgentCollector struct {
db *badger.DB
vpcsTotal *prometheus.Desc
subnetsTotal *prometheus.Desc
vmsTotal *prometheus.Desc
}
func NewAgentCollector(db *badger.DB) *AgentCollector {
@ -32,17 +33,24 @@ func NewAgentCollector(db *badger.DB) *AgentCollector {
"Number of subnets by state.",
[]string{"state"}, nil,
),
vmsTotal: prometheus.NewDesc(
"syonad_vms_total",
"Number of VMs by state.",
[]string{"state"}, nil,
),
}
}
func (c *AgentCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- c.vpcsTotal
ch <- c.subnetsTotal
ch <- c.vmsTotal
}
func (c *AgentCollector) Collect(ch chan<- prometheus.Metric) {
c.collectStates(ch, "vpc/", c.vpcsTotal)
c.collectStates(ch, "subnet/", c.subnetsTotal)
c.collectStates(ch, "vm/", c.vmsTotal)
}
// collectStates counts resources under the given DB prefix by their state value