Metrics now have expiration if not updated
This commit is contained in:
@@ -1,40 +1,48 @@
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
"lostak.dev/pve-exporter/proxmox"
|
||||
)
|
||||
|
||||
// PVE cluster state collector.
|
||||
type PveClusterStateCollector struct {
|
||||
apiClient *proxmox.PveApiClient // PVE API client instance.
|
||||
registry *TTLRegistry // TTL metrics registry.
|
||||
|
||||
nodes *prometheus.GaugeVec // Count of nodes prometheus gauge.
|
||||
quorate *prometheus.GaugeVec // Cluster quorum state prometheus gauge.
|
||||
nodes *TTLGaugeVec // Count of nodes prometheus gauge.
|
||||
quorate *TTLGaugeVec // Cluster quorum state prometheus gauge.
|
||||
}
|
||||
|
||||
// Create new instance of PVE cluster state collector.
|
||||
func NewPveClusterStateCollector(apiClient *proxmox.PveApiClient) *PveClusterStateCollector {
|
||||
func NewPveClusterStateCollector(apiClient *proxmox.PveApiClient, registry *TTLRegistry) *PveClusterStateCollector {
|
||||
c := PveClusterStateCollector{apiClient: apiClient}
|
||||
c.registry = registry
|
||||
|
||||
// Cluster meta gauge.
|
||||
c.nodes = promauto.NewGaugeVec(
|
||||
c.nodes = NewTTLGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "pve_cluster_nodes",
|
||||
Help: "Cluster nodes count.",
|
||||
},
|
||||
[]string{"cluster"},
|
||||
1*time.Minute,
|
||||
)
|
||||
c.registry.Register(c.nodes)
|
||||
|
||||
// Cluster quorate gauge.
|
||||
c.quorate = promauto.NewGaugeVec(
|
||||
c.quorate = NewTTLGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "pve_cluster_quorate",
|
||||
Help: "Cluster quorum state.",
|
||||
},
|
||||
[]string{"cluster"},
|
||||
1*time.Minute,
|
||||
)
|
||||
c.registry.Register(c.quorate)
|
||||
c.registry.StartCleanupLoop(5 * time.Second)
|
||||
|
||||
return &c
|
||||
}
|
||||
@@ -46,9 +54,6 @@ func (c *PveClusterStateCollector) CollectMetrics() error {
|
||||
return err
|
||||
}
|
||||
|
||||
c.nodes.Reset()
|
||||
c.quorate.Reset()
|
||||
|
||||
l := prometheus.Labels{"cluster": cluster.Name}
|
||||
c.nodes.With(l).Set(float64(cluster.Nodes))
|
||||
c.quorate.With(l).Set(float64(cluster.Quorate))
|
||||
|
||||
Reference in New Issue
Block a user