Metrics now have expiration if not updated

This commit is contained in:
Jan Lošťák
2025-02-22 21:24:03 +01:00
parent 2ed310eef7
commit f78df9d3e3
10 changed files with 455 additions and 232 deletions

View File

@@ -1,30 +1,35 @@
package metrics
import (
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"lostak.dev/pve-exporter/proxmox"
)
// PVE SDN state collector.
type PveSdnCollector struct {
apiClient *proxmox.PveApiClient // PVE API client instance.
registry *TTLRegistry // TTL metrics registry.
state *prometheus.GaugeVec // SDN state prometheus gauge.
state *TTLGaugeVec // SDN state prometheus gauge.
}
// Create new instance of PVE SDN collector.
func NewPveSdnCollector(apiClient *proxmox.PveApiClient) *PveSdnCollector {
func NewPveSdnCollector(apiClient *proxmox.PveApiClient, registry *TTLRegistry) *PveSdnCollector {
c := PveSdnCollector{apiClient: apiClient}
c.registry = registry
// SDN Up state.
c.state = promauto.NewGaugeVec(
c.state = NewTTLGaugeVec(
prometheus.GaugeOpts{
Name: "pve_sdn_state",
Help: "Node software defined network state.",
},
[]string{"cluster", "node", "sdn", "sdn_id"},
1*time.Minute,
)
c.registry.Register(c.state)
return &c
}
@@ -41,8 +46,6 @@ func (c *PveSdnCollector) CollectMetrics() error {
return err
}
c.state.Reset()
for _, node := range cluster.NodeStatuses {
sdns := resources.FindNodeSDN(node.Name)
if len(*sdns) > 0 {