mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-03-02 00:26:35 +00:00
mscluster: fix cluster and network sub collectors (#1759)
Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
This commit is contained in:
@@ -8,13 +8,22 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/alecthomas/kingpin/v2"
|
"github.com/alecthomas/kingpin/v2"
|
||||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "mscluster"
|
const (
|
||||||
|
Name = "mscluster"
|
||||||
|
|
||||||
|
subCollectorCluster = "cluster"
|
||||||
|
subCollectorNetwork = "network"
|
||||||
|
subCollectorNode = "node"
|
||||||
|
subCollectorResource = "resource"
|
||||||
|
subCollectorResourceGroup = "resourcegroup"
|
||||||
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
CollectorsEnabled []string `yaml:"collectors_enabled"`
|
CollectorsEnabled []string `yaml:"collectors_enabled"`
|
||||||
@@ -22,11 +31,11 @@ type Config struct {
|
|||||||
|
|
||||||
var ConfigDefaults = Config{
|
var ConfigDefaults = Config{
|
||||||
CollectorsEnabled: []string{
|
CollectorsEnabled: []string{
|
||||||
"cluster",
|
subCollectorCluster,
|
||||||
"network",
|
subCollectorNetwork,
|
||||||
"node",
|
subCollectorNode,
|
||||||
"resource",
|
subCollectorResource,
|
||||||
"resourcegroup",
|
subCollectorResourceGroup,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,27 +108,39 @@ func (c *Collector) Build(_ *slog.Logger, miSession *mi.Session) error {
|
|||||||
|
|
||||||
c.miSession = miSession
|
c.miSession = miSession
|
||||||
|
|
||||||
if slices.Contains(c.config.CollectorsEnabled, "cluster") {
|
errs := make([]error, 0, 5)
|
||||||
c.buildCluster()
|
|
||||||
|
if slices.Contains(c.config.CollectorsEnabled, subCollectorCluster) {
|
||||||
|
if err := c.buildCluster(); err != nil {
|
||||||
|
errs = append(errs, fmt.Errorf("failed to build cluster collector: %w", err))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if slices.Contains(c.config.CollectorsEnabled, "network") {
|
if slices.Contains(c.config.CollectorsEnabled, subCollectorNetwork) {
|
||||||
c.buildNetwork()
|
if err := c.buildNetwork(); err != nil {
|
||||||
|
errs = append(errs, fmt.Errorf("failed to build network collector: %w", err))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if slices.Contains(c.config.CollectorsEnabled, "node") {
|
if slices.Contains(c.config.CollectorsEnabled, subCollectorNode) {
|
||||||
c.buildNode()
|
if err := c.buildNode(); err != nil {
|
||||||
|
errs = append(errs, fmt.Errorf("failed to build node collector: %w", err))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if slices.Contains(c.config.CollectorsEnabled, "resource") {
|
if slices.Contains(c.config.CollectorsEnabled, subCollectorResource) {
|
||||||
c.buildResource()
|
if err := c.buildResource(); err != nil {
|
||||||
|
errs = append(errs, fmt.Errorf("failed to build resource collector: %w", err))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if slices.Contains(c.config.CollectorsEnabled, "resourcegroup") {
|
if slices.Contains(c.config.CollectorsEnabled, subCollectorResourceGroup) {
|
||||||
c.buildResourceGroup()
|
if err := c.buildResourceGroup(); err != nil {
|
||||||
|
errs = append(errs, fmt.Errorf("failed to build resource group collector: %w", err))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return errors.Join(errs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
@@ -129,40 +150,73 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
errCh := make(chan error, 5)
|
||||||
err error
|
|
||||||
errs []error
|
|
||||||
nodeNames []string
|
|
||||||
)
|
|
||||||
|
|
||||||
if slices.Contains(c.config.CollectorsEnabled, "cluster") {
|
wg := sync.WaitGroup{}
|
||||||
if err = c.collectCluster(ch); err != nil {
|
wg.Add(5)
|
||||||
errs = append(errs, fmt.Errorf("failed to collect cluster metrics: %w", err))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if slices.Contains(c.config.CollectorsEnabled, "network") {
|
go func() {
|
||||||
if err = c.collectNetwork(ch); err != nil {
|
defer wg.Done()
|
||||||
errs = append(errs, fmt.Errorf("failed to collect network metrics: %w", err))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if slices.Contains(c.config.CollectorsEnabled, "node") {
|
if slices.Contains(c.config.CollectorsEnabled, subCollectorCluster) {
|
||||||
if nodeNames, err = c.collectNode(ch); err != nil {
|
if err := c.collectCluster(ch); err != nil {
|
||||||
errs = append(errs, fmt.Errorf("failed to collect node metrics: %w", err))
|
errCh <- fmt.Errorf("failed to collect cluster metrics: %w", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}()
|
||||||
|
|
||||||
if slices.Contains(c.config.CollectorsEnabled, "resource") {
|
go func() {
|
||||||
if err = c.collectResource(ch, nodeNames); err != nil {
|
defer wg.Done()
|
||||||
errs = append(errs, fmt.Errorf("failed to collect resource metrics: %w", err))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if slices.Contains(c.config.CollectorsEnabled, "resourcegroup") {
|
if slices.Contains(c.config.CollectorsEnabled, subCollectorNetwork) {
|
||||||
if err = c.collectResourceGroup(ch, nodeNames); err != nil {
|
if err := c.collectNetwork(ch); err != nil {
|
||||||
errs = append(errs, fmt.Errorf("failed to collect resource group metrics: %w", err))
|
errCh <- fmt.Errorf("failed to collect network metrics: %w", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
|
||||||
|
nodeNames := make([]string, 0)
|
||||||
|
|
||||||
|
if slices.Contains(c.config.CollectorsEnabled, subCollectorNode) {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
nodeNames, err = c.collectNode(ch)
|
||||||
|
if err != nil {
|
||||||
|
errCh <- fmt.Errorf("failed to collect node metrics: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
|
||||||
|
if slices.Contains(c.config.CollectorsEnabled, subCollectorResource) {
|
||||||
|
if err := c.collectResource(ch, nodeNames); err != nil {
|
||||||
|
errCh <- fmt.Errorf("failed to collect resource metrics: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
|
||||||
|
if slices.Contains(c.config.CollectorsEnabled, subCollectorResourceGroup) {
|
||||||
|
if err := c.collectResourceGroup(ch, nodeNames); err != nil {
|
||||||
|
errCh <- fmt.Errorf("failed to collect resource group metrics: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}()
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
|
close(errCh)
|
||||||
|
|
||||||
|
errs := make([]error, 0, 5)
|
||||||
|
|
||||||
|
for err := range errCh {
|
||||||
|
errs = append(errs, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return errors.Join(errs...)
|
return errors.Join(errs...)
|
||||||
|
|||||||
@@ -7,13 +7,14 @@ import (
|
|||||||
|
|
||||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||||
"github.com/prometheus-community/windows_exporter/internal/utils"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const nameCluster = Name + "_cluster"
|
const nameCluster = Name + "_cluster"
|
||||||
|
|
||||||
type collectorCluster struct {
|
type collectorCluster struct {
|
||||||
|
clusterMIQuery mi.Query
|
||||||
|
|
||||||
clusterAddEvictDelay *prometheus.Desc
|
clusterAddEvictDelay *prometheus.Desc
|
||||||
clusterAdminAccessPoint *prometheus.Desc
|
clusterAdminAccessPoint *prometheus.Desc
|
||||||
clusterAutoAssignNodeSite *prometheus.Desc
|
clusterAutoAssignNodeSite *prometheus.Desc
|
||||||
@@ -177,7 +178,14 @@ type msClusterCluster struct {
|
|||||||
WitnessRestartInterval uint `mi:"WitnessRestartInterval"`
|
WitnessRestartInterval uint `mi:"WitnessRestartInterval"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) buildCluster() {
|
func (c *Collector) buildCluster() error {
|
||||||
|
clusterMIQuery, err := mi.NewQuery("SELECT * FROM MSCluster_Cluster")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create WMI query: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.clusterMIQuery = clusterMIQuery
|
||||||
|
|
||||||
c.clusterAddEvictDelay = prometheus.NewDesc(
|
c.clusterAddEvictDelay = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, nameCluster, "add_evict_delay"),
|
prometheus.BuildFQName(types.Namespace, nameCluster, "add_evict_delay"),
|
||||||
"Provides access to the cluster's AddEvictDelay property, which is the number a seconds that a new node is delayed after an eviction of another node.",
|
"Provides access to the cluster's AddEvictDelay property, which is the number a seconds that a new node is delayed after an eviction of another node.",
|
||||||
@@ -640,11 +648,13 @@ func (c *Collector) buildCluster() {
|
|||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collectCluster(ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectCluster(ch chan<- prometheus.Metric) error {
|
||||||
var dst []msClusterCluster
|
var dst []msClusterCluster
|
||||||
if err := c.miSession.Query(&dst, mi.NamespaceRootMSCluster, utils.Must(mi.NewQuery("SELECT * MSCluster_Cluster"))); err != nil {
|
if err := c.miSession.Query(&dst, mi.NamespaceRootMSCluster, c.clusterMIQuery); err != nil {
|
||||||
return fmt.Errorf("WMI query failed: %w", err)
|
return fmt.Errorf("WMI query failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,13 +7,14 @@ import (
|
|||||||
|
|
||||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||||
"github.com/prometheus-community/windows_exporter/internal/utils"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const nameNetwork = Name + "_network"
|
const nameNetwork = Name + "_network"
|
||||||
|
|
||||||
type collectorNetwork struct {
|
type collectorNetwork struct {
|
||||||
|
networkMIQuery mi.Query
|
||||||
|
|
||||||
networkCharacteristics *prometheus.Desc
|
networkCharacteristics *prometheus.Desc
|
||||||
networkFlags *prometheus.Desc
|
networkFlags *prometheus.Desc
|
||||||
networkMetric *prometheus.Desc
|
networkMetric *prometheus.Desc
|
||||||
@@ -33,7 +34,14 @@ type msClusterNetwork struct {
|
|||||||
State uint `mi:"State"`
|
State uint `mi:"State"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) buildNetwork() {
|
func (c *Collector) buildNetwork() error {
|
||||||
|
networkMIQuery, err := mi.NewQuery("SELECT * FROM MSCluster_Network")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create WMI query: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.networkMIQuery = networkMIQuery
|
||||||
|
|
||||||
c.networkCharacteristics = prometheus.NewDesc(
|
c.networkCharacteristics = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, nameNetwork, "characteristics"),
|
prometheus.BuildFQName(types.Namespace, nameNetwork, "characteristics"),
|
||||||
"Provides the characteristics of the network.",
|
"Provides the characteristics of the network.",
|
||||||
@@ -64,6 +72,8 @@ func (c *Collector) buildNetwork() {
|
|||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
@@ -71,7 +81,7 @@ func (c *Collector) buildNetwork() {
|
|||||||
func (c *Collector) collectNetwork(ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectNetwork(ch chan<- prometheus.Metric) error {
|
||||||
var dst []msClusterNetwork
|
var dst []msClusterNetwork
|
||||||
|
|
||||||
if err := c.miSession.Query(&dst, mi.NamespaceRootMSCluster, utils.Must(mi.NewQuery("SELECT * MSCluster_Node"))); err != nil {
|
if err := c.miSession.Query(&dst, mi.NamespaceRootMSCluster, c.networkMIQuery); err != nil {
|
||||||
return fmt.Errorf("WMI query failed: %w", err)
|
return fmt.Errorf("WMI query failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,13 +7,14 @@ import (
|
|||||||
|
|
||||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||||
"github.com/prometheus-community/windows_exporter/internal/utils"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const nameNode = Name + "_node"
|
const nameNode = Name + "_node"
|
||||||
|
|
||||||
type collectorNode struct {
|
type collectorNode struct {
|
||||||
|
nodeMIQuery mi.Query
|
||||||
|
|
||||||
nodeBuildNumber *prometheus.Desc
|
nodeBuildNumber *prometheus.Desc
|
||||||
nodeCharacteristics *prometheus.Desc
|
nodeCharacteristics *prometheus.Desc
|
||||||
nodeDetectedCloudPlatform *prometheus.Desc
|
nodeDetectedCloudPlatform *prometheus.Desc
|
||||||
@@ -51,7 +52,14 @@ type msClusterNode struct {
|
|||||||
StatusInformation uint `mi:"StatusInformation"`
|
StatusInformation uint `mi:"StatusInformation"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) buildNode() {
|
func (c *Collector) buildNode() error {
|
||||||
|
nodeMIQuery, err := mi.NewQuery("SELECT * FROM MSCluster_Node")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create WMI query: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.nodeMIQuery = nodeMIQuery
|
||||||
|
|
||||||
c.nodeBuildNumber = prometheus.NewDesc(
|
c.nodeBuildNumber = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, nameNode, "build_number"),
|
prometheus.BuildFQName(types.Namespace, nameNode, "build_number"),
|
||||||
"Provides access to the node's BuildNumber property.",
|
"Provides access to the node's BuildNumber property.",
|
||||||
@@ -136,6 +144,8 @@ func (c *Collector) buildNode() {
|
|||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
@@ -143,7 +153,7 @@ func (c *Collector) buildNode() {
|
|||||||
func (c *Collector) collectNode(ch chan<- prometheus.Metric) ([]string, error) {
|
func (c *Collector) collectNode(ch chan<- prometheus.Metric) ([]string, error) {
|
||||||
var dst []msClusterNode
|
var dst []msClusterNode
|
||||||
|
|
||||||
if err := c.miSession.Query(&dst, mi.NamespaceRootMSCluster, utils.Must(mi.NewQuery("SELECT * FROM MSCluster_Node"))); err != nil {
|
if err := c.miSession.Query(&dst, mi.NamespaceRootMSCluster, c.nodeMIQuery); err != nil {
|
||||||
return nil, fmt.Errorf("WMI query failed: %w", err)
|
return nil, fmt.Errorf("WMI query failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,13 +7,14 @@ import (
|
|||||||
|
|
||||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||||
"github.com/prometheus-community/windows_exporter/internal/utils"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const nameResource = Name + "_resource"
|
const nameResource = Name + "_resource"
|
||||||
|
|
||||||
type collectorResource struct {
|
type collectorResource struct {
|
||||||
|
resourceMIQuery mi.Query
|
||||||
|
|
||||||
resourceCharacteristics *prometheus.Desc
|
resourceCharacteristics *prometheus.Desc
|
||||||
resourceDeadlockTimeout *prometheus.Desc
|
resourceDeadlockTimeout *prometheus.Desc
|
||||||
resourceEmbeddedFailureAction *prometheus.Desc
|
resourceEmbeddedFailureAction *prometheus.Desc
|
||||||
@@ -59,7 +60,14 @@ type msClusterResource struct {
|
|||||||
Subclass uint `mi:"Subclass"`
|
Subclass uint `mi:"Subclass"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) buildResource() {
|
func (c *Collector) buildResource() error {
|
||||||
|
resourceMIQuery, err := mi.NewQuery("SELECT * FROM MSCluster_Resource")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create WMI query: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.resourceMIQuery = resourceMIQuery
|
||||||
|
|
||||||
c.resourceCharacteristics = prometheus.NewDesc(
|
c.resourceCharacteristics = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, nameResource, "characteristics"),
|
prometheus.BuildFQName(types.Namespace, nameResource, "characteristics"),
|
||||||
"Provides the characteristics of the object.",
|
"Provides the characteristics of the object.",
|
||||||
@@ -168,6 +176,8 @@ func (c *Collector) buildResource() {
|
|||||||
[]string{"type", "owner_group", "name"},
|
[]string{"type", "owner_group", "name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
@@ -175,7 +185,7 @@ func (c *Collector) buildResource() {
|
|||||||
func (c *Collector) collectResource(ch chan<- prometheus.Metric, nodeNames []string) error {
|
func (c *Collector) collectResource(ch chan<- prometheus.Metric, nodeNames []string) error {
|
||||||
var dst []msClusterResource
|
var dst []msClusterResource
|
||||||
|
|
||||||
if err := c.miSession.Query(&dst, mi.NamespaceRootMSCluster, utils.Must(mi.NewQuery("SELECT * FROM MSCluster_Resource"))); err != nil {
|
if err := c.miSession.Query(&dst, mi.NamespaceRootMSCluster, c.resourceMIQuery); err != nil {
|
||||||
return fmt.Errorf("WMI query failed: %w", err)
|
return fmt.Errorf("WMI query failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,13 +7,14 @@ import (
|
|||||||
|
|
||||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||||
"github.com/prometheus-community/windows_exporter/internal/utils"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const nameResourceGroup = Name + "_resourcegroup"
|
const nameResourceGroup = Name + "_resourcegroup"
|
||||||
|
|
||||||
type collectorResourceGroup struct {
|
type collectorResourceGroup struct {
|
||||||
|
resourceGroupMIQuery mi.Query
|
||||||
|
|
||||||
resourceGroupAutoFailbackType *prometheus.Desc
|
resourceGroupAutoFailbackType *prometheus.Desc
|
||||||
resourceGroupCharacteristics *prometheus.Desc
|
resourceGroupCharacteristics *prometheus.Desc
|
||||||
resourceGroupColdStartSetting *prometheus.Desc
|
resourceGroupColdStartSetting *prometheus.Desc
|
||||||
@@ -51,7 +52,14 @@ type msClusterResourceGroup struct {
|
|||||||
State uint `mi:"State"`
|
State uint `mi:"State"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) buildResourceGroup() {
|
func (c *Collector) buildResourceGroup() error {
|
||||||
|
resourceGroupMIQuery, err := mi.NewQuery("SELECT * FROM MSCluster_ResourceGroup")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create WMI query: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.resourceGroupMIQuery = resourceGroupMIQuery
|
||||||
|
|
||||||
c.resourceGroupAutoFailbackType = prometheus.NewDesc(
|
c.resourceGroupAutoFailbackType = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, nameResourceGroup, "auto_failback_type"),
|
prometheus.BuildFQName(types.Namespace, nameResourceGroup, "auto_failback_type"),
|
||||||
"Provides access to the group's AutoFailbackType property.",
|
"Provides access to the group's AutoFailbackType property.",
|
||||||
@@ -142,6 +150,8 @@ func (c *Collector) buildResourceGroup() {
|
|||||||
[]string{"name"},
|
[]string{"name"},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
@@ -149,7 +159,7 @@ func (c *Collector) buildResourceGroup() {
|
|||||||
func (c *Collector) collectResourceGroup(ch chan<- prometheus.Metric, nodeNames []string) error {
|
func (c *Collector) collectResourceGroup(ch chan<- prometheus.Metric, nodeNames []string) error {
|
||||||
var dst []msClusterResourceGroup
|
var dst []msClusterResourceGroup
|
||||||
|
|
||||||
if err := c.miSession.Query(&dst, mi.NamespaceRootMSCluster, utils.Must(mi.NewQuery("SELECT * FROM MSCluster_ResourceGroup"))); err != nil {
|
if err := c.miSession.Query(&dst, mi.NamespaceRootMSCluster, c.resourceGroupMIQuery); err != nil {
|
||||||
return fmt.Errorf("WMI query failed: %w", err)
|
return fmt.Errorf("WMI query failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user