2021-12-06 20:06:43 +00:00
package collector
import (
"github.com/StackExchange/wmi"
"github.com/prometheus/client_golang/prometheus"
)
func init ( ) {
2021-12-22 12:33:52 +00:00
registerCollector ( "mscluster_network" , newMSCluster_NetworkCollector )
2021-12-06 20:06:43 +00:00
}
// A MSCluster_NetworkCollector is a Prometheus collector for WMI MSCluster_Network metrics
type MSCluster_NetworkCollector struct {
Characteristics * prometheus . Desc
Flags * prometheus . Desc
Metric * prometheus . Desc
Role * prometheus . Desc
State * prometheus . Desc
}
func newMSCluster_NetworkCollector ( ) ( Collector , error ) {
const subsystem = "mscluster_network"
return & MSCluster_NetworkCollector {
Characteristics : prometheus . NewDesc (
prometheus . BuildFQName ( Namespace , subsystem , "characteristics" ) ,
2022-01-09 22:28:09 +00:00
"Provides the characteristics of the network." ,
2021-12-06 20:06:43 +00:00
[ ] string { "name" } ,
nil ,
) ,
Flags : prometheus . NewDesc (
prometheus . BuildFQName ( Namespace , subsystem , "flags" ) ,
2022-01-09 22:28:09 +00:00
"Provides access to the flags set for the node. " ,
2021-12-06 20:06:43 +00:00
[ ] string { "name" } ,
nil ,
) ,
Metric : prometheus . NewDesc (
prometheus . BuildFQName ( Namespace , subsystem , "metric" ) ,
2022-01-09 22:28:09 +00:00
"The metric of a cluster network (networks with lower values are used first). If this value is set, then the AutoMetric property is set to false." ,
2021-12-06 20:06:43 +00:00
[ ] string { "name" } ,
nil ,
) ,
Role : prometheus . NewDesc (
prometheus . BuildFQName ( Namespace , subsystem , "role" ) ,
2022-01-09 22:28:09 +00:00
"Provides access to the network's Role property. The Role property describes the role of the network in the cluster. 0: None; 1: Cluster; 2: Client; 3: Both " ,
2021-12-06 20:06:43 +00:00
[ ] string { "name" } ,
nil ,
) ,
State : prometheus . NewDesc (
prometheus . BuildFQName ( Namespace , subsystem , "state" ) ,
2022-01-09 22:28:09 +00:00
"Provides the current state of the network. 1-1: Unknown; 0: Unavailable; 1: Down; 2: Partitioned; 3: Up" ,
2021-12-06 20:06:43 +00:00
[ ] string { "name" } ,
nil ,
) ,
} , nil
}
// MSCluster_Network docs:
2021-12-22 12:42:17 +00:00
// - https://docs.microsoft.com/en-us/previous-versions/windows/desktop/cluswmi/mscluster-network
//
2021-12-06 20:06:43 +00:00
type MSCluster_Network struct {
Name string
Characteristics uint
Flags uint
Metric uint
Role uint
State uint
}
// Collect sends the metric values for each metric
// to the provided prometheus Metric channel.
func ( c * MSCluster_NetworkCollector ) Collect ( ctx * ScrapeContext , ch chan <- prometheus . Metric ) error {
var dst [ ] MSCluster_Network
q := queryAll ( & dst )
if err := wmi . QueryNamespace ( q , & dst , "root/MSCluster" ) ; err != nil {
return err
}
for _ , v := range dst {
ch <- prometheus . MustNewConstMetric (
c . Characteristics ,
prometheus . GaugeValue ,
float64 ( v . Characteristics ) ,
v . Name ,
)
ch <- prometheus . MustNewConstMetric (
c . Flags ,
prometheus . GaugeValue ,
float64 ( v . Flags ) ,
v . Name ,
)
ch <- prometheus . MustNewConstMetric (
c . Metric ,
prometheus . GaugeValue ,
float64 ( v . Metric ) ,
v . Name ,
)
ch <- prometheus . MustNewConstMetric (
c . Role ,
prometheus . GaugeValue ,
float64 ( v . Role ) ,
v . Name ,
)
ch <- prometheus . MustNewConstMetric (
c . State ,
prometheus . GaugeValue ,
float64 ( v . State ) ,
v . Name ,
)
}
return nil
}