Metrics now have expiration if not updated
This commit is contained in:
@@ -2,61 +2,71 @@ package metrics
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
"lostak.dev/pve-exporter/proxmox"
|
||||
)
|
||||
|
||||
// PVE Storage state collector.
|
||||
type PveStorageCollector struct {
|
||||
apiClient *proxmox.PveApiClient // PVE API client instance.
|
||||
registry *TTLRegistry // TTL metrics registry.
|
||||
|
||||
state *prometheus.GaugeVec // Storage state prometheus gauge.
|
||||
total *prometheus.GaugeVec // Storage total bytes prometheus gauge.
|
||||
avail *prometheus.GaugeVec // Storage available bytes prometheus gauge.
|
||||
used *prometheus.GaugeVec // Storage used bytes prometheus gauge.
|
||||
state *TTLGaugeVec // Storage state prometheus gauge.
|
||||
total *TTLGaugeVec // Storage total bytes prometheus gauge.
|
||||
avail *TTLGaugeVec // Storage available bytes prometheus gauge.
|
||||
used *TTLGaugeVec // Storage used bytes prometheus gauge.
|
||||
}
|
||||
|
||||
// Create new instance of PVE SDN collector.
|
||||
func NewPveStorageCollector(apiClient *proxmox.PveApiClient) *PveStorageCollector {
|
||||
func NewPveStorageCollector(apiClient *proxmox.PveApiClient, registry *TTLRegistry) *PveStorageCollector {
|
||||
c := PveStorageCollector{apiClient: apiClient}
|
||||
c.registry = registry
|
||||
|
||||
// Storage state.
|
||||
c.state = promauto.NewGaugeVec(
|
||||
c.state = NewTTLGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "pve_storage_up",
|
||||
Help: "Node storage UP state.",
|
||||
},
|
||||
[]string{"cluster", "node", "storage", "type", "content", "shared"},
|
||||
1*time.Minute,
|
||||
)
|
||||
c.registry.Register(c.state)
|
||||
|
||||
// Storage total bytes.
|
||||
c.total = promauto.NewGaugeVec(
|
||||
c.total = NewTTLGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "pve_storage_total_bytes",
|
||||
Help: "Node storage total capacity in bytes.",
|
||||
},
|
||||
[]string{"cluster", "node", "storage", "type", "content", "shared"},
|
||||
1*time.Minute,
|
||||
)
|
||||
c.registry.Register(c.total)
|
||||
|
||||
// Storage available bytes.
|
||||
c.avail = promauto.NewGaugeVec(
|
||||
c.avail = NewTTLGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "pve_storage_avail_bytes",
|
||||
Help: "Node storage available capacity in bytes.",
|
||||
},
|
||||
[]string{"cluster", "node", "storage", "type", "content", "shared"},
|
||||
1*time.Minute,
|
||||
)
|
||||
c.registry.Register(c.avail)
|
||||
|
||||
// Storage used bytes.
|
||||
c.used = promauto.NewGaugeVec(
|
||||
c.used = NewTTLGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "pve_storage_used_bytes",
|
||||
Help: "Node storage used capacity in bytes.",
|
||||
},
|
||||
[]string{"cluster", "node", "storage", "type", "content", "shared"},
|
||||
1*time.Minute,
|
||||
)
|
||||
c.registry.Register(c.used)
|
||||
|
||||
return &c
|
||||
}
|
||||
@@ -68,11 +78,6 @@ func (c *PveStorageCollector) CollectMetrics() error {
|
||||
return err
|
||||
}
|
||||
|
||||
c.state.Reset()
|
||||
c.total.Reset()
|
||||
c.avail.Reset()
|
||||
c.used.Reset()
|
||||
|
||||
for _, node := range cluster.NodeStatuses {
|
||||
storages, err := c.apiClient.GetNodeStorages(node.Name)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user