Skip to content

Commit

Permalink
Merge pull request #48 from Starttoaster/handle-vmids
Browse files Browse the repository at this point in the history
Handle Int and String VM IDs
  • Loading branch information
Starttoaster authored Aug 8, 2024
2 parents f3b42ae + c5c91ea commit 147a9d7
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/prometheus/client_golang v1.19.1
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.19.0
github.com/starttoaster/go-proxmox v0.0.2
github.com/starttoaster/go-proxmox v0.0.3
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI=
github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg=
github.com/starttoaster/go-proxmox v0.0.2 h1:4BI2DlIfFTDxUE80DLhshfzDTe/IGXVeQW1HUSdvr+s=
github.com/starttoaster/go-proxmox v0.0.2/go.mod h1:eyvj8nnoKJfwSjXIisLkErTtE2ErEsUHExcjG2zf+mQ=
github.com/starttoaster/go-proxmox v0.0.3 h1:1Z1EYMuNFkACdeYdR7gDOyTwykI74pZl9wi/b5cDi1M=
github.com/starttoaster/go-proxmox v0.0.3/go.mod h1:eyvj8nnoKJfwSjXIisLkErTtE2ErEsUHExcjG2zf+mQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
Expand Down
4 changes: 2 additions & 2 deletions internal/prometheus/lxc.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ func (c *Collector) collectLxcMetrics(ch chan<- prometheus.Metric, node proxmox.
if strings.EqualFold(lxc.Status, "running") {
status = 1.0
}
ch <- prometheus.MustNewConstMetric(c.guestUp, prometheus.GaugeValue, status, node.Node, lxc.Type, lxc.Name, lxc.VMID)
ch <- prometheus.MustNewConstMetric(c.guestUp, prometheus.GaugeValue, status, node.Node, lxc.Type, lxc.Name, string(lxc.VMID))

// Add to LXC aggregate metrics
res.cpusAllocated += lxc.Cpus
res.cpusAllocated += lxc.CPUs
res.memAllocated += lxc.MaxMem
}
return &res
Expand Down
4 changes: 2 additions & 2 deletions internal/prometheus/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ func (c *Collector) collectNode(ch chan<- prometheus.Metric, clusterResources *p
if err != nil {
logger.Logger.Error("failed making request to get node status", "node", node.Node, "error", err.Error())
} else {
resp.clusterCPUs = nodeStatus.Data.CPUInfo.Cpus
resp.clusterCPUs = nodeStatus.Data.CPUInfo.CPUs
resp.clusterMem = nodeStatus.Data.Memory.Total
c.collectNodeVersionMetric(ch, node, nodeStatus.Data)
ch <- prometheus.MustNewConstMetric(c.nodeCPUsTotal, prometheus.GaugeValue, float64(nodeStatus.Data.CPUInfo.Cpus), node.Node)
ch <- prometheus.MustNewConstMetric(c.nodeCPUsTotal, prometheus.GaugeValue, float64(nodeStatus.Data.CPUInfo.CPUs), node.Node)
ch <- prometheus.MustNewConstMetric(c.nodeMemTotal, prometheus.GaugeValue, float64(nodeStatus.Data.Memory.Total), node.Node)
}

Expand Down
5 changes: 2 additions & 3 deletions internal/prometheus/virtualmachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package prometheus

import (
"github.com/starttoaster/proxmox-exporter/internal/logger"
"strconv"
"strings"

"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -49,10 +48,10 @@ func (c *Collector) collectVirtualMachineMetrics(ch chan<- prometheus.Metric, cl
if strings.EqualFold(vm.Status, "running") {
status = 1.0
}
ch <- prometheus.MustNewConstMetric(c.guestUp, prometheus.GaugeValue, status, node.Node, "qemu", vm.Name, strconv.Itoa(vm.VMID))
ch <- prometheus.MustNewConstMetric(c.guestUp, prometheus.GaugeValue, status, node.Node, "qemu", vm.Name, string(vm.VMID))

// Add to VM aggregate metrics
res.cpusAllocated += vm.Cpus
res.cpusAllocated += vm.CPUs
res.memAllocated += vm.MaxMem
}
return &res
Expand Down

0 comments on commit 147a9d7

Please sign in to comment.