71 lines
1.5 KiB
Go
71 lines
1.5 KiB
Go
package metrics
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"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 *TTLGaugeVec // SDN state prometheus gauge.
|
|
}
|
|
|
|
// Create new instance of PVE SDN collector.
|
|
func NewPveSdnCollector(apiClient *proxmox.PveApiClient, registry *TTLRegistry) *PveSdnCollector {
|
|
c := PveSdnCollector{apiClient: apiClient}
|
|
c.registry = registry
|
|
|
|
// SDN Up state.
|
|
c.state = NewTTLGaugeVec(
|
|
prometheus.GaugeOpts{
|
|
Name: "pve_sdn_state",
|
|
Help: "Node software defined network state.",
|
|
},
|
|
[]string{"cluster", "node", "sdn", "sdn_id"},
|
|
5*time.Minute,
|
|
)
|
|
c.registry.Register(c.state)
|
|
|
|
return &c
|
|
}
|
|
|
|
// PveMetricsCollector interface implementation.
|
|
func (c *PveSdnCollector) CollectMetrics() error {
|
|
cluster, err := c.apiClient.GetClusterStatus()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
resources, err := c.apiClient.GetClusterResources()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, node := range cluster.NodeStatuses {
|
|
sdns := resources.FindNodeSDN(node.Name)
|
|
if len(*sdns) > 0 {
|
|
for _, sdn := range *sdns {
|
|
labels := prometheus.Labels{
|
|
"cluster": cluster.GetClusterName(),
|
|
"node": node.Name,
|
|
"sdn": sdn.SDN,
|
|
"sdn_id": sdn.ID,
|
|
}
|
|
|
|
c.state.With(labels).Set(sdn.GetStatusNumeric())
|
|
}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// PveMetricsCollector interface implementation.
|
|
func (c *PveSdnCollector) GetName() string {
|
|
return "SDN"
|
|
}
|