Initial commit
This commit is contained in:
65
metrics/pve_node_sdn_collector.go
Normal file
65
metrics/pve_node_sdn_collector.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"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.
|
||||
|
||||
state *prometheus.GaugeVec // SDN state prometheus gauge.
|
||||
}
|
||||
|
||||
// Create new instance of PVE SDN collector.
|
||||
func NewPveSdnCollector(apiClient *proxmox.PveApiClient) *PveSdnCollector {
|
||||
c := PveSdnCollector{apiClient: apiClient}
|
||||
|
||||
// SDN Up state.
|
||||
c.state = promauto.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "pve_sdn_state",
|
||||
Help: "Node software defined network state.",
|
||||
},
|
||||
[]string{"cluster", "node", "sdn", "sdn_id"},
|
||||
)
|
||||
|
||||
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"
|
||||
}
|
||||
Reference in New Issue
Block a user