Skip to content

Commit

Permalink
Merge pull request #51 from Starttoaster/vm-template-identification
Browse files Browse the repository at this point in the history
Correctly identify VM templates by ID
  • Loading branch information
Starttoaster authored Aug 17, 2024
2 parents b8b707b + 4412e57 commit 3f58287
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions internal/prometheus/virtualmachine.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package prometheus

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

"github.com/starttoaster/proxmox-exporter/internal/logger"

"github.com/prometheus/client_golang/prometheus"
proxmox "github.com/starttoaster/go-proxmox"
)
Expand All @@ -23,23 +24,23 @@ func (c *Collector) collectVirtualMachineMetrics(ch chan<- prometheus.Metric, cl
var vmIsTemplate bool
if clusterResources != nil {
for _, res := range clusterResources.Data {
var name string
if res.Name != nil {
name = *res.Name
var id proxmox.IntOrString
if res.VMID != nil {
id = *res.VMID
}
var template int
if res.Template != nil {
template = *res.Template
}
if vm.Name == name && template == 1 {
if vm.VMID == id && template == 1 {
vmIsTemplate = true
}
}
}

// Don't collect VM metrics on templates
if vmIsTemplate {
logger.Logger.Debug("excluding VM from collecting metrics because it is a template.", "name", vm.Name)
logger.Logger.Debug("excluding VM from collecting metrics because it is a template.", "name", vm.Name, "ID", vm.VMID)
continue
}

Expand Down

0 comments on commit 3f58287

Please sign in to comment.