mi: replace all WMI calls with MI calls (#1700)

This commit is contained in:
Jan-Otto Kröpke
2024-11-03 01:03:34 +01:00
committed by GitHub
parent 582d8dd29c
commit c4f5d58a3e
82 changed files with 2767 additions and 738 deletions

View File

@@ -1,7 +1,11 @@
package mscluster
import (
"fmt"
"github.com/prometheus-community/windows_exporter/internal/mi"
"github.com/prometheus-community/windows_exporter/internal/types"
"github.com/prometheus-community/windows_exporter/internal/utils"
"github.com/prometheus/client_golang/prometheus"
)
@@ -10,13 +14,13 @@ const nameNetwork = Name + "_network"
// msClusterNetwork represents the MSCluster_Network WMI class
// - https://docs.microsoft.com/en-us/previous-versions/windows/desktop/cluswmi/mscluster-network
type msClusterNetwork struct {
Name string
Name string `mi:"Name"`
Characteristics uint
Flags uint
Metric uint
Role uint
State uint
Characteristics uint `mi:"Characteristics"`
Flags uint `mi:"Flags"`
Metric uint `mi:"Metric"`
Role uint `mi:"Role"`
State uint `mi:"State"`
}
func (c *Collector) buildNetwork() {
@@ -57,8 +61,8 @@ func (c *Collector) buildNetwork() {
func (c *Collector) collectNetwork(ch chan<- prometheus.Metric) error {
var dst []msClusterNetwork
if err := c.wmiClient.Query("SELECT * FROM MSCluster_Network", &dst, nil, "root/MSCluster"); err != nil {
return err
if err := c.miSession.Query(&dst, mi.NamespaceRootMSCluster, utils.Must(mi.NewQuery("SELECT * MSCluster_Node"))); err != nil {
return fmt.Errorf("WMI query failed: %w", err)
}
for _, v := range dst {