mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-27 07:06:35 +00:00
mi: replace all WMI calls with MI calls (#1700)
This commit is contained in:
@@ -8,10 +8,10 @@ import (
|
||||
"log/slog"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/perfdata"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
)
|
||||
|
||||
const Name = "ad"
|
||||
@@ -118,7 +118,7 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *wmi.Client) error {
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
|
||||
counters := []string{
|
||||
abANRPerSec,
|
||||
abBrowsesPerSec,
|
||||
|
||||
@@ -8,12 +8,12 @@ import (
|
||||
"log/slog"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/perfdata"
|
||||
v1 "github.com/prometheus-community/windows_exporter/internal/perfdata/v1"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus-community/windows_exporter/internal/utils"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
)
|
||||
|
||||
const Name = "adcs"
|
||||
@@ -74,7 +74,7 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *wmi.Client) error {
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
|
||||
if utils.PDHEnabled() {
|
||||
counters := []string{
|
||||
requestsPerSecond,
|
||||
|
||||
@@ -11,12 +11,12 @@ import (
|
||||
"slices"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/perfdata"
|
||||
v1 "github.com/prometheus-community/windows_exporter/internal/perfdata/v1"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus-community/windows_exporter/internal/utils"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
)
|
||||
|
||||
const Name = "adfs"
|
||||
@@ -107,7 +107,7 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *wmi.Client) error {
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
|
||||
if utils.PDHEnabled() {
|
||||
counters := []string{
|
||||
adLoginConnectionFailures,
|
||||
|
||||
4
internal/collector/cache/cache.go
vendored
4
internal/collector/cache/cache.go
vendored
@@ -8,13 +8,13 @@ import (
|
||||
"log/slog"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/perfdata"
|
||||
"github.com/prometheus-community/windows_exporter/internal/perfdata/perftypes"
|
||||
v1 "github.com/prometheus-community/windows_exporter/internal/perfdata/v1"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus-community/windows_exporter/internal/utils"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
)
|
||||
|
||||
const Name = "cache"
|
||||
@@ -92,7 +92,7 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *wmi.Client) error {
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
|
||||
if utils.PDHEnabled() {
|
||||
counters := []string{
|
||||
asyncCopyReadsTotal,
|
||||
|
||||
@@ -10,10 +10,10 @@ import (
|
||||
|
||||
"github.com/Microsoft/hcsshim"
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/perfdata/perftypes"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
)
|
||||
|
||||
const Name = "container"
|
||||
@@ -86,7 +86,7 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *wmi.Client) error {
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
|
||||
c.containerAvailable = prometheus.NewDesc(
|
||||
prometheus.BuildFQName(types.Namespace, Name, "available"),
|
||||
"Available",
|
||||
|
||||
@@ -8,12 +8,12 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/perfdata"
|
||||
v1 "github.com/prometheus-community/windows_exporter/internal/perfdata/v1"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus-community/windows_exporter/internal/utils"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
)
|
||||
|
||||
const Name = "cpu"
|
||||
@@ -83,7 +83,7 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *wmi.Client) error {
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
|
||||
if utils.PDHEnabled() {
|
||||
counters := []string{
|
||||
c1TimeSeconds,
|
||||
|
||||
@@ -4,14 +4,15 @@ package cpu_info
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
)
|
||||
|
||||
const Name = "cpu_info"
|
||||
@@ -22,9 +23,9 @@ var ConfigDefaults = Config{}
|
||||
|
||||
// A Collector is a Prometheus Collector for a few WMI metrics in Win32_Processor.
|
||||
type Collector struct {
|
||||
config Config
|
||||
|
||||
wmiClient *wmi.Client
|
||||
config Config
|
||||
miSession *mi.Session
|
||||
miQuery mi.Query
|
||||
|
||||
cpuInfo *prometheus.Desc
|
||||
cpuCoreCount *prometheus.Desc
|
||||
@@ -63,12 +64,19 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(_ *slog.Logger, wmiClient *wmi.Client) error {
|
||||
if wmiClient == nil || wmiClient.SWbemServicesClient == nil {
|
||||
return errors.New("wmiClient or SWbemServicesClient is nil")
|
||||
func (c *Collector) Build(_ *slog.Logger, miSession *mi.Session) error {
|
||||
if miSession == nil {
|
||||
return errors.New("miSession is nil")
|
||||
}
|
||||
|
||||
c.wmiClient = wmiClient
|
||||
miQuery, err := mi.NewQuery("SELECT Architecture, DeviceId, Description, Family, L2CacheSize, L3CacheSize, Name, ThreadCount, NumberOfCores, NumberOfEnabledCore, NumberOfLogicalProcessors FROM Win32_Processor")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create WMI query: %w", err)
|
||||
}
|
||||
|
||||
c.miQuery = miQuery
|
||||
c.miSession = miSession
|
||||
|
||||
c.cpuInfo = prometheus.NewDesc(
|
||||
prometheus.BuildFQName(types.Namespace, "", Name),
|
||||
"Labelled CPU information as provided by Win32_Processor",
|
||||
@@ -133,18 +141,20 @@ func (c *Collector) Build(_ *slog.Logger, wmiClient *wmi.Client) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type win32Processor struct {
|
||||
Architecture uint32
|
||||
DeviceID string
|
||||
Description string
|
||||
Family uint16
|
||||
L2CacheSize uint32
|
||||
L3CacheSize uint32
|
||||
Name string
|
||||
ThreadCount uint32
|
||||
NumberOfCores uint32
|
||||
NumberOfEnabledCore uint32
|
||||
NumberOfLogicalProcessors uint32
|
||||
type miProcessor struct {
|
||||
Architecture uint32 `mi:"Architecture"`
|
||||
DeviceID string `mi:"DeviceID"`
|
||||
Description string `mi:"Description"`
|
||||
Family uint16 `mi:"Family"`
|
||||
L2CacheSize uint32 `mi:"L2CacheSize"`
|
||||
L3CacheSize uint32 `mi:"L3CacheSize"`
|
||||
Name string `mi:"Name"`
|
||||
ThreadCount uint32 `mi:"ThreadCount"`
|
||||
NumberOfCores uint32 `mi:"NumberOfCores"`
|
||||
NumberOfEnabledCore uint32 `mi:"NumberOfEnabledCore"`
|
||||
NumberOfLogicalProcessors uint32 `mi:"NumberOfLogicalProcessors"`
|
||||
|
||||
Total int
|
||||
}
|
||||
|
||||
// Collect sends the metric values for each metric
|
||||
@@ -163,16 +173,9 @@ func (c *Collector) Collect(_ *types.ScrapeContext, logger *slog.Logger, ch chan
|
||||
}
|
||||
|
||||
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||
var dst []win32Processor
|
||||
// We use a static query here because the provided methods in wmi.go all issue a SELECT *;
|
||||
// This results in the time-consuming LoadPercentage field being read which seems to measure each CPU
|
||||
// serially over a 1 second interval, so the scrape time is at least 1s * num_sockets
|
||||
if err := c.wmiClient.Query("SELECT Architecture, DeviceId, Description, Family, L2CacheSize, L3CacheSize, Name, ThreadCount, NumberOfCores, NumberOfEnabledCore, NumberOfLogicalProcessors FROM Win32_Processor", &dst); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(dst) == 0 {
|
||||
return errors.New("WMI query returned empty result set")
|
||||
var dst []miProcessor
|
||||
if err := c.miSession.Query(&dst, mi.NamespaceRootCIMv2, c.miQuery); err != nil {
|
||||
return fmt.Errorf("WMI query failed: %w", err)
|
||||
}
|
||||
|
||||
// Some CPUs end up exposing trailing spaces for certain strings, so clean them up
|
||||
|
||||
@@ -7,9 +7,9 @@ import (
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/headers/sysinfoapi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
)
|
||||
|
||||
const Name = "cs"
|
||||
@@ -61,7 +61,7 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(logger *slog.Logger, _ *wmi.Client) error {
|
||||
func (c *Collector) Build(logger *slog.Logger, _ *mi.Session) error {
|
||||
logger.Warn("The cs collector is deprecated and will be removed in a future release. " +
|
||||
"Logical processors has been moved to cpu_info collector. " +
|
||||
"Physical memory has been moved to memory collector. " +
|
||||
|
||||
@@ -10,12 +10,12 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/perfdata"
|
||||
v1 "github.com/prometheus-community/windows_exporter/internal/perfdata/v1"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus-community/windows_exporter/internal/utils"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
)
|
||||
|
||||
const Name = "dfsr"
|
||||
@@ -167,7 +167,7 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(logger *slog.Logger, _ *wmi.Client) error {
|
||||
func (c *Collector) Build(logger *slog.Logger, _ *mi.Session) error {
|
||||
logger = logger.With(slog.String("collector", Name))
|
||||
|
||||
logger.Info("dfsr collector is in an experimental state! Metrics for this collector have not been tested.")
|
||||
|
||||
@@ -8,13 +8,13 @@ import (
|
||||
"log/slog"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/perfdata"
|
||||
"github.com/prometheus-community/windows_exporter/internal/perfdata/perftypes"
|
||||
v1 "github.com/prometheus-community/windows_exporter/internal/perfdata/v1"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus-community/windows_exporter/internal/utils"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
)
|
||||
|
||||
const Name = "dhcp"
|
||||
@@ -88,7 +88,7 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *wmi.Client) error {
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
|
||||
if utils.PDHEnabled() {
|
||||
counters := []string{
|
||||
acksTotal,
|
||||
|
||||
@@ -4,19 +4,17 @@ package diskdrive
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
)
|
||||
|
||||
const (
|
||||
Name = "diskdrive"
|
||||
win32DiskQuery = "SELECT DeviceID, Model, Caption, Name, Partitions, Size, Status, Availability FROM WIN32_DiskDrive"
|
||||
)
|
||||
const Name = "diskdrive"
|
||||
|
||||
type Config struct{}
|
||||
|
||||
@@ -25,7 +23,8 @@ var ConfigDefaults = Config{}
|
||||
// A Collector is a Prometheus Collector for a few WMI metrics in Win32_DiskDrive.
|
||||
type Collector struct {
|
||||
config Config
|
||||
wmiClient *wmi.Client
|
||||
miSession *mi.Session
|
||||
miQuery mi.Query
|
||||
|
||||
availability *prometheus.Desc
|
||||
diskInfo *prometheus.Desc
|
||||
@@ -62,12 +61,19 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(_ *slog.Logger, wmiClient *wmi.Client) error {
|
||||
if wmiClient == nil || wmiClient.SWbemServicesClient == nil {
|
||||
return errors.New("wmiClient or SWbemServicesClient is nil")
|
||||
func (c *Collector) Build(_ *slog.Logger, miSession *mi.Session) error {
|
||||
if miSession == nil {
|
||||
return errors.New("miSession is nil")
|
||||
}
|
||||
|
||||
c.wmiClient = wmiClient
|
||||
miQuery, err := mi.NewQuery("SELECT DeviceID, Model, Caption, Name, Partitions, Size, Status, Availability FROM WIN32_DiskDrive")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create WMI query: %w", err)
|
||||
}
|
||||
|
||||
c.miQuery = miQuery
|
||||
c.miSession = miSession
|
||||
|
||||
c.diskInfo = prometheus.NewDesc(
|
||||
prometheus.BuildFQName(types.Namespace, Name, "info"),
|
||||
"General drive information",
|
||||
@@ -108,14 +114,14 @@ func (c *Collector) Build(_ *slog.Logger, wmiClient *wmi.Client) error {
|
||||
}
|
||||
|
||||
type win32_DiskDrive struct {
|
||||
DeviceID string
|
||||
Model string
|
||||
Size uint64
|
||||
Name string
|
||||
Caption string
|
||||
Partitions uint32
|
||||
Status string
|
||||
Availability uint16
|
||||
DeviceID string `mi:"DeviceID"`
|
||||
Model string `mi:"Model"`
|
||||
Size uint64 `mi:"Size"`
|
||||
Name string `mi:"Name"`
|
||||
Caption string `mi:"Caption"`
|
||||
Partitions uint32 `mi:"Partitions"`
|
||||
Status string `mi:"Status"`
|
||||
Availability uint16 `mi:"Availability"`
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -175,9 +181,8 @@ func (c *Collector) Collect(_ *types.ScrapeContext, logger *slog.Logger, ch chan
|
||||
|
||||
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||
var dst []win32_DiskDrive
|
||||
|
||||
if err := c.wmiClient.Query(win32DiskQuery, &dst); err != nil {
|
||||
return err
|
||||
if err := c.miSession.Query(&dst, mi.NamespaceRootCIMv2, c.miQuery); err != nil {
|
||||
return fmt.Errorf("WMI query failed: %w", err)
|
||||
}
|
||||
|
||||
if len(dst) == 0 {
|
||||
|
||||
@@ -8,11 +8,11 @@ import (
|
||||
"log/slog"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/perfdata"
|
||||
"github.com/prometheus-community/windows_exporter/internal/perfdata/perftypes"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
)
|
||||
|
||||
const Name = "dns"
|
||||
@@ -79,7 +79,7 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *wmi.Client) error {
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
|
||||
counters := []string{
|
||||
axfrRequestReceived,
|
||||
axfrRequestSent,
|
||||
|
||||
@@ -10,11 +10,11 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/perfdata"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus-community/windows_exporter/internal/utils"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
)
|
||||
|
||||
const Name = "exchange"
|
||||
@@ -207,7 +207,7 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *wmi.Client) error {
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
|
||||
if utils.PDHEnabled() {
|
||||
collectorFuncs := map[string]func() error{
|
||||
adAccessProcesses: c.buildADAccessProcesses,
|
||||
|
||||
@@ -12,9 +12,9 @@ import (
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/bmatcuk/doublestar/v4"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
)
|
||||
|
||||
const Name = "filetime"
|
||||
@@ -85,7 +85,7 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(logger *slog.Logger, _ *wmi.Client) error {
|
||||
func (c *Collector) Build(logger *slog.Logger, _ *mi.Session) error {
|
||||
logger.Info("filetime collector is in an experimental state! It may subject to change.",
|
||||
slog.String("collector", Name),
|
||||
)
|
||||
|
||||
@@ -4,13 +4,14 @@ package fsrmquota
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"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"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
)
|
||||
|
||||
const Name = "fsrmquota"
|
||||
@@ -21,7 +22,8 @@ var ConfigDefaults = Config{}
|
||||
|
||||
type Collector struct {
|
||||
config Config
|
||||
wmiClient *wmi.Client
|
||||
miSession *mi.Session
|
||||
miQuery mi.Query
|
||||
|
||||
quotasCount *prometheus.Desc
|
||||
peakUsage *prometheus.Desc
|
||||
@@ -63,12 +65,18 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(_ *slog.Logger, wmiClient *wmi.Client) error {
|
||||
if wmiClient == nil || wmiClient.SWbemServicesClient == nil {
|
||||
return errors.New("wmiClient or SWbemServicesClient is nil")
|
||||
func (c *Collector) Build(_ *slog.Logger, miSession *mi.Session) error {
|
||||
if miSession == nil {
|
||||
return errors.New("miSession is nil")
|
||||
}
|
||||
|
||||
c.wmiClient = wmiClient
|
||||
miQuery, err := mi.NewQuery("SELECT * FROM MSFT_FSRMQuota")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create WMI query: %w", err)
|
||||
}
|
||||
|
||||
c.miQuery = miQuery
|
||||
c.miSession = miSession
|
||||
|
||||
c.quotasCount = prometheus.NewDesc(
|
||||
prometheus.BuildFQName(types.Namespace, Name, "count"),
|
||||
@@ -146,29 +154,28 @@ func (c *Collector) Collect(_ *types.ScrapeContext, logger *slog.Logger, ch chan
|
||||
// MSFT_FSRMQuota docs:
|
||||
// https://docs.microsoft.com/en-us/previous-versions/windows/desktop/fsrm/msft-fsrmquota
|
||||
type MSFT_FSRMQuota struct {
|
||||
Name string
|
||||
Name string `mi:"Name"`
|
||||
|
||||
Path string
|
||||
PeakUsage uint64
|
||||
Size uint64
|
||||
Usage uint64
|
||||
Description string
|
||||
Template string
|
||||
// Threshold string
|
||||
Disabled bool
|
||||
MatchesTemplate bool
|
||||
SoftLimit bool
|
||||
Path string `mi:"Path"`
|
||||
PeakUsage uint64 `mi:"PeakUsage"`
|
||||
Size uint64 `mi:"Size"`
|
||||
Usage uint64 `mi:"Usage"`
|
||||
Description string `mi:"Description"`
|
||||
Template string `mi:"Template"`
|
||||
// Threshold string `mi:"Threshold"`
|
||||
Disabled bool `mi:"Disabled"`
|
||||
MatchesTemplate bool `mi:"MatchesTemplate"`
|
||||
SoftLimit bool `mi:"SoftLimit"`
|
||||
}
|
||||
|
||||
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||
var dst []MSFT_FSRMQuota
|
||||
if err := c.miSession.Query(&dst, mi.NamespaceRootWindowsFSRM, c.miQuery); err != nil {
|
||||
return fmt.Errorf("WMI query failed: %w", err)
|
||||
}
|
||||
|
||||
var count int
|
||||
|
||||
if err := c.wmiClient.Query("SELECT * FROM MSFT_FSRMQuota", &dst, nil, "root/microsoft/windows/fsrm"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, quota := range dst {
|
||||
count++
|
||||
path := quota.Path
|
||||
|
||||
@@ -9,9 +9,10 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"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"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
)
|
||||
|
||||
const Name = "hyperv"
|
||||
@@ -23,7 +24,7 @@ var ConfigDefaults = Config{}
|
||||
// Collector is a Prometheus Collector for hyper-v.
|
||||
type Collector struct {
|
||||
config Config
|
||||
wmiClient *wmi.Client
|
||||
miSession *mi.Session
|
||||
|
||||
// Win32_PerfRawData_VmmsVirtualMachineStats_HyperVVirtualMachineHealthSummary
|
||||
healthCritical *prometheus.Desc
|
||||
@@ -168,12 +169,12 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(_ *slog.Logger, wmiClient *wmi.Client) error {
|
||||
if wmiClient == nil || wmiClient.SWbemServicesClient == nil {
|
||||
return errors.New("wmiClient or SWbemServicesClient is nil")
|
||||
func (c *Collector) Build(_ *slog.Logger, miSession *mi.Session) error {
|
||||
if miSession == nil {
|
||||
return errors.New("miSession is nil")
|
||||
}
|
||||
|
||||
c.wmiClient = wmiClient
|
||||
c.miSession = miSession
|
||||
|
||||
buildSubsystemName := func(component string) string { return "hyperv_" + component }
|
||||
|
||||
@@ -858,14 +859,14 @@ func (c *Collector) Collect(_ *types.ScrapeContext, logger *slog.Logger, ch chan
|
||||
|
||||
// Win32_PerfRawData_VmmsVirtualMachineStats_HyperVVirtualMachineHealthSummary vm health status.
|
||||
type Win32_PerfRawData_VmmsVirtualMachineStats_HyperVVirtualMachineHealthSummary struct {
|
||||
HealthCritical uint32
|
||||
HealthOk uint32
|
||||
HealthCritical uint32 `mi:"HealthCritical"`
|
||||
HealthOk uint32 `mi:"HealthOK"`
|
||||
}
|
||||
|
||||
func (c *Collector) collectVmHealth(ch chan<- prometheus.Metric) error {
|
||||
var dst []Win32_PerfRawData_VmmsVirtualMachineStats_HyperVVirtualMachineHealthSummary
|
||||
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_VmmsVirtualMachineStats_HyperVVirtualMachineHealthSummary", &dst); err != nil {
|
||||
return err
|
||||
if err := c.miSession.Query(&dst, mi.NamespaceRootCIMv2, utils.Must(mi.NewQuery("SELECT * Win32_PerfRawData_VmmsVirtualMachineStats_HyperVVirtualMachineHealthSummary"))); err != nil {
|
||||
return fmt.Errorf("WMI query failed: %w", err)
|
||||
}
|
||||
|
||||
for _, health := range dst {
|
||||
@@ -887,16 +888,16 @@ func (c *Collector) collectVmHealth(ch chan<- prometheus.Metric) error {
|
||||
|
||||
// Win32_PerfRawData_VidPerfProvider_HyperVVMVidPartition ..,.
|
||||
type Win32_PerfRawData_VidPerfProvider_HyperVVMVidPartition struct {
|
||||
Name string
|
||||
PhysicalPagesAllocated uint64
|
||||
PreferredNUMANodeIndex uint64
|
||||
RemotePhysicalPages uint64
|
||||
Name string `mi:"Name"`
|
||||
PhysicalPagesAllocated uint64 `mi:"PhysicalPagesAllocated"`
|
||||
PreferredNUMANodeIndex uint64 `mi:"PreferredNUMANodeIndex"`
|
||||
RemotePhysicalPages uint64 `mi:"RemotePhysicalPages"`
|
||||
}
|
||||
|
||||
func (c *Collector) collectVmVid(ch chan<- prometheus.Metric) error {
|
||||
var dst []Win32_PerfRawData_VidPerfProvider_HyperVVMVidPartition
|
||||
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_VidPerfProvider_HyperVVMVidPartition", &dst); err != nil {
|
||||
return err
|
||||
if err := c.miSession.Query(&dst, mi.NamespaceRootCIMv2, utils.Must(mi.NewQuery("SELECT * Win32_PerfRawData_VidPerfProvider_HyperVVMVidPartition"))); err != nil {
|
||||
return fmt.Errorf("WMI query failed: %w", err)
|
||||
}
|
||||
|
||||
for _, page := range dst {
|
||||
@@ -931,34 +932,34 @@ func (c *Collector) collectVmVid(ch chan<- prometheus.Metric) error {
|
||||
|
||||
// Win32_PerfRawData_HvStats_HyperVHypervisorRootPartition ...
|
||||
type Win32_PerfRawData_HvStats_HyperVHypervisorRootPartition struct {
|
||||
Name string
|
||||
AddressSpaces uint64
|
||||
AttachedDevices uint64
|
||||
DepositedPages uint64
|
||||
DeviceDMAErrors uint64
|
||||
DeviceInterruptErrors uint64
|
||||
DeviceInterruptMappings uint64
|
||||
DeviceInterruptThrottleEvents uint64
|
||||
GPAPages uint64
|
||||
GPASpaceModificationsPersec uint64
|
||||
IOTLBFlushCost uint64
|
||||
IOTLBFlushesPersec uint64
|
||||
RecommendedVirtualTLBSize uint64
|
||||
SkippedTimerTicks uint64
|
||||
Value1Gdevicepages uint64
|
||||
Value1GGPApages uint64
|
||||
Value2Mdevicepages uint64
|
||||
Value2MGPApages uint64
|
||||
Value4Kdevicepages uint64
|
||||
Value4KGPApages uint64
|
||||
VirtualTLBFlushEntiresPersec uint64
|
||||
VirtualTLBPages uint64
|
||||
Name string `mi:"Name"`
|
||||
AddressSpaces uint64 `mi:"AddressSpaces"`
|
||||
AttachedDevices uint64 `mi:"AttachedDevices"`
|
||||
DepositedPages uint64 `mi:"DepositedPages"`
|
||||
DeviceDMAErrors uint64 `mi:"DeviceDMAErrors"`
|
||||
DeviceInterruptErrors uint64 `mi:"DeviceInterruptErrors"`
|
||||
DeviceInterruptMappings uint64 `mi:"DeviceInterruptMappings"`
|
||||
DeviceInterruptThrottleEvents uint64 `mi:"DeviceInterruptThrottleEvents"`
|
||||
GPAPages uint64 `mi:"GPAPages"`
|
||||
GPASpaceModificationsPersec uint64 `mi:"GPASpaceModificationsPersec"`
|
||||
IOTLBFlushCost uint64 `mi:"IOTLBFlushCost"`
|
||||
IOTLBFlushesPersec uint64 `mi:"IOTLBFlushesPersec"`
|
||||
RecommendedVirtualTLBSize uint64 `mi:"RecommendedVirtualTLBSize"`
|
||||
SkippedTimerTicks uint64 `mi:"SkippedTimerTicks"`
|
||||
Value1Gdevicepages uint64 `mi:"Value1Gdevicepages"`
|
||||
Value1GGPApages uint64 `mi:"Value1GGPApages"`
|
||||
Value2Mdevicepages uint64 `mi:"Value2Mdevicepages"`
|
||||
Value2MGPApages uint64 `mi:"Value2MGPApages"`
|
||||
Value4Kdevicepages uint64 `mi:"Value4Kdevicepages"`
|
||||
Value4KGPApages uint64 `mi:"Value4KGPApages"`
|
||||
VirtualTLBFlushEntiresPersec uint64 `mi:"VirtualTLBFlushEntiresPersec"`
|
||||
VirtualTLBPages uint64 `mi:"VirtualTLBPages"`
|
||||
}
|
||||
|
||||
func (c *Collector) collectVmHv(ch chan<- prometheus.Metric) error {
|
||||
var dst []Win32_PerfRawData_HvStats_HyperVHypervisorRootPartition
|
||||
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_HvStats_HyperVHypervisorRootPartition", &dst); err != nil {
|
||||
return err
|
||||
if err := c.miSession.Query(&dst, mi.NamespaceRootCIMv2, utils.Must(mi.NewQuery("SELECT * Win32_PerfRawData_HvStats_HyperVHypervisorRootPartition"))); err != nil {
|
||||
return fmt.Errorf("WMI query failed: %w", err)
|
||||
}
|
||||
|
||||
for _, obj := range dst {
|
||||
@@ -1087,14 +1088,14 @@ func (c *Collector) collectVmHv(ch chan<- prometheus.Metric) error {
|
||||
|
||||
// Win32_PerfRawData_HvStats_HyperVHypervisor ...
|
||||
type Win32_PerfRawData_HvStats_HyperVHypervisor struct {
|
||||
LogicalProcessors uint64
|
||||
VirtualProcessors uint64
|
||||
LogicalProcessors uint64 `mi:"LogicalProcessors"`
|
||||
VirtualProcessors uint64 `mi:"VirtualProcessors"`
|
||||
}
|
||||
|
||||
func (c *Collector) collectVmProcessor(ch chan<- prometheus.Metric) error {
|
||||
var dst []Win32_PerfRawData_HvStats_HyperVHypervisor
|
||||
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_HvStats_HyperVHypervisor", &dst); err != nil {
|
||||
return err
|
||||
if err := c.miSession.Query(&dst, mi.NamespaceRootCIMv2, utils.Must(mi.NewQuery("SELECT * Win32_PerfRawData_HvStats_HyperVHypervisor"))); err != nil {
|
||||
return fmt.Errorf("WMI query failed: %w", err)
|
||||
}
|
||||
|
||||
for _, obj := range dst {
|
||||
@@ -1116,16 +1117,16 @@ func (c *Collector) collectVmProcessor(ch chan<- prometheus.Metric) error {
|
||||
|
||||
// Win32_PerfRawData_HvStats_HyperVHypervisorLogicalProcessor ...
|
||||
type Win32_PerfRawData_HvStats_HyperVHypervisorLogicalProcessor struct {
|
||||
Name string
|
||||
PercentGuestRunTime uint64
|
||||
PercentHypervisorRunTime uint64
|
||||
PercentTotalRunTime uint
|
||||
Name string `mi:"Name"`
|
||||
PercentGuestRunTime uint64 `mi:"PercentGuestRunTime"`
|
||||
PercentHypervisorRunTime uint64 `mi:"PercentHypervisorRunTime"`
|
||||
PercentTotalRunTime uint64 `mi:"PercentTotalRunTime"`
|
||||
}
|
||||
|
||||
func (c *Collector) collectHostLPUsage(logger *slog.Logger, ch chan<- prometheus.Metric) error {
|
||||
var dst []Win32_PerfRawData_HvStats_HyperVHypervisorLogicalProcessor
|
||||
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_HvStats_HyperVHypervisorLogicalProcessor", &dst); err != nil {
|
||||
return err
|
||||
if err := c.miSession.Query(&dst, mi.NamespaceRootCIMv2, utils.Must(mi.NewQuery("SELECT * Win32_PerfRawData_HvStats_HyperVHypervisorLogicalProcessor"))); err != nil {
|
||||
return fmt.Errorf("WMI query failed: %w", err)
|
||||
}
|
||||
|
||||
for _, obj := range dst {
|
||||
@@ -1170,18 +1171,18 @@ func (c *Collector) collectHostLPUsage(logger *slog.Logger, ch chan<- prometheus
|
||||
|
||||
// Win32_PerfRawData_HvStats_HyperVHypervisorRootVirtualProcessor ...
|
||||
type Win32_PerfRawData_HvStats_HyperVHypervisorRootVirtualProcessor struct {
|
||||
Name string
|
||||
PercentGuestRunTime uint64
|
||||
PercentHypervisorRunTime uint64
|
||||
PercentRemoteRunTime uint64
|
||||
PercentTotalRunTime uint64
|
||||
CPUWaitTimePerDispatch uint64
|
||||
Name string `mi:"Name"`
|
||||
PercentGuestRunTime uint64 `mi:"PercentGuestRunTime"`
|
||||
PercentHypervisorRunTime uint64 `mi:"PercentHypervisorRunTime"`
|
||||
PercentRemoteRunTime uint64 `mi:"PercentRemoteRunTime"`
|
||||
PercentTotalRunTime uint64 `mi:"PercentTotalRunTime"`
|
||||
CPUWaitTimePerDispatch uint64 `mi:"CPUWaitTimePerDispatch"`
|
||||
}
|
||||
|
||||
func (c *Collector) collectHostCpuUsage(logger *slog.Logger, ch chan<- prometheus.Metric) error {
|
||||
var dst []Win32_PerfRawData_HvStats_HyperVHypervisorRootVirtualProcessor
|
||||
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_HvStats_HyperVHypervisorRootVirtualProcessor", &dst); err != nil {
|
||||
return err
|
||||
if err := c.miSession.Query(&dst, mi.NamespaceRootCIMv2, utils.Must(mi.NewQuery("SELECT * Win32_PerfRawData_HvStats_HyperVHypervisorRootVirtualProcessor"))); err != nil {
|
||||
return fmt.Errorf("WMI query failed: %w", err)
|
||||
}
|
||||
|
||||
for _, obj := range dst {
|
||||
@@ -1240,18 +1241,18 @@ func (c *Collector) collectHostCpuUsage(logger *slog.Logger, ch chan<- prometheu
|
||||
|
||||
// Win32_PerfRawData_HvStats_HyperVHypervisorVirtualProcessor ...
|
||||
type Win32_PerfRawData_HvStats_HyperVHypervisorVirtualProcessor struct {
|
||||
Name string
|
||||
PercentGuestRunTime uint64
|
||||
PercentHypervisorRunTime uint64
|
||||
PercentRemoteRunTime uint64
|
||||
PercentTotalRunTime uint64
|
||||
CPUWaitTimePerDispatch uint64
|
||||
Name string `mi:"Name"`
|
||||
PercentGuestRunTime uint64 `mi:"PercentGuestRunTime"`
|
||||
PercentHypervisorRunTime uint64 `mi:"PercentHypervisorRunTime"`
|
||||
PercentRemoteRunTime uint64 `mi:"PercentRemoteRunTime"`
|
||||
PercentTotalRunTime uint64 `mi:"PercentTotalRunTime"`
|
||||
CPUWaitTimePerDispatch uint64 `mi:"CPUWaitTimePerDispatch"`
|
||||
}
|
||||
|
||||
func (c *Collector) collectVmCpuUsage(logger *slog.Logger, ch chan<- prometheus.Metric) error {
|
||||
var dst []Win32_PerfRawData_HvStats_HyperVHypervisorVirtualProcessor
|
||||
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_HvStats_HyperVHypervisorVirtualProcessor", &dst); err != nil {
|
||||
return err
|
||||
if err := c.miSession.Query(&dst, mi.NamespaceRootCIMv2, utils.Must(mi.NewQuery("SELECT * Win32_PerfRawData_HvStats_HyperVHypervisorVirtualProcessor"))); err != nil {
|
||||
return fmt.Errorf("WMI query failed: %w", err)
|
||||
}
|
||||
|
||||
for _, obj := range dst {
|
||||
@@ -1318,37 +1319,37 @@ func (c *Collector) collectVmCpuUsage(logger *slog.Logger, ch chan<- prometheus.
|
||||
|
||||
// Win32_PerfRawData_NvspSwitchStats_HyperVVirtualSwitch ...
|
||||
type Win32_PerfRawData_NvspSwitchStats_HyperVVirtualSwitch struct {
|
||||
Name string
|
||||
BroadcastPacketsReceivedPersec uint64
|
||||
BroadcastPacketsSentPersec uint64
|
||||
BytesPersec uint64
|
||||
BytesReceivedPersec uint64
|
||||
BytesSentPersec uint64
|
||||
DirectedPacketsReceivedPersec uint64
|
||||
DirectedPacketsSentPersec uint64
|
||||
DroppedPacketsIncomingPersec uint64
|
||||
DroppedPacketsOutgoingPersec uint64
|
||||
ExtensionsDroppedPacketsIncomingPersec uint64
|
||||
ExtensionsDroppedPacketsOutgoingPersec uint64
|
||||
LearnedMacAddresses uint64
|
||||
LearnedMacAddressesPersec uint64
|
||||
MulticastPacketsReceivedPersec uint64
|
||||
MulticastPacketsSentPersec uint64
|
||||
NumberofSendChannelMovesPersec uint64
|
||||
NumberofVMQMovesPersec uint64
|
||||
PacketsFlooded uint64
|
||||
PacketsFloodedPersec uint64
|
||||
PacketsPersec uint64
|
||||
PacketsReceivedPersec uint64
|
||||
PacketsSentPersec uint64
|
||||
PurgedMacAddresses uint64
|
||||
PurgedMacAddressesPersec uint64
|
||||
Name string `mi:"Name"`
|
||||
BroadcastPacketsReceivedPersec uint64 `mi:"BroadcastPacketsReceivedPersec"`
|
||||
BroadcastPacketsSentPersec uint64 `mi:"BroadcastPacketsSentPersec"`
|
||||
BytesPersec uint64 `mi:"BytesPersec"`
|
||||
BytesReceivedPersec uint64 `mi:"BytesReceivedPersec"`
|
||||
BytesSentPersec uint64 `mi:"BytesSentPersec"`
|
||||
DirectedPacketsReceivedPersec uint64 `mi:"DirectedPacketsReceivedPersec"`
|
||||
DirectedPacketsSentPersec uint64 `mi:"DirectedPacketsSentPersec"`
|
||||
DroppedPacketsIncomingPersec uint64 `mi:"DroppedPacketsIncomingPersec"`
|
||||
DroppedPacketsOutgoingPersec uint64 `mi:"DroppedPacketsOutgoingPersec"`
|
||||
ExtensionsDroppedPacketsIncomingPersec uint64 `mi:"ExtensionsDroppedPacketsIncomingPersec"`
|
||||
ExtensionsDroppedPacketsOutgoingPersec uint64 `mi:"ExtensionsDroppedPacketsOutgoingPersec"`
|
||||
LearnedMacAddresses uint64 `mi:"LearnedMacAddresses"`
|
||||
LearnedMacAddressesPersec uint64 `mi:"LearnedMacAddressesPersec"`
|
||||
MulticastPacketsReceivedPersec uint64 `mi:"MulticastPacketsReceivedPersec"`
|
||||
MulticastPacketsSentPersec uint64 `mi:"MulticastPacketsSentPersec"`
|
||||
NumberofSendChannelMovesPersec uint64 `mi:"NumberofSendChannelMovesPersec"`
|
||||
NumberofVMQMovesPersec uint64 `mi:"NumberofVMQMovesPersec"`
|
||||
PacketsFlooded uint64 `mi:"PacketsFlooded"`
|
||||
PacketsFloodedPersec uint64 `mi:"PacketsFloodedPersec"`
|
||||
PacketsPersec uint64 `mi:"PacketsPersec"`
|
||||
PacketsReceivedPersec uint64 `mi:"PacketsReceivedPersec"`
|
||||
PacketsSentPersec uint64 `mi:"PacketsSentPersec"`
|
||||
PurgedMacAddresses uint64 `mi:"PurgedMacAddresses"`
|
||||
PurgedMacAddressesPersec uint64 `mi:"PurgedMacAddressesPersec"`
|
||||
}
|
||||
|
||||
func (c *Collector) collectVmSwitch(ch chan<- prometheus.Metric) error {
|
||||
var dst []Win32_PerfRawData_NvspSwitchStats_HyperVVirtualSwitch
|
||||
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_NvspSwitchStats_HyperVVirtualSwitch", &dst); err != nil {
|
||||
return err
|
||||
if err := c.miSession.Query(&dst, mi.NamespaceRootCIMv2, utils.Must(mi.NewQuery("SELECT * Win32_PerfRawData_NvspSwitchStats_HyperVVirtualSwitch"))); err != nil {
|
||||
return fmt.Errorf("WMI query failed: %w", err)
|
||||
}
|
||||
|
||||
for _, obj := range dst {
|
||||
@@ -1500,19 +1501,19 @@ func (c *Collector) collectVmSwitch(ch chan<- prometheus.Metric) error {
|
||||
|
||||
// Win32_PerfRawData_EthernetPerfProvider_HyperVLegacyNetworkAdapter ...
|
||||
type Win32_PerfRawData_EthernetPerfProvider_HyperVLegacyNetworkAdapter struct {
|
||||
Name string
|
||||
BytesDropped uint64
|
||||
BytesReceivedPersec uint64
|
||||
BytesSentPersec uint64
|
||||
FramesDropped uint64
|
||||
FramesReceivedPersec uint64
|
||||
FramesSentPersec uint64
|
||||
Name string `mi:"Name"`
|
||||
BytesDropped uint64 `mi:"BytesDropped"`
|
||||
BytesReceivedPersec uint64 `mi:"BytesReceivedPersec"`
|
||||
BytesSentPersec uint64 `mi:"BytesSentPersec"`
|
||||
FramesDropped uint64 `mi:"FramesDropped"`
|
||||
FramesReceivedPersec uint64 `mi:"FramesReceivedPersec"`
|
||||
FramesSentPersec uint64 `mi:"FramesSentPersec"`
|
||||
}
|
||||
|
||||
func (c *Collector) collectVmEthernet(ch chan<- prometheus.Metric) error {
|
||||
var dst []Win32_PerfRawData_EthernetPerfProvider_HyperVLegacyNetworkAdapter
|
||||
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_EthernetPerfProvider_HyperVLegacyNetworkAdapter", &dst); err != nil {
|
||||
return err
|
||||
if err := c.miSession.Query(&dst, mi.NamespaceRootCIMv2, utils.Must(mi.NewQuery("SELECT * Win32_PerfRawData_EthernetPerfProvider_HyperVLegacyNetworkAdapter"))); err != nil {
|
||||
return fmt.Errorf("WMI query failed: %w", err)
|
||||
}
|
||||
|
||||
for _, obj := range dst {
|
||||
@@ -1568,19 +1569,19 @@ func (c *Collector) collectVmEthernet(ch chan<- prometheus.Metric) error {
|
||||
|
||||
// Win32_PerfRawData_Counters_HyperVVirtualStorageDevice ...
|
||||
type Win32_PerfRawData_Counters_HyperVVirtualStorageDevice struct {
|
||||
Name string
|
||||
ErrorCount uint64
|
||||
QueueLength uint32
|
||||
ReadBytesPersec uint64
|
||||
ReadOperationsPerSec uint64
|
||||
WriteBytesPersec uint64
|
||||
WriteOperationsPerSec uint64
|
||||
Name string `mi:"Name"`
|
||||
ErrorCount uint64 `mi:"ErrorCount"`
|
||||
QueueLength uint32 `mi:"QueueLength"`
|
||||
ReadBytesPersec uint64 `mi:"ReadBytesPersec"`
|
||||
ReadOperationsPerSec uint64 `mi:"ReadOperationsPerSec"`
|
||||
WriteBytesPersec uint64 `mi:"WriteBytesPersec"`
|
||||
WriteOperationsPerSec uint64 `mi:"WriteOperationsPerSec"`
|
||||
}
|
||||
|
||||
func (c *Collector) collectVmStorage(ch chan<- prometheus.Metric) error {
|
||||
var dst []Win32_PerfRawData_Counters_HyperVVirtualStorageDevice
|
||||
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_Counters_HyperVVirtualStorageDevice", &dst); err != nil {
|
||||
return err
|
||||
if err := c.miSession.Query(&dst, mi.NamespaceRootCIMv2, utils.Must(mi.NewQuery("SELECT * Win32_PerfRawData_Counters_HyperVVirtualStorageDevice"))); err != nil {
|
||||
return fmt.Errorf("WMI query failed: %w", err)
|
||||
}
|
||||
|
||||
for _, obj := range dst {
|
||||
@@ -1636,19 +1637,19 @@ func (c *Collector) collectVmStorage(ch chan<- prometheus.Metric) error {
|
||||
|
||||
// Win32_PerfRawData_NvspNicStats_HyperVVirtualNetworkAdapter ...
|
||||
type Win32_PerfRawData_NvspNicStats_HyperVVirtualNetworkAdapter struct {
|
||||
Name string
|
||||
BytesReceivedPersec uint64
|
||||
BytesSentPersec uint64
|
||||
DroppedPacketsIncomingPersec uint64
|
||||
DroppedPacketsOutgoingPersec uint64
|
||||
PacketsReceivedPersec uint64
|
||||
PacketsSentPersec uint64
|
||||
Name string `mi:"Name"`
|
||||
BytesReceivedPersec uint64 `mi:"BytesReceivedPersec"`
|
||||
BytesSentPersec uint64 `mi:"BytesSentPersec"`
|
||||
DroppedPacketsIncomingPersec uint64 `mi:"DroppedPacketsIncomingPersec"`
|
||||
DroppedPacketsOutgoingPersec uint64 `mi:"DroppedPacketsOutgoingPersec"`
|
||||
PacketsReceivedPersec uint64 `mi:"PacketsReceivedPersec"`
|
||||
PacketsSentPersec uint64 `mi:"PacketsSentPersec"`
|
||||
}
|
||||
|
||||
func (c *Collector) collectVmNetwork(ch chan<- prometheus.Metric) error {
|
||||
var dst []Win32_PerfRawData_NvspNicStats_HyperVVirtualNetworkAdapter
|
||||
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_NvspNicStats_HyperVVirtualNetworkAdapter", &dst); err != nil {
|
||||
return err
|
||||
if err := c.miSession.Query(&dst, mi.NamespaceRootCIMv2, utils.Must(mi.NewQuery("SELECT * Win32_PerfRawData_NvspNicStats_HyperVVirtualNetworkAdapter"))); err != nil {
|
||||
return fmt.Errorf("WMI query failed: %w", err)
|
||||
}
|
||||
|
||||
for _, obj := range dst {
|
||||
@@ -1704,23 +1705,23 @@ func (c *Collector) collectVmNetwork(ch chan<- prometheus.Metric) error {
|
||||
|
||||
// Win32_PerfRawData_BalancerStats_HyperVDynamicMemoryVM ...
|
||||
type Win32_PerfRawData_BalancerStats_HyperVDynamicMemoryVM struct {
|
||||
Name string
|
||||
AddedMemory uint64
|
||||
AveragePressure uint64
|
||||
CurrentPressure uint64
|
||||
GuestVisiblePhysicalMemory uint64
|
||||
MaximumPressure uint64
|
||||
MemoryAddOperations uint64
|
||||
MemoryRemoveOperations uint64
|
||||
MinimumPressure uint64
|
||||
PhysicalMemory uint64
|
||||
RemovedMemory uint64
|
||||
Name string `mi:"Name"`
|
||||
AddedMemory uint64 `mi:"AddedMemory"`
|
||||
AveragePressure uint64 `mi:"AveragePressure"`
|
||||
CurrentPressure uint64 `mi:"CurrentPressure"`
|
||||
GuestVisiblePhysicalMemory uint64 `mi:"GuestVisiblePhysicalMemory"`
|
||||
MaximumPressure uint64 `mi:"MaximumPressure"`
|
||||
MemoryAddOperations uint64 `mi:"MemoryAddOperations"`
|
||||
MemoryRemoveOperations uint64 `mi:"MemoryRemoveOperations"`
|
||||
MinimumPressure uint64 `mi:"MinimumPressure"`
|
||||
PhysicalMemory uint64 `mi:"PhysicalMemory"`
|
||||
RemovedMemory uint64 `mi:"RemovedMemory"`
|
||||
}
|
||||
|
||||
func (c *Collector) collectVmMemory(ch chan<- prometheus.Metric) error {
|
||||
var dst []Win32_PerfRawData_BalancerStats_HyperVDynamicMemoryVM
|
||||
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_BalancerStats_HyperVDynamicMemoryVM", &dst); err != nil {
|
||||
return err
|
||||
if err := c.miSession.Query(&dst, mi.NamespaceRootCIMv2, utils.Must(mi.NewQuery("SELECT * Win32_PerfRawData_BalancerStats_HyperVDynamicMemoryVM"))); err != nil {
|
||||
return fmt.Errorf("WMI query failed: %w", err)
|
||||
}
|
||||
|
||||
for _, obj := range dst {
|
||||
|
||||
@@ -10,10 +10,10 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
v1 "github.com/prometheus-community/windows_exporter/internal/perfdata/v1"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
"golang.org/x/sys/windows/registry"
|
||||
)
|
||||
|
||||
@@ -262,7 +262,7 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(logger *slog.Logger, _ *wmi.Client) error {
|
||||
func (c *Collector) Build(logger *slog.Logger, _ *mi.Session) error {
|
||||
logger = logger.With(slog.String("collector", Name))
|
||||
|
||||
c.iisVersion = getIISVersion(logger)
|
||||
|
||||
@@ -7,9 +7,9 @@ import (
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/headers/slc"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
)
|
||||
|
||||
const Name = "license"
|
||||
@@ -61,7 +61,7 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *wmi.Client) error {
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
|
||||
c.licenseStatus = prometheus.NewDesc(
|
||||
prometheus.BuildFQName(types.Namespace, Name, "status"),
|
||||
"Status of windows license",
|
||||
|
||||
@@ -13,13 +13,13 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/perfdata"
|
||||
"github.com/prometheus-community/windows_exporter/internal/perfdata/perftypes"
|
||||
v1 "github.com/prometheus-community/windows_exporter/internal/perfdata/v1"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus-community/windows_exporter/internal/utils"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
@@ -141,7 +141,7 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *wmi.Client) error {
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
|
||||
if utils.PDHEnabled() {
|
||||
counters := []string{
|
||||
currentDiskQueueLength,
|
||||
|
||||
@@ -8,9 +8,9 @@ import (
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/headers/secur32"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
)
|
||||
|
||||
const Name = "logon"
|
||||
@@ -54,7 +54,7 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *wmi.Client) error {
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
|
||||
c.sessionInfo = prometheus.NewDesc(
|
||||
prometheus.BuildFQName(types.Namespace, Name, "session_logon_timestamp_seconds"),
|
||||
"timestamp of the logon session in seconds.",
|
||||
|
||||
@@ -12,13 +12,13 @@ import (
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/headers/sysinfoapi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/perfdata"
|
||||
"github.com/prometheus-community/windows_exporter/internal/perfdata/perftypes"
|
||||
v1 "github.com/prometheus-community/windows_exporter/internal/perfdata/v1"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus-community/windows_exporter/internal/utils"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
)
|
||||
|
||||
const Name = "memory"
|
||||
@@ -105,7 +105,7 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *wmi.Client) error {
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
|
||||
if utils.PDHEnabled() {
|
||||
counters := []string{
|
||||
availableBytes,
|
||||
|
||||
@@ -8,9 +8,9 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
)
|
||||
|
||||
const Name = "mscluster"
|
||||
@@ -32,7 +32,7 @@ var ConfigDefaults = Config{
|
||||
// A Collector is a Prometheus Collector for WMI MSCluster_Cluster metrics.
|
||||
type Collector struct {
|
||||
config Config
|
||||
wmiClient *wmi.Client
|
||||
miSession *mi.Session
|
||||
|
||||
// cluster
|
||||
clusterAddEvictDelay *prometheus.Desc
|
||||
@@ -221,16 +221,16 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(_ *slog.Logger, wmiClient *wmi.Client) error {
|
||||
func (c *Collector) Build(_ *slog.Logger, miSession *mi.Session) error {
|
||||
if len(c.config.CollectorsEnabled) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if wmiClient == nil || wmiClient.SWbemServicesClient == nil {
|
||||
return errors.New("wmiClient or SWbemServicesClient is nil")
|
||||
if miSession == nil {
|
||||
return errors.New("miSession is nil")
|
||||
}
|
||||
|
||||
c.wmiClient = wmiClient
|
||||
c.miSession = miSession
|
||||
|
||||
if slices.Contains(c.config.CollectorsEnabled, "cluster") {
|
||||
c.buildCluster()
|
||||
|
||||
@@ -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,85 +14,85 @@ const nameCluster = Name + "_cluster"
|
||||
// msClusterCluster represents the MSCluster_Cluster WMI class
|
||||
// - https://docs.microsoft.com/en-us/previous-versions/windows/desktop/cluswmi/mscluster-cluster
|
||||
type msClusterCluster struct {
|
||||
Name string
|
||||
Name string `mi:"Name"`
|
||||
|
||||
AddEvictDelay uint
|
||||
AdminAccessPoint uint
|
||||
AutoAssignNodeSite uint
|
||||
AutoBalancerLevel uint
|
||||
AutoBalancerMode uint
|
||||
BackupInProgress uint
|
||||
BlockCacheSize uint
|
||||
ClusSvcHangTimeout uint
|
||||
ClusSvcRegroupOpeningTimeout uint
|
||||
ClusSvcRegroupPruningTimeout uint
|
||||
ClusSvcRegroupStageTimeout uint
|
||||
ClusSvcRegroupTickInMilliseconds uint
|
||||
ClusterEnforcedAntiAffinity uint
|
||||
ClusterFunctionalLevel uint
|
||||
ClusterGroupWaitDelay uint
|
||||
ClusterLogLevel uint
|
||||
ClusterLogSize uint
|
||||
ClusterUpgradeVersion uint
|
||||
CrossSiteDelay uint
|
||||
CrossSiteThreshold uint
|
||||
CrossSubnetDelay uint
|
||||
CrossSubnetThreshold uint
|
||||
CsvBalancer uint
|
||||
DatabaseReadWriteMode uint
|
||||
DefaultNetworkRole uint
|
||||
DetectedCloudPlatform uint
|
||||
DetectManagedEvents uint
|
||||
DetectManagedEventsThreshold uint
|
||||
DisableGroupPreferredOwnerRandomization uint
|
||||
DrainOnShutdown uint
|
||||
DynamicQuorumEnabled uint
|
||||
EnableSharedVolumes uint
|
||||
FixQuorum uint
|
||||
GracePeriodEnabled uint
|
||||
GracePeriodTimeout uint
|
||||
GroupDependencyTimeout uint
|
||||
HangRecoveryAction uint
|
||||
IgnorePersistentStateOnStartup uint
|
||||
LogResourceControls uint
|
||||
LowerQuorumPriorityNodeId uint
|
||||
MaxNumberOfNodes uint
|
||||
MessageBufferLength uint
|
||||
MinimumNeverPreemptPriority uint
|
||||
MinimumPreemptorPriority uint
|
||||
NetftIPSecEnabled uint
|
||||
PlacementOptions uint
|
||||
PlumbAllCrossSubnetRoutes uint
|
||||
PreventQuorum uint
|
||||
QuarantineDuration uint
|
||||
QuarantineThreshold uint
|
||||
QuorumArbitrationTimeMax uint
|
||||
QuorumArbitrationTimeMin uint
|
||||
QuorumLogFileSize uint
|
||||
QuorumTypeValue uint
|
||||
RequestReplyTimeout uint
|
||||
ResiliencyDefaultPeriod uint
|
||||
ResiliencyLevel uint
|
||||
ResourceDllDeadlockPeriod uint
|
||||
RootMemoryReserved uint
|
||||
RouteHistoryLength uint
|
||||
S2DBusTypes uint
|
||||
S2DCacheDesiredState uint
|
||||
S2DCacheFlashReservePercent uint
|
||||
S2DCachePageSizeKBytes uint
|
||||
S2DEnabled uint
|
||||
S2DIOLatencyThreshold uint
|
||||
S2DOptimizations uint
|
||||
SameSubnetDelay uint
|
||||
SameSubnetThreshold uint
|
||||
SecurityLevel uint
|
||||
SecurityLevelForStorage uint
|
||||
SharedVolumeVssWriterOperationTimeout uint
|
||||
ShutdownTimeoutInMinutes uint
|
||||
UseClientAccessNetworksForSharedVolumes uint
|
||||
WitnessDatabaseWriteTimeout uint
|
||||
WitnessDynamicWeight uint
|
||||
WitnessRestartInterval uint
|
||||
AddEvictDelay uint `mi:"AddEvictDelay"`
|
||||
AdminAccessPoint uint `mi:"AdminAccessPoint"`
|
||||
AutoAssignNodeSite uint `mi:"AutoAssignNodeSite"`
|
||||
AutoBalancerLevel uint `mi:"AutoBalancerLevel"`
|
||||
AutoBalancerMode uint `mi:"AutoBalancerMode"`
|
||||
BackupInProgress uint `mi:"BackupInProgress"`
|
||||
BlockCacheSize uint `mi:"BlockCacheSize"`
|
||||
ClusSvcHangTimeout uint `mi:"ClusSvcHangTimeout"`
|
||||
ClusSvcRegroupOpeningTimeout uint `mi:"ClusSvcRegroupOpeningTimeout"`
|
||||
ClusSvcRegroupPruningTimeout uint `mi:"ClusSvcRegroupPruningTimeout"`
|
||||
ClusSvcRegroupStageTimeout uint `mi:"ClusSvcRegroupStageTimeout"`
|
||||
ClusSvcRegroupTickInMilliseconds uint `mi:"ClusSvcRegroupTickInMilliseconds"`
|
||||
ClusterEnforcedAntiAffinity uint `mi:"ClusterEnforcedAntiAffinity"`
|
||||
ClusterFunctionalLevel uint `mi:"ClusterFunctionalLevel"`
|
||||
ClusterGroupWaitDelay uint `mi:"ClusterGroupWaitDelay"`
|
||||
ClusterLogLevel uint `mi:"ClusterLogLevel"`
|
||||
ClusterLogSize uint `mi:"ClusterLogSize"`
|
||||
ClusterUpgradeVersion uint `mi:"ClusterUpgradeVersion"`
|
||||
CrossSiteDelay uint `mi:"CrossSiteDelay"`
|
||||
CrossSiteThreshold uint `mi:"CrossSiteThreshold"`
|
||||
CrossSubnetDelay uint `mi:"CrossSubnetDelay"`
|
||||
CrossSubnetThreshold uint `mi:"CrossSubnetThreshold"`
|
||||
CsvBalancer uint `mi:"CsvBalancer"`
|
||||
DatabaseReadWriteMode uint `mi:"DatabaseReadWriteMode"`
|
||||
DefaultNetworkRole uint `mi:"DefaultNetworkRole"`
|
||||
DetectedCloudPlatform uint `mi:"DetectedCloudPlatform"`
|
||||
DetectManagedEvents uint `mi:"DetectManagedEvents"`
|
||||
DetectManagedEventsThreshold uint `mi:"DetectManagedEventsThreshold"`
|
||||
DisableGroupPreferredOwnerRandomization uint `mi:"DisableGroupPreferredOwnerRandomization"`
|
||||
DrainOnShutdown uint `mi:"DrainOnShutdown"`
|
||||
DynamicQuorumEnabled uint `mi:"DynamicQuorumEnabled"`
|
||||
EnableSharedVolumes uint `mi:"EnableSharedVolumes"`
|
||||
FixQuorum uint `mi:"FixQuorum"`
|
||||
GracePeriodEnabled uint `mi:"GracePeriodEnabled"`
|
||||
GracePeriodTimeout uint `mi:"GracePeriodTimeout"`
|
||||
GroupDependencyTimeout uint `mi:"GroupDependencyTimeout"`
|
||||
HangRecoveryAction uint `mi:"HangRecoveryAction"`
|
||||
IgnorePersistentStateOnStartup uint `mi:"IgnorePersistentStateOnStartup"`
|
||||
LogResourceControls uint `mi:"LogResourceControls"`
|
||||
LowerQuorumPriorityNodeId uint `mi:"LowerQuorumPriorityNodeId"`
|
||||
MaxNumberOfNodes uint `mi:"MaxNumberOfNodes"`
|
||||
MessageBufferLength uint `mi:"MessageBufferLength"`
|
||||
MinimumNeverPreemptPriority uint `mi:"MinimumNeverPreemptPriority"`
|
||||
MinimumPreemptorPriority uint `mi:"MinimumPreemptorPriority"`
|
||||
NetftIPSecEnabled uint `mi:"NetftIPSecEnabled"`
|
||||
PlacementOptions uint `mi:"PlacementOptions"`
|
||||
PlumbAllCrossSubnetRoutes uint `mi:"PlumbAllCrossSubnetRoutes"`
|
||||
PreventQuorum uint `mi:"PreventQuorum"`
|
||||
QuarantineDuration uint `mi:"QuarantineDuration"`
|
||||
QuarantineThreshold uint `mi:"QuarantineThreshold"`
|
||||
QuorumArbitrationTimeMax uint `mi:"QuorumArbitrationTimeMax"`
|
||||
QuorumArbitrationTimeMin uint `mi:"QuorumArbitrationTimeMin"`
|
||||
QuorumLogFileSize uint `mi:"QuorumLogFileSize"`
|
||||
QuorumTypeValue uint `mi:"QuorumTypeValue"`
|
||||
RequestReplyTimeout uint `mi:"RequestReplyTimeout"`
|
||||
ResiliencyDefaultPeriod uint `mi:"ResiliencyDefaultPeriod"`
|
||||
ResiliencyLevel uint `mi:"ResiliencyLevel"`
|
||||
ResourceDllDeadlockPeriod uint `mi:"ResourceDllDeadlockPeriod"`
|
||||
RootMemoryReserved uint `mi:"RootMemoryReserved"`
|
||||
RouteHistoryLength uint `mi:"RouteHistoryLength"`
|
||||
S2DBusTypes uint `mi:"S2DBusTypes"`
|
||||
S2DCacheDesiredState uint `mi:"S2DCacheDesiredState"`
|
||||
S2DCacheFlashReservePercent uint `mi:"S2DCacheFlashReservePercent"`
|
||||
S2DCachePageSizeKBytes uint `mi:"S2DCachePageSizeKBytes"`
|
||||
S2DEnabled uint `mi:"S2DEnabled"`
|
||||
S2DIOLatencyThreshold uint `mi:"S2DIOLatencyThreshold"`
|
||||
S2DOptimizations uint `mi:"S2DOptimizations"`
|
||||
SameSubnetDelay uint `mi:"SameSubnetDelay"`
|
||||
SameSubnetThreshold uint `mi:"SameSubnetThreshold"`
|
||||
SecurityLevel uint `mi:"SecurityLevel"`
|
||||
SecurityLevelForStorage uint `mi:"SecurityLevelForStorage"`
|
||||
SharedVolumeVssWriterOperationTimeout uint `mi:"SharedVolumeVssWriterOperationTimeout"`
|
||||
ShutdownTimeoutInMinutes uint `mi:"ShutdownTimeoutInMinutes"`
|
||||
UseClientAccessNetworksForSharedVolumes uint `mi:"UseClientAccessNetworksForSharedVolumes"`
|
||||
WitnessDatabaseWriteTimeout uint `mi:"WitnessDatabaseWriteTimeout"`
|
||||
WitnessDynamicWeight uint `mi:"WitnessDynamicWeight"`
|
||||
WitnessRestartInterval uint `mi:"WitnessRestartInterval"`
|
||||
}
|
||||
|
||||
func (c *Collector) buildCluster() {
|
||||
@@ -558,8 +562,8 @@ func (c *Collector) buildCluster() {
|
||||
|
||||
func (c *Collector) collectCluster(ch chan<- prometheus.Metric) error {
|
||||
var dst []msClusterCluster
|
||||
if err := c.wmiClient.Query("SELECT * FROM MSCluster_Cluster", &dst, nil, "root/MSCluster"); err != nil {
|
||||
return err
|
||||
if err := c.miSession.Query(&dst, mi.NamespaceRootMSCluster, utils.Must(mi.NewQuery("SELECT * MSCluster_Cluster"))); err != nil {
|
||||
return fmt.Errorf("WMI query failed: %w", err)
|
||||
}
|
||||
|
||||
for _, v := range dst {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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,22 +14,22 @@ const nameNode = Name + "_node"
|
||||
// msClusterNode represents the MSCluster_Node WMI class
|
||||
// - https://docs.microsoft.com/en-us/previous-versions/windows/desktop/cluswmi/mscluster-node
|
||||
type msClusterNode struct {
|
||||
Name string
|
||||
Name string `mi:"Name"`
|
||||
|
||||
BuildNumber uint
|
||||
Characteristics uint
|
||||
DetectedCloudPlatform uint
|
||||
DynamicWeight uint
|
||||
Flags uint
|
||||
MajorVersion uint
|
||||
MinorVersion uint
|
||||
NeedsPreventQuorum uint
|
||||
NodeDrainStatus uint
|
||||
NodeHighestVersion uint
|
||||
NodeLowestVersion uint
|
||||
NodeWeight uint
|
||||
State uint
|
||||
StatusInformation uint
|
||||
BuildNumber uint `mi:"BuildNumber"`
|
||||
Characteristics uint `mi:"Characteristics"`
|
||||
DetectedCloudPlatform uint `mi:"DetectedCloudPlatform"`
|
||||
DynamicWeight uint `mi:"DynamicWeight"`
|
||||
Flags uint `mi:"Flags"`
|
||||
MajorVersion uint `mi:"MajorVersion"`
|
||||
MinorVersion uint `mi:"MinorVersion"`
|
||||
NeedsPreventQuorum uint `mi:"NeedsPreventQuorum"`
|
||||
NodeDrainStatus uint `mi:"NodeDrainStatus"`
|
||||
NodeHighestVersion uint `mi:"NodeHighestVersion"`
|
||||
NodeLowestVersion uint `mi:"NodeLowestVersion"`
|
||||
NodeWeight uint `mi:"NodeWeight"`
|
||||
State uint `mi:"State"`
|
||||
StatusInformation uint `mi:"StatusInformation"`
|
||||
}
|
||||
|
||||
func (c *Collector) buildNode() {
|
||||
@@ -120,8 +124,8 @@ func (c *Collector) buildNode() {
|
||||
func (c *Collector) collectNode(ch chan<- prometheus.Metric) ([]string, error) {
|
||||
var dst []msClusterNode
|
||||
|
||||
if err := c.wmiClient.Query("SELECT * FROM MSCluster_Node", &dst, nil, "root/MSCluster"); err != nil {
|
||||
return nil, err
|
||||
if err := c.miSession.Query(&dst, mi.NamespaceRootMSCluster, utils.Must(mi.NewQuery("SELECT * FROM MSCluster_Node"))); err != nil {
|
||||
return nil, fmt.Errorf("WMI query failed: %w", err)
|
||||
}
|
||||
|
||||
nodeNames := make([]string, 0, len(dst))
|
||||
|
||||
@@ -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,27 +14,27 @@ const nameResource = Name + "_resource"
|
||||
// msClusterResource represents the MSCluster_Resource WMI class
|
||||
// - https://docs.microsoft.com/en-us/previous-versions/windows/desktop/cluswmi/mscluster-resource
|
||||
type msClusterResource struct {
|
||||
Name string
|
||||
Type string
|
||||
OwnerGroup string
|
||||
OwnerNode string
|
||||
Name string `mi:"Name"`
|
||||
Type string `mi:"Type"`
|
||||
OwnerGroup string `mi:"OwnerGroup"`
|
||||
OwnerNode string `mi:"OwnerNode"`
|
||||
|
||||
Characteristics uint
|
||||
DeadlockTimeout uint
|
||||
EmbeddedFailureAction uint
|
||||
Flags uint
|
||||
IsAlivePollInterval uint
|
||||
LooksAlivePollInterval uint
|
||||
MonitorProcessId uint
|
||||
PendingTimeout uint
|
||||
ResourceClass uint
|
||||
RestartAction uint
|
||||
RestartDelay uint
|
||||
RestartPeriod uint
|
||||
RestartThreshold uint
|
||||
RetryPeriodOnFailure uint
|
||||
State uint
|
||||
Subclass uint
|
||||
Characteristics uint `mi:"Characteristics"`
|
||||
DeadlockTimeout uint `mi:"DeadlockTimeout"`
|
||||
EmbeddedFailureAction uint `mi:"EmbeddedFailureAction"`
|
||||
Flags uint `mi:"Flags"`
|
||||
IsAlivePollInterval uint `mi:"IsAlivePollInterval"`
|
||||
LooksAlivePollInterval uint `mi:"LooksAlivePollInterval"`
|
||||
MonitorProcessId uint `mi:"MonitorProcessId"`
|
||||
PendingTimeout uint `mi:"PendingTimeout"`
|
||||
ResourceClass uint `mi:"ResourceClass"`
|
||||
RestartAction uint `mi:"RestartAction"`
|
||||
RestartDelay uint `mi:"RestartDelay"`
|
||||
RestartPeriod uint `mi:"RestartPeriod"`
|
||||
RestartThreshold uint `mi:"RestartThreshold"`
|
||||
RetryPeriodOnFailure uint `mi:"RetryPeriodOnFailure"`
|
||||
State uint `mi:"State"`
|
||||
Subclass uint `mi:"Subclass"`
|
||||
}
|
||||
|
||||
func (c *Collector) buildResource() {
|
||||
@@ -149,8 +153,8 @@ func (c *Collector) buildResource() {
|
||||
func (c *Collector) collectResource(ch chan<- prometheus.Metric, nodeNames []string) error {
|
||||
var dst []msClusterResource
|
||||
|
||||
if err := c.wmiClient.Query("SELECT * FROM MSCluster_Resource", &dst, nil, "root/MSCluster"); err != nil {
|
||||
return err
|
||||
if err := c.miSession.Query(&dst, mi.NamespaceRootMSCluster, utils.Must(mi.NewQuery("SELECT * FROM MSCluster_Resource"))); err != nil {
|
||||
return fmt.Errorf("WMI query failed: %w", err)
|
||||
}
|
||||
|
||||
for _, v := range dst {
|
||||
|
||||
@@ -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,22 +14,22 @@ const nameResourceGroup = Name + "_resourcegroup"
|
||||
// msClusterResourceGroup represents the MSCluster_ResourceGroup WMI class
|
||||
// - https://docs.microsoft.com/en-us/previous-versions/windows/desktop/cluswmi/mscluster-resourcegroup
|
||||
type msClusterResourceGroup struct {
|
||||
Name string
|
||||
Name string `mi:"Name"`
|
||||
|
||||
AutoFailbackType uint
|
||||
Characteristics uint
|
||||
ColdStartSetting uint
|
||||
DefaultOwner uint
|
||||
FailbackWindowEnd int
|
||||
FailbackWindowStart int
|
||||
FailoverPeriod uint
|
||||
FailoverThreshold uint
|
||||
Flags uint
|
||||
GroupType uint
|
||||
OwnerNode string
|
||||
Priority uint
|
||||
ResiliencyPeriod uint
|
||||
State uint
|
||||
AutoFailbackType uint `mi:"AutoFailbackType"`
|
||||
Characteristics uint `mi:"Characteristics"`
|
||||
ColdStartSetting uint `mi:"ColdStartSetting"`
|
||||
DefaultOwner uint `mi:"DefaultOwner"`
|
||||
FailbackWindowEnd int `mi:"FailbackWindowEnd"`
|
||||
FailbackWindowStart int `mi:"FailbackWindowStart"`
|
||||
FailoverPeriod uint `mi:"FailoverPeriod"`
|
||||
FailoverThreshold uint `mi:"FailoverThreshold"`
|
||||
Flags uint `mi:"Flags"`
|
||||
GroupType uint `mi:"GroupType"`
|
||||
OwnerNode string `mi:"OwnerNode"`
|
||||
Priority uint `mi:"Priority"`
|
||||
ResiliencyPeriod uint `mi:"ResiliencyPeriod"`
|
||||
State uint `mi:"State"`
|
||||
}
|
||||
|
||||
func (c *Collector) buildResourceGroup() {
|
||||
@@ -126,8 +130,8 @@ func (c *Collector) buildResourceGroup() {
|
||||
func (c *Collector) collectResourceGroup(ch chan<- prometheus.Metric, nodeNames []string) error {
|
||||
var dst []msClusterResourceGroup
|
||||
|
||||
if err := c.wmiClient.Query("SELECT * FROM MSCluster_ResourceGroup", &dst, nil, "root/MSCluster"); err != nil {
|
||||
return err
|
||||
if err := c.miSession.Query(&dst, mi.NamespaceRootMSCluster, utils.Must(mi.NewQuery("SELECT * FROM MSCluster_ResourceGroup"))); err != nil {
|
||||
return fmt.Errorf("WMI query failed: %w", err)
|
||||
}
|
||||
|
||||
for _, v := range dst {
|
||||
|
||||
@@ -4,14 +4,15 @@ package msmq
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"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"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
)
|
||||
|
||||
const Name = "msmq"
|
||||
@@ -27,7 +28,7 @@ var ConfigDefaults = Config{
|
||||
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_MSMQ_MSMQQueue metrics.
|
||||
type Collector struct {
|
||||
config Config
|
||||
wmiClient *wmi.Client
|
||||
miSession *mi.Session
|
||||
|
||||
bytesInJournalQueue *prometheus.Desc
|
||||
bytesInQueue *prometheus.Desc
|
||||
@@ -75,14 +76,14 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(logger *slog.Logger, wmiClient *wmi.Client) error {
|
||||
func (c *Collector) Build(logger *slog.Logger, miSession *mi.Session) error {
|
||||
logger = logger.With(slog.String("collector", Name))
|
||||
|
||||
if wmiClient == nil || wmiClient.SWbemServicesClient == nil {
|
||||
return errors.New("wmiClient or SWbemServicesClient is nil")
|
||||
if miSession == nil {
|
||||
return errors.New("miSession is nil")
|
||||
}
|
||||
|
||||
c.wmiClient = wmiClient
|
||||
c.miSession = miSession
|
||||
|
||||
if *c.config.QueryWhereClause == "" {
|
||||
logger.Warn("No where-clause specified for msmq collector. This will generate a very large number of metrics!")
|
||||
@@ -132,12 +133,12 @@ func (c *Collector) Collect(_ *types.ScrapeContext, logger *slog.Logger, ch chan
|
||||
}
|
||||
|
||||
type msmqQueue struct {
|
||||
Name string
|
||||
Name string `mi:"Name"`
|
||||
|
||||
BytesInJournalQueue uint64
|
||||
BytesInQueue uint64
|
||||
MessagesInJournalQueue uint64
|
||||
MessagesInQueue uint64
|
||||
BytesInJournalQueue uint64 `mi:"BytesInJournalQueue"`
|
||||
BytesInQueue uint64 `mi:"BytesInQueue"`
|
||||
MessagesInJournalQueue uint64 `mi:"MessagesInJournalQueue"`
|
||||
MessagesInQueue uint64 `mi:"MessagesInQueue"`
|
||||
}
|
||||
|
||||
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||
@@ -148,8 +149,13 @@ func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||
query += " WHERE " + *c.config.QueryWhereClause
|
||||
}
|
||||
|
||||
if err := c.wmiClient.Query(query, &dst); err != nil {
|
||||
return err
|
||||
queryExpression, err := mi.NewQuery(query)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create WMI query: %w", err)
|
||||
}
|
||||
|
||||
if err := c.miSession.Query(&dst, mi.NamespaceRootCIMv2, queryExpression); err != nil {
|
||||
return fmt.Errorf("WMI query failed: %w", err)
|
||||
}
|
||||
|
||||
for _, msmq := range dst {
|
||||
|
||||
@@ -13,10 +13,10 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
v1 "github.com/prometheus-community/windows_exporter/internal/perfdata/v1"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
"golang.org/x/sys/windows/registry"
|
||||
)
|
||||
|
||||
@@ -508,7 +508,7 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *wmi.Client) error {
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
|
||||
// Result must order, to prevent test failures.
|
||||
sort.Strings(c.config.CollectorsEnabled)
|
||||
|
||||
|
||||
@@ -13,12 +13,12 @@ import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/perfdata"
|
||||
v1 "github.com/prometheus-community/windows_exporter/internal/perfdata/v1"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus-community/windows_exporter/internal/utils"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
@@ -149,7 +149,7 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(logger *slog.Logger, _ *wmi.Client) error {
|
||||
func (c *Collector) Build(logger *slog.Logger, _ *mi.Session) error {
|
||||
if utils.PDHEnabled() {
|
||||
counters := []string{
|
||||
BytesReceivedPerSec,
|
||||
|
||||
@@ -9,9 +9,9 @@ import (
|
||||
"slices"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
)
|
||||
|
||||
const Name = "netframework"
|
||||
@@ -47,7 +47,7 @@ const (
|
||||
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRExceptions metrics.
|
||||
type Collector struct {
|
||||
config Config
|
||||
wmiClient *wmi.Client
|
||||
miSession *mi.Session
|
||||
|
||||
// clrexceptions
|
||||
numberOfExceptionsThrown *prometheus.Desc
|
||||
@@ -143,12 +143,12 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(_ *slog.Logger, wmiClient *wmi.Client) error {
|
||||
if wmiClient == nil || wmiClient.SWbemServicesClient == nil {
|
||||
return errors.New("wmiClient or SWbemServicesClient is nil")
|
||||
func (c *Collector) Build(_ *slog.Logger, miSession *mi.Session) error {
|
||||
if miSession == nil {
|
||||
return errors.New("miSession is nil")
|
||||
}
|
||||
|
||||
c.wmiClient = wmiClient
|
||||
c.miSession = miSession
|
||||
|
||||
if slices.Contains(c.config.CollectorsEnabled, collectorClrExceptions) {
|
||||
c.buildClrExceptions()
|
||||
|
||||
@@ -3,7 +3,11 @@
|
||||
package netframework
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
@@ -35,19 +39,19 @@ func (c *Collector) buildClrExceptions() {
|
||||
}
|
||||
|
||||
type Win32_PerfRawData_NETFramework_NETCLRExceptions struct {
|
||||
Name string
|
||||
Name string `mi:"Name"`
|
||||
|
||||
NumberofExcepsThrown uint32
|
||||
NumberofExcepsThrownPersec uint32
|
||||
NumberofFiltersPersec uint32
|
||||
NumberofFinallysPersec uint32
|
||||
ThrowToCatchDepthPersec uint32
|
||||
NumberofExcepsThrown uint32 `mi:"NumberofExcepsThrown"`
|
||||
NumberofExcepsThrownPersec uint32 `mi:"NumberofExcepsThrownPersec"`
|
||||
NumberofFiltersPersec uint32 `mi:"NumberofFiltersPersec"`
|
||||
NumberofFinallysPersec uint32 `mi:"NumberofFinallysPersec"`
|
||||
ThrowToCatchDepthPersec uint32 `mi:"ThrowToCatchDepthPersec"`
|
||||
}
|
||||
|
||||
func (c *Collector) collectClrExceptions(ch chan<- prometheus.Metric) error {
|
||||
var dst []Win32_PerfRawData_NETFramework_NETCLRExceptions
|
||||
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_NETFramework_NETCLRExceptions", &dst); err != nil {
|
||||
return err
|
||||
if err := c.miSession.Query(&dst, mi.NamespaceRootCIMv2, utils.Must(mi.NewQuery("SELECT * Win32_PerfRawData_NETFramework_NETCLRExceptions"))); err != nil {
|
||||
return fmt.Errorf("WMI query failed: %w", err)
|
||||
}
|
||||
|
||||
for _, process := range dst {
|
||||
|
||||
@@ -3,7 +3,11 @@
|
||||
package netframework
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
@@ -29,19 +33,19 @@ func (c *Collector) buildClrInterop() {
|
||||
}
|
||||
|
||||
type Win32_PerfRawData_NETFramework_NETCLRInterop struct {
|
||||
Name string
|
||||
Name string `mi:"Name"`
|
||||
|
||||
NumberofCCWs uint32
|
||||
Numberofmarshalling uint32
|
||||
NumberofStubs uint32
|
||||
NumberofTLBexportsPersec uint32
|
||||
NumberofTLBimportsPersec uint32
|
||||
NumberofCCWs uint32 `mi:"NumberofCCWs"`
|
||||
Numberofmarshalling uint32 `mi:"Numberofmarshalling"`
|
||||
NumberofStubs uint32 `mi:"NumberofStubs"`
|
||||
NumberofTLBexportsPersec uint32 `mi:"NumberofTLBexportsPersec"`
|
||||
NumberofTLBimportsPersec uint32 `mi:"NumberofTLBimportsPersec"`
|
||||
}
|
||||
|
||||
func (c *Collector) collectClrInterop(ch chan<- prometheus.Metric) error {
|
||||
var dst []Win32_PerfRawData_NETFramework_NETCLRInterop
|
||||
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_NETFramework_NETCLRInterop", &dst); err != nil {
|
||||
return err
|
||||
if err := c.miSession.Query(&dst, mi.NamespaceRootCIMv2, utils.Must(mi.NewQuery("SELECT * Win32_PerfRawData_NETFramework_NETCLRInterop"))); err != nil {
|
||||
return fmt.Errorf("WMI query failed: %w", err)
|
||||
}
|
||||
|
||||
for _, process := range dst {
|
||||
|
||||
@@ -3,7 +3,11 @@
|
||||
package netframework
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
@@ -35,21 +39,21 @@ func (c *Collector) buildClrJIT() {
|
||||
}
|
||||
|
||||
type Win32_PerfRawData_NETFramework_NETCLRJit struct {
|
||||
Name string
|
||||
Name string `mi:"Name"`
|
||||
|
||||
Frequency_PerfTime uint32
|
||||
ILBytesJittedPersec uint32
|
||||
NumberofILBytesJitted uint32
|
||||
NumberofMethodsJitted uint32
|
||||
PercentTimeinJit uint32
|
||||
StandardJitFailures uint32
|
||||
TotalNumberofILBytesJitted uint32
|
||||
Frequency_PerfTime uint32 `mi:"Frequency_PerfTime"`
|
||||
ILBytesJittedPersec uint32 `mi:"ILBytesJittedPersec"`
|
||||
NumberofILBytesJitted uint32 `mi:"NumberofILBytesJitted"`
|
||||
NumberofMethodsJitted uint32 `mi:"NumberofMethodsJitted"`
|
||||
PercentTimeinJit uint32 `mi:"PercentTimeinJit"`
|
||||
StandardJitFailures uint32 `mi:"StandardJitFailures"`
|
||||
TotalNumberofILBytesJitted uint32 `mi:"TotalNumberofILBytesJitted"`
|
||||
}
|
||||
|
||||
func (c *Collector) collectClrJIT(ch chan<- prometheus.Metric) error {
|
||||
var dst []Win32_PerfRawData_NETFramework_NETCLRJit
|
||||
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_NETFramework_NETCLRJit", &dst); err != nil {
|
||||
return err
|
||||
if err := c.miSession.Query(&dst, mi.NamespaceRootCIMv2, utils.Must(mi.NewQuery("SELECT * Win32_PerfRawData_NETFramework_NETCLRJit"))); err != nil {
|
||||
return fmt.Errorf("WMI query failed: %w", err)
|
||||
}
|
||||
|
||||
for _, process := range dst {
|
||||
|
||||
@@ -3,7 +3,11 @@
|
||||
package netframework
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
@@ -65,30 +69,30 @@ func (c *Collector) buildClrLoading() {
|
||||
}
|
||||
|
||||
type Win32_PerfRawData_NETFramework_NETCLRLoading struct {
|
||||
Name string
|
||||
Name string `mi:"Name"`
|
||||
|
||||
AssemblySearchLength uint32
|
||||
BytesinLoaderHeap uint64
|
||||
Currentappdomains uint32
|
||||
CurrentAssemblies uint32
|
||||
CurrentClassesLoaded uint32
|
||||
PercentTimeLoading uint64
|
||||
Rateofappdomains uint32
|
||||
Rateofappdomainsunloaded uint32
|
||||
RateofAssemblies uint32
|
||||
RateofClassesLoaded uint32
|
||||
RateofLoadFailures uint32
|
||||
TotalAppdomains uint32
|
||||
Totalappdomainsunloaded uint32
|
||||
TotalAssemblies uint32
|
||||
TotalClassesLoaded uint32
|
||||
TotalNumberofLoadFailures uint32
|
||||
AssemblySearchLength uint32 `mi:"AssemblySearchLength"`
|
||||
BytesinLoaderHeap uint64 `mi:"BytesinLoaderHeap"`
|
||||
Currentappdomains uint32 `mi:"Currentappdomains"`
|
||||
CurrentAssemblies uint32 `mi:"CurrentAssemblies"`
|
||||
CurrentClassesLoaded uint32 `mi:"CurrentClassesLoaded"`
|
||||
PercentTimeLoading uint64 `mi:"PercentTimeLoading"`
|
||||
Rateofappdomains uint32 `mi:"Rateofappdomains"`
|
||||
Rateofappdomainsunloaded uint32 `mi:"Rateofappdomainsunloaded"`
|
||||
RateofAssemblies uint32 `mi:"RateofAssemblies"`
|
||||
RateofClassesLoaded uint32 `mi:"RateofClassesLoaded"`
|
||||
RateofLoadFailures uint32 `mi:"RateofLoadFailures"`
|
||||
TotalAppdomains uint32 `mi:"TotalAppdomains"`
|
||||
Totalappdomainsunloaded uint32 `mi:"Totalappdomainsunloaded"`
|
||||
TotalAssemblies uint32 `mi:"TotalAssemblies"`
|
||||
TotalClassesLoaded uint32 `mi:"TotalClassesLoaded"`
|
||||
TotalNumberofLoadFailures uint32 `mi:"TotalNumberofLoadFailures"`
|
||||
}
|
||||
|
||||
func (c *Collector) collectClrLoading(ch chan<- prometheus.Metric) error {
|
||||
var dst []Win32_PerfRawData_NETFramework_NETCLRLoading
|
||||
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_NETFramework_NETCLRLoading", &dst); err != nil {
|
||||
return err
|
||||
if err := c.miSession.Query(&dst, mi.NamespaceRootCIMv2, utils.Must(mi.NewQuery("SELECT * Win32_PerfRawData_NETFramework_NETCLRLoading"))); err != nil {
|
||||
return fmt.Errorf("WMI query failed: %w", err)
|
||||
}
|
||||
|
||||
for _, process := range dst {
|
||||
|
||||
@@ -3,7 +3,11 @@
|
||||
package netframework
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
@@ -53,24 +57,24 @@ func (c *Collector) buildClrLocksAndThreads() {
|
||||
}
|
||||
|
||||
type Win32_PerfRawData_NETFramework_NETCLRLocksAndThreads struct {
|
||||
Name string
|
||||
Name string `mi:"Name"`
|
||||
|
||||
ContentionRatePersec uint32
|
||||
CurrentQueueLength uint32
|
||||
NumberofcurrentlogicalThreads uint32
|
||||
NumberofcurrentphysicalThreads uint32
|
||||
Numberofcurrentrecognizedthreads uint32
|
||||
Numberoftotalrecognizedthreads uint32
|
||||
QueueLengthPeak uint32
|
||||
QueueLengthPersec uint32
|
||||
RateOfRecognizedThreadsPersec uint32
|
||||
TotalNumberofContentions uint32
|
||||
ContentionRatePersec uint32 `mi:"ContentionRatePersec"`
|
||||
CurrentQueueLength uint32 `mi:"CurrentQueueLength"`
|
||||
NumberofcurrentlogicalThreads uint32 `mi:"NumberofcurrentlogicalThreads"`
|
||||
NumberofcurrentphysicalThreads uint32 `mi:"NumberofcurrentphysicalThreads"`
|
||||
Numberofcurrentrecognizedthreads uint32 `mi:"Numberofcurrentrecognizedthreads"`
|
||||
Numberoftotalrecognizedthreads uint32 `mi:"Numberoftotalrecognizedthreads"`
|
||||
QueueLengthPeak uint32 `mi:"QueueLengthPeak"`
|
||||
QueueLengthPersec uint32 `mi:"QueueLengthPersec"`
|
||||
RateOfRecognizedThreadsPersec uint32 `mi:"RateOfRecognizedThreadsPersec"`
|
||||
TotalNumberofContentions uint32 `mi:"TotalNumberofContentions"`
|
||||
}
|
||||
|
||||
func (c *Collector) collectClrLocksAndThreads(ch chan<- prometheus.Metric) error {
|
||||
var dst []Win32_PerfRawData_NETFramework_NETCLRLocksAndThreads
|
||||
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_NETFramework_NETCLRLocksAndThreads", &dst); err != nil {
|
||||
return err
|
||||
if err := c.miSession.Query(&dst, mi.NamespaceRootCIMv2, utils.Must(mi.NewQuery("SELECT * Win32_PerfRawData_NETFramework_NETCLRLocksAndThreads"))); err != nil {
|
||||
return fmt.Errorf("WMI query failed: %w", err)
|
||||
}
|
||||
|
||||
for _, process := range dst {
|
||||
|
||||
@@ -3,7 +3,11 @@
|
||||
package netframework
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
@@ -83,43 +87,43 @@ func (c *Collector) buildClrMemory() {
|
||||
}
|
||||
|
||||
type Win32_PerfRawData_NETFramework_NETCLRMemory struct {
|
||||
Name string
|
||||
Name string `mi:"Name"`
|
||||
|
||||
AllocatedBytesPersec uint64
|
||||
FinalizationSurvivors uint64
|
||||
Frequency_PerfTime uint64
|
||||
Gen0heapsize uint64
|
||||
Gen0PromotedBytesPerSec uint64
|
||||
Gen1heapsize uint64
|
||||
Gen1PromotedBytesPerSec uint64
|
||||
Gen2heapsize uint64
|
||||
LargeObjectHeapsize uint64
|
||||
NumberBytesinallHeaps uint64
|
||||
NumberGCHandles uint64
|
||||
NumberGen0Collections uint64
|
||||
NumberGen1Collections uint64
|
||||
NumberGen2Collections uint64
|
||||
NumberInducedGC uint64
|
||||
NumberofPinnedObjects uint64
|
||||
NumberofSinkBlocksinuse uint64
|
||||
NumberTotalcommittedBytes uint64
|
||||
NumberTotalreservedBytes uint64
|
||||
AllocatedBytesPersec uint64 `mi:"AllocatedBytesPersec"`
|
||||
FinalizationSurvivors uint64 `mi:"FinalizationSurvivors"`
|
||||
Frequency_PerfTime uint64 `mi:"Frequency_PerfTime"`
|
||||
Gen0heapsize uint64 `mi:"Gen0heapsize"`
|
||||
Gen0PromotedBytesPerSec uint64 `mi:"Gen0PromotedBytesPersec"`
|
||||
Gen1heapsize uint64 `mi:"Gen1heapsize"`
|
||||
Gen1PromotedBytesPerSec uint64 `mi:"Gen1PromotedBytesPersec"`
|
||||
Gen2heapsize uint64 `mi:"Gen2heapsize"`
|
||||
LargeObjectHeapsize uint64 `mi:"LargeObjectHeapsize"`
|
||||
NumberBytesinallHeaps uint64 `mi:"NumberBytesinallHeaps"`
|
||||
NumberGCHandles uint64 `mi:"NumberGCHandles"`
|
||||
NumberGen0Collections uint64 `mi:"NumberGen0Collections"`
|
||||
NumberGen1Collections uint64 `mi:"NumberGen1Collections"`
|
||||
NumberGen2Collections uint64 `mi:"NumberGen2Collections"`
|
||||
NumberInducedGC uint64 `mi:"NumberInducedGC"`
|
||||
NumberofPinnedObjects uint64 `mi:"NumberofPinnedObjects"`
|
||||
NumberofSinkBlocksinuse uint64 `mi:"NumberofSinkBlocksinuse"`
|
||||
NumberTotalcommittedBytes uint64 `mi:"NumberTotalcommittedBytes"`
|
||||
NumberTotalreservedBytes uint64 `mi:"NumberTotalreservedBytes"`
|
||||
// PercentTimeinGC has countertype=PERF_RAW_FRACTION.
|
||||
// Formula: (100 * CounterValue) / BaseValue
|
||||
// By docs https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/scripting-articles/ms974615(v=msdn.10)#perf_raw_fraction
|
||||
PercentTimeinGC uint32
|
||||
PercentTimeinGC uint32 `mi:"PercentTimeinGC"`
|
||||
// BaseValue is just a "magic" number used to make the calculation come out right.
|
||||
PercentTimeinGC_base uint32
|
||||
ProcessID uint64
|
||||
PromotedFinalizationMemoryfromGen0 uint64
|
||||
PromotedMemoryfromGen0 uint64
|
||||
PromotedMemoryfromGen1 uint64
|
||||
PercentTimeinGC_base uint32 `mi:"PercentTimeinGC_base"`
|
||||
ProcessID uint64 `mi:"ProcessID"`
|
||||
PromotedFinalizationMemoryfromGen0 uint64 `mi:"PromotedFinalizationMemoryfromGen0"`
|
||||
PromotedMemoryfromGen0 uint64 `mi:"PromotedMemoryfromGen0"`
|
||||
PromotedMemoryfromGen1 uint64 `mi:"PromotedMemoryfromGen1"`
|
||||
}
|
||||
|
||||
func (c *Collector) collectClrMemory(ch chan<- prometheus.Metric) error {
|
||||
var dst []Win32_PerfRawData_NETFramework_NETCLRMemory
|
||||
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_NETFramework_NETCLRMemory", &dst); err != nil {
|
||||
return err
|
||||
if err := c.miSession.Query(&dst, mi.NamespaceRootCIMv2, utils.Must(mi.NewQuery("SELECT * Win32_PerfRawData_NETFramework_NETCLRMemory"))); err != nil {
|
||||
return fmt.Errorf("WMI query failed: %w", err)
|
||||
}
|
||||
|
||||
for _, process := range dst {
|
||||
|
||||
@@ -3,7 +3,11 @@
|
||||
package netframework
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
@@ -47,21 +51,21 @@ func (c *Collector) buildClrRemoting() {
|
||||
}
|
||||
|
||||
type Win32_PerfRawData_NETFramework_NETCLRRemoting struct {
|
||||
Name string
|
||||
Name string `mi:"Name"`
|
||||
|
||||
Channels uint32
|
||||
ContextBoundClassesLoaded uint32
|
||||
ContextBoundObjectsAllocPersec uint32
|
||||
ContextProxies uint32
|
||||
Contexts uint32
|
||||
RemoteCallsPersec uint32
|
||||
TotalRemoteCalls uint32
|
||||
Channels uint32 `mi:"Channels"`
|
||||
ContextBoundClassesLoaded uint32 `mi:"ContextBoundClassesLoaded"`
|
||||
ContextBoundObjectsAllocPersec uint32 `mi:"ContextBoundObjectsAllocPersec"`
|
||||
ContextProxies uint32 `mi:"ContextProxies"`
|
||||
Contexts uint32 `mi:"Contexts"`
|
||||
RemoteCallsPersec uint32 `mi:"RemoteCallsPersec"`
|
||||
TotalRemoteCalls uint32 `mi:"TotalRemoteCalls"`
|
||||
}
|
||||
|
||||
func (c *Collector) collectClrRemoting(ch chan<- prometheus.Metric) error {
|
||||
var dst []Win32_PerfRawData_NETFramework_NETCLRRemoting
|
||||
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_NETFramework_NETCLRRemoting", &dst); err != nil {
|
||||
return err
|
||||
if err := c.miSession.Query(&dst, mi.NamespaceRootCIMv2, utils.Must(mi.NewQuery("SELECT * Win32_PerfRawData_NETFramework_NETCLRRemoting"))); err != nil {
|
||||
return fmt.Errorf("WMI query failed: %w", err)
|
||||
}
|
||||
|
||||
for _, process := range dst {
|
||||
|
||||
@@ -3,7 +3,11 @@
|
||||
package netframework
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
@@ -35,20 +39,20 @@ func (c *Collector) buildClrSecurity() {
|
||||
}
|
||||
|
||||
type Win32_PerfRawData_NETFramework_NETCLRSecurity struct {
|
||||
Name string
|
||||
Name string `mi:"Name"`
|
||||
|
||||
Frequency_PerfTime uint32
|
||||
NumberLinkTimeChecks uint32
|
||||
PercentTimeinRTchecks uint32
|
||||
PercentTimeSigAuthenticating uint64
|
||||
StackWalkDepth uint32
|
||||
TotalRuntimeChecks uint32
|
||||
Frequency_PerfTime uint32 `mi:"Frequency_PerfTime"`
|
||||
NumberLinkTimeChecks uint32 `mi:"NumberLinkTimeChecks"`
|
||||
PercentTimeinRTchecks uint32 `mi:"PercentTimeinRTchecks"`
|
||||
PercentTimeSigAuthenticating uint64 `mi:"PercentTimeSigAuthenticating"`
|
||||
StackWalkDepth uint32 `mi:"StackWalkDepth"`
|
||||
TotalRuntimeChecks uint32 `mi:"TotalRuntimeChecks"`
|
||||
}
|
||||
|
||||
func (c *Collector) collectClrSecurity(ch chan<- prometheus.Metric) error {
|
||||
var dst []Win32_PerfRawData_NETFramework_NETCLRSecurity
|
||||
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_NETFramework_NETCLRSecurity", &dst); err != nil {
|
||||
return err
|
||||
if err := c.miSession.Query(&dst, mi.NamespaceRootCIMv2, utils.Must(mi.NewQuery("SELECT * Win32_PerfRawData_NETFramework_NETCLRSecurity"))); err != nil {
|
||||
return fmt.Errorf("WMI query failed: %w", err)
|
||||
}
|
||||
|
||||
for _, process := range dst {
|
||||
|
||||
@@ -6,9 +6,9 @@ import (
|
||||
"log/slog"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
)
|
||||
|
||||
const Name = "nps"
|
||||
@@ -20,7 +20,10 @@ var ConfigDefaults = Config{}
|
||||
// Collector is a Prometheus Collector for WMI Win32_PerfRawData_IAS_NPSAuthenticationServer and Win32_PerfRawData_IAS_NPSAccountingServer metrics.
|
||||
type Collector struct {
|
||||
config Config
|
||||
wmiClient *wmi.Client
|
||||
miSession *mi.Session
|
||||
|
||||
miQueryAuthenticationServer mi.Query
|
||||
miQueryAccountingServer mi.Query
|
||||
|
||||
accessAccepts *prometheus.Desc
|
||||
accessChallenges *prometheus.Desc
|
||||
@@ -78,12 +81,26 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(_ *slog.Logger, wmiClient *wmi.Client) error {
|
||||
if wmiClient == nil || wmiClient.SWbemServicesClient == nil {
|
||||
return errors.New("wmiClient or SWbemServicesClient is nil")
|
||||
func (c *Collector) Build(_ *slog.Logger, miSession *mi.Session) error {
|
||||
if miSession == nil {
|
||||
return errors.New("miSession is nil")
|
||||
}
|
||||
|
||||
c.wmiClient = wmiClient
|
||||
miQuery, err := mi.NewQuery("SELECT Name, AccessAccepts, AccessChallenges, AccessRejects, AccessRequests, AccessBadAuthenticators, AccessDroppedPackets, AccessInvalidRequests, AccessMalformedPackets, AccessPacketsReceived, AccessPacketsSent, AccessServerResetTime, AccessServerUpTime, AccessUnknownType FROM Win32_PerfRawData_IAS_NPSAuthenticationServer")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create WMI query: %w", err)
|
||||
}
|
||||
|
||||
c.miQueryAuthenticationServer = miQuery
|
||||
|
||||
miQuery, err = mi.NewQuery("SELECT Name, AccountingRequests, AccountingResponses, AccountingBadAuthenticators, AccountingDroppedPackets, AccountingInvalidRequests, AccountingMalformedPackets, AccountingNoRecord, AccountingPacketsReceived, AccountingPacketsSent, AccountingServerResetTime, AccountingServerUpTime, AccountingUnknownType FROM Win32_PerfRawData_IAS_NPSAccountingServer")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create WMI query: %w", err)
|
||||
}
|
||||
|
||||
c.miQueryAccountingServer = miQuery
|
||||
c.miSession = miSession
|
||||
|
||||
c.accessAccepts = prometheus.NewDesc(
|
||||
prometheus.BuildFQName(types.Namespace, Name, "access_accepts"),
|
||||
"(AccessAccepts)",
|
||||
@@ -261,46 +278,46 @@ func (c *Collector) Collect(_ *types.ScrapeContext, logger *slog.Logger, ch chan
|
||||
// Win32_PerfRawData_IAS_NPSAuthenticationServer docs:
|
||||
// at the moment there is no Microsoft documentation.
|
||||
type Win32_PerfRawData_IAS_NPSAuthenticationServer struct {
|
||||
Name string
|
||||
Name string `mi:"Name"`
|
||||
|
||||
AccessAccepts uint32
|
||||
AccessChallenges uint32
|
||||
AccessRejects uint32
|
||||
AccessRequests uint32
|
||||
AccessBadAuthenticators uint32
|
||||
AccessDroppedPackets uint32
|
||||
AccessInvalidRequests uint32
|
||||
AccessMalformedPackets uint32
|
||||
AccessPacketsReceived uint32
|
||||
AccessPacketsSent uint32
|
||||
AccessServerResetTime uint32
|
||||
AccessServerUpTime uint32
|
||||
AccessUnknownType uint32
|
||||
AccessAccepts uint32 `mi:"AccessAccepts"`
|
||||
AccessChallenges uint32 `mi:"AccessChallenges"`
|
||||
AccessRejects uint32 `mi:"AccessRejects"`
|
||||
AccessRequests uint32 `mi:"AccessRequests"`
|
||||
AccessBadAuthenticators uint32 `mi:"AccessBadAuthenticators"`
|
||||
AccessDroppedPackets uint32 `mi:"AccessDroppedPackets"`
|
||||
AccessInvalidRequests uint32 `mi:"AccessInvalidRequests"`
|
||||
AccessMalformedPackets uint32 `mi:"AccessMalformedPackets"`
|
||||
AccessPacketsReceived uint32 `mi:"AccessPacketsReceived"`
|
||||
AccessPacketsSent uint32 `mi:"AccessPacketsSent"`
|
||||
AccessServerResetTime uint32 `mi:"AccessServerResetTime"`
|
||||
AccessServerUpTime uint32 `mi:"AccessServerUpTime"`
|
||||
AccessUnknownType uint32 `mi:"AccessUnknownType"`
|
||||
}
|
||||
|
||||
type Win32_PerfRawData_IAS_NPSAccountingServer struct {
|
||||
Name string
|
||||
Name string `mi:"Name"`
|
||||
|
||||
AccountingRequests uint32
|
||||
AccountingResponses uint32
|
||||
AccountingBadAuthenticators uint32
|
||||
AccountingDroppedPackets uint32
|
||||
AccountingInvalidRequests uint32
|
||||
AccountingMalformedPackets uint32
|
||||
AccountingNoRecord uint32
|
||||
AccountingPacketsReceived uint32
|
||||
AccountingPacketsSent uint32
|
||||
AccountingServerResetTime uint32
|
||||
AccountingServerUpTime uint32
|
||||
AccountingUnknownType uint32
|
||||
AccountingRequests uint32 `mi:"AccountingRequests"`
|
||||
AccountingResponses uint32 `mi:"AccountingResponses"`
|
||||
AccountingBadAuthenticators uint32 `mi:"AccountingBadAuthenticators"`
|
||||
AccountingDroppedPackets uint32 `mi:"AccountingDroppedPackets"`
|
||||
AccountingInvalidRequests uint32 `mi:"AccountingInvalidRequests"`
|
||||
AccountingMalformedPackets uint32 `mi:"AccountingMalformedPackets"`
|
||||
AccountingNoRecord uint32 `mi:"AccountingNoRecord"`
|
||||
AccountingPacketsReceived uint32 `mi:"AccountingPacketsReceived"`
|
||||
AccountingPacketsSent uint32 `mi:"AccountingPacketsSent"`
|
||||
AccountingServerResetTime uint32 `mi:"AccountingServerResetTime"`
|
||||
AccountingServerUpTime uint32 `mi:"AccountingServerUpTime"`
|
||||
AccountingUnknownType uint32 `mi:"AccountingUnknownType"`
|
||||
}
|
||||
|
||||
// CollectAccept sends the metric values for each metric
|
||||
// to the provided prometheus Metric channel.
|
||||
func (c *Collector) CollectAccept(ch chan<- prometheus.Metric) error {
|
||||
var dst []Win32_PerfRawData_IAS_NPSAuthenticationServer
|
||||
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_IAS_NPSAuthenticationServer", &dst); err != nil {
|
||||
return err
|
||||
if err := c.miSession.Query(&dst, mi.NamespaceRootCIMv2, c.miQueryAuthenticationServer); err != nil {
|
||||
return fmt.Errorf("WMI query failed: %w", err)
|
||||
}
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
@@ -386,8 +403,8 @@ func (c *Collector) CollectAccept(ch chan<- prometheus.Metric) error {
|
||||
|
||||
func (c *Collector) CollectAccounting(ch chan<- prometheus.Metric) error {
|
||||
var dst []Win32_PerfRawData_IAS_NPSAccountingServer
|
||||
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_IAS_NPSAccountingServer", &dst); err != nil {
|
||||
return err
|
||||
if err := c.miSession.Query(&dst, mi.NamespaceRootCIMv2, c.miQueryAccountingServer); err != nil {
|
||||
return fmt.Errorf("WMI query failed: %w", err)
|
||||
}
|
||||
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
|
||||
@@ -16,10 +16,10 @@ import (
|
||||
"github.com/prometheus-community/windows_exporter/internal/headers/netapi32"
|
||||
"github.com/prometheus-community/windows_exporter/internal/headers/psapi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/headers/sysinfoapi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
v1 "github.com/prometheus-community/windows_exporter/internal/perfdata/v1"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
"golang.org/x/sys/windows"
|
||||
"golang.org/x/sys/windows/registry"
|
||||
)
|
||||
@@ -109,9 +109,11 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(logger *slog.Logger, _ *wmi.Client) error {
|
||||
logger.Warn("The os collect holds a number of deprecated metrics and will be removed mid 2025. " +
|
||||
"See https://github.com/prometheus-community/windows_exporter/pull/1596 for more information.")
|
||||
func (c *Collector) Build(logger *slog.Logger, _ *mi.Session) error {
|
||||
logger.Warn("The os collect holds a number of deprecated metrics and will be removed mid 2025. "+
|
||||
"See https://github.com/prometheus-community/windows_exporter/pull/1596 for more information.",
|
||||
slog.String("collector", Name),
|
||||
)
|
||||
|
||||
workstationInfo, err := netapi32.GetWorkstationInfo()
|
||||
if err != nil {
|
||||
|
||||
@@ -11,11 +11,11 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/perfdata"
|
||||
"github.com/prometheus-community/windows_exporter/internal/perfdata/perftypes"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
)
|
||||
|
||||
const Name = "perfdata"
|
||||
@@ -92,7 +92,7 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(logger *slog.Logger, _ *wmi.Client) error {
|
||||
func (c *Collector) Build(logger *slog.Logger, _ *mi.Session) error {
|
||||
logger.Warn("The perfdata collector is in an experimental state! The configuration may change in future. Please report any issues.")
|
||||
|
||||
for i, object := range c.config.Objects {
|
||||
|
||||
@@ -9,11 +9,11 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/perfdata/perftypes"
|
||||
v1 "github.com/prometheus-community/windows_exporter/internal/perfdata/v1"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
)
|
||||
|
||||
const Name = "physical_disk"
|
||||
@@ -114,7 +114,7 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *wmi.Client) error {
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
|
||||
c.requestsQueued = prometheus.NewDesc(
|
||||
prometheus.BuildFQName(types.Namespace, Name, "requests_queued"),
|
||||
"The number of requests queued to the disk (PhysicalDisk.CurrentDiskQueueLength)",
|
||||
|
||||
@@ -10,9 +10,9 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
)
|
||||
|
||||
const Name = "printer"
|
||||
@@ -39,8 +39,10 @@ var ConfigDefaults = Config{
|
||||
}
|
||||
|
||||
type Collector struct {
|
||||
config Config
|
||||
wmiClient *wmi.Client
|
||||
config Config
|
||||
miSession *mi.Session
|
||||
miQueryPrinterJobs mi.Query
|
||||
miQueryPrinter mi.Query
|
||||
|
||||
printerStatus *prometheus.Desc
|
||||
printerJobStatus *prometheus.Desc
|
||||
@@ -107,12 +109,25 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(_ *slog.Logger, wmiClient *wmi.Client) error {
|
||||
if wmiClient == nil || wmiClient.SWbemServicesClient == nil {
|
||||
return errors.New("wmiClient or SWbemServicesClient is nil")
|
||||
func (c *Collector) Build(_ *slog.Logger, miSession *mi.Session) error {
|
||||
if miSession == nil {
|
||||
return errors.New("miSession is nil")
|
||||
}
|
||||
|
||||
c.wmiClient = wmiClient
|
||||
miQuery, err := mi.NewQuery("SELECT Name, Default, PrinterStatus, JobCountSinceLastReset FROM win32_Printer")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create WMI query: %w", err)
|
||||
}
|
||||
|
||||
c.miQueryPrinter = miQuery
|
||||
|
||||
miQuery, err = mi.NewQuery("SELECT Name, Status FROM win32_PrintJob")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create WMI query: %w", err)
|
||||
}
|
||||
|
||||
c.miQueryPrinterJobs = miQuery
|
||||
c.miSession = miSession
|
||||
|
||||
c.printerJobStatus = prometheus.NewDesc(
|
||||
prometheus.BuildFQName(types.Namespace, Name, "job_status"),
|
||||
@@ -143,42 +158,35 @@ func (c *Collector) GetPerfCounter(_ *slog.Logger) ([]string, error) {
|
||||
}
|
||||
|
||||
type wmiPrinter struct {
|
||||
Name string
|
||||
Default bool
|
||||
PrinterStatus uint16
|
||||
JobCountSinceLastReset uint32
|
||||
Name string `mi:"Name"`
|
||||
Default bool `mi:"Default"`
|
||||
PrinterStatus uint16 `mi:"PrinterStatus"`
|
||||
JobCountSinceLastReset uint32 `mi:"JobCountSinceLastReset"`
|
||||
}
|
||||
|
||||
type wmiPrintJob struct {
|
||||
Name string
|
||||
Status string
|
||||
Name string `mi:"Name"`
|
||||
Status string `mi:"Status"`
|
||||
}
|
||||
|
||||
func (c *Collector) Collect(_ *types.ScrapeContext, logger *slog.Logger, ch chan<- prometheus.Metric) error {
|
||||
logger = logger.With(slog.String("collector", Name))
|
||||
if err := c.collectPrinterStatus(ch); err != nil {
|
||||
logger.Error("failed to collect printer status metrics",
|
||||
slog.Any("err", err),
|
||||
)
|
||||
func (c *Collector) Collect(_ *types.ScrapeContext, _ *slog.Logger, ch chan<- prometheus.Metric) error {
|
||||
var errs []error
|
||||
|
||||
return err
|
||||
if err := c.collectPrinterStatus(ch); err != nil {
|
||||
errs = append(errs, fmt.Errorf("failed to collect printer status metrics: %w", err))
|
||||
}
|
||||
|
||||
if err := c.collectPrinterJobStatus(ch); err != nil {
|
||||
logger.Error("failed to collect printer job status metrics",
|
||||
slog.Any("err", err),
|
||||
)
|
||||
|
||||
return err
|
||||
errs = append(errs, fmt.Errorf("failed to collect printer job status metrics: %w", err))
|
||||
}
|
||||
|
||||
return nil
|
||||
return errors.Join(errs...)
|
||||
}
|
||||
|
||||
func (c *Collector) collectPrinterStatus(ch chan<- prometheus.Metric) error {
|
||||
var printers []wmiPrinter
|
||||
if err := c.wmiClient.Query("SELECT * FROM win32_Printer", &printers); err != nil {
|
||||
return err
|
||||
if err := c.miSession.Query(&printers, mi.NamespaceRootCIMv2, c.miQueryPrinter); err != nil {
|
||||
return fmt.Errorf("WMI query failed: %w", err)
|
||||
}
|
||||
|
||||
for _, printer := range printers {
|
||||
@@ -215,8 +223,8 @@ func (c *Collector) collectPrinterStatus(ch chan<- prometheus.Metric) error {
|
||||
|
||||
func (c *Collector) collectPrinterJobStatus(ch chan<- prometheus.Metric) error {
|
||||
var printJobs []wmiPrintJob
|
||||
if err := c.wmiClient.Query("SELECT * FROM win32_PrintJob", &printJobs); err != nil {
|
||||
return err
|
||||
if err := c.miSession.Query(&printJobs, mi.NamespaceRootCIMv2, c.miQueryPrinterJobs); err != nil {
|
||||
return fmt.Errorf("WMI query failed: %w", err)
|
||||
}
|
||||
|
||||
groupedPrintJobs := c.groupPrintJobs(printJobs)
|
||||
|
||||
@@ -12,13 +12,13 @@ import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/perfdata"
|
||||
v1 "github.com/prometheus-community/windows_exporter/internal/perfdata/v1"
|
||||
v2 "github.com/prometheus-community/windows_exporter/internal/perfdata/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus-community/windows_exporter/internal/utils"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
@@ -38,7 +38,9 @@ var ConfigDefaults = Config{
|
||||
|
||||
type Collector struct {
|
||||
config Config
|
||||
wmiClient *wmi.Client
|
||||
miSession *mi.Session
|
||||
|
||||
workerProcessMIQueryQuery mi.Query
|
||||
|
||||
perfDataCollector perfdata.Collector
|
||||
|
||||
@@ -139,14 +141,20 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(logger *slog.Logger, wmiClient *wmi.Client) error {
|
||||
func (c *Collector) Build(logger *slog.Logger, miSession *mi.Session) error {
|
||||
logger = logger.With(slog.String("collector", Name))
|
||||
|
||||
if wmiClient == nil || wmiClient.SWbemServicesClient == nil {
|
||||
return errors.New("wmiClient or SWbemServicesClient is nil")
|
||||
if miSession == nil {
|
||||
return errors.New("miSession is nil")
|
||||
}
|
||||
|
||||
c.wmiClient = wmiClient
|
||||
miQuery, err := mi.NewQuery("SELECT AppPoolName, ProcessId FROM WorkerProcess")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create WMI query: %w", err)
|
||||
}
|
||||
|
||||
c.workerProcessMIQueryQuery = miQuery
|
||||
c.miSession = miSession
|
||||
|
||||
if utils.PDHEnabled() {
|
||||
counters := []string{
|
||||
@@ -302,8 +310,8 @@ func (c *Collector) Build(logger *slog.Logger, wmiClient *wmi.Client) error {
|
||||
}
|
||||
|
||||
type WorkerProcess struct {
|
||||
AppPoolName string
|
||||
ProcessId uint64
|
||||
AppPoolName string `mi:"AppPoolName"`
|
||||
ProcessId uint64 `mi:"ProcessId"`
|
||||
}
|
||||
|
||||
func (c *Collector) Collect(ctx *types.ScrapeContext, logger *slog.Logger, ch chan<- prometheus.Metric) error {
|
||||
@@ -333,10 +341,8 @@ func (c *Collector) collect(ctx *types.ScrapeContext, logger *slog.Logger, ch ch
|
||||
|
||||
var workerProcesses []WorkerProcess
|
||||
if c.config.EnableWorkerProcess {
|
||||
if err := c.wmiClient.Query("SELECT * FROM WorkerProcess", &workerProcesses, nil, "root\\WebAdministration"); err != nil {
|
||||
logger.Debug("Could not query WebAdministration namespace for IIS worker processes",
|
||||
slog.Any("err", err),
|
||||
)
|
||||
if err := c.miSession.Query(&workerProcesses, mi.NamespaceRootWebAdministration, c.workerProcessMIQueryQuery); err != nil {
|
||||
return fmt.Errorf("WMI query failed: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -540,10 +546,8 @@ func (c *Collector) collectPDH(logger *slog.Logger, ch chan<- prometheus.Metric)
|
||||
|
||||
var workerProcesses []WorkerProcess
|
||||
if c.config.EnableWorkerProcess {
|
||||
if err := c.wmiClient.Query("SELECT * FROM WorkerProcess", &workerProcesses, nil, "root\\WebAdministration"); err != nil {
|
||||
logger.Debug("Could not query WebAdministration namespace for IIS worker processes",
|
||||
slog.Any("err", err),
|
||||
)
|
||||
if err := c.miSession.Query(&workerProcesses, mi.NamespaceRootWebAdministration, c.workerProcessMIQueryQuery); err != nil {
|
||||
return fmt.Errorf("WMI query failed: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,11 +7,11 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
v1 "github.com/prometheus-community/windows_exporter/internal/perfdata/v1"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus-community/windows_exporter/internal/utils"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
)
|
||||
|
||||
const Name = "remote_fx"
|
||||
@@ -81,7 +81,7 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(*slog.Logger, *wmi.Client) error {
|
||||
func (c *Collector) Build(*slog.Logger, *mi.Session) error {
|
||||
// net
|
||||
c.baseTCPRTT = prometheus.NewDesc(
|
||||
prometheus.BuildFQName(types.Namespace, Name, "net_base_tcp_rtt_seconds"),
|
||||
|
||||
@@ -13,9 +13,9 @@ import (
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/go-ole/go-ole"
|
||||
"github.com/go-ole/go-ole/oleutil"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
)
|
||||
|
||||
const Name = "scheduled_task"
|
||||
@@ -148,7 +148,7 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *wmi.Client) error {
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
|
||||
initErrCh := make(chan error)
|
||||
c.scheduledTasksReqCh = make(chan struct{})
|
||||
c.scheduledTasksCh = make(chan *scheduledTaskResults)
|
||||
@@ -281,7 +281,7 @@ func (c *Collector) initializeScheduleService(initErrCh chan<- error) {
|
||||
|
||||
if err := ole.CoInitializeEx(0, ole.COINIT_MULTITHREADED); err != nil {
|
||||
var oleCode *ole.OleError
|
||||
if errors.As(err, &oleCode) && oleCode.Code() != ole.S_OK && oleCode.Code() != wmi.S_FALSE {
|
||||
if errors.As(err, &oleCode) && oleCode.Code() != ole.S_OK && oleCode.Code() != 0x00000001 {
|
||||
initErrCh <- err
|
||||
|
||||
return
|
||||
|
||||
@@ -11,9 +11,9 @@ import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
"golang.org/x/sys/windows"
|
||||
"golang.org/x/sys/windows/svc/mgr"
|
||||
)
|
||||
@@ -106,7 +106,7 @@ func (c *Collector) GetPerfCounter(_ *slog.Logger) ([]string, error) {
|
||||
return []string{}, nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(logger *slog.Logger, _ *wmi.Client) error {
|
||||
func (c *Collector) Build(logger *slog.Logger, _ *mi.Session) error {
|
||||
logger = logger.With(slog.String("collector", Name))
|
||||
|
||||
if c.config.ServiceInclude.String() == "^(?:.*)$" && c.config.ServiceExclude.String() == "^(?:)$" {
|
||||
|
||||
@@ -7,10 +7,10 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
v1 "github.com/prometheus-community/windows_exporter/internal/perfdata/v1"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
)
|
||||
|
||||
const Name = "smb"
|
||||
@@ -56,7 +56,7 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *wmi.Client) error {
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
|
||||
// desc creates a new prometheus description
|
||||
desc := func(metricName string, description string, labels ...string) *prometheus.Desc {
|
||||
return prometheus.NewDesc(
|
||||
|
||||
@@ -7,11 +7,11 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/perfdata/perftypes"
|
||||
v1 "github.com/prometheus-community/windows_exporter/internal/perfdata/v1"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -79,7 +79,7 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *wmi.Client) error {
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
|
||||
// desc creates a new prometheus description
|
||||
desc := func(metricName string, description string, labels []string) *prometheus.Desc {
|
||||
return prometheus.NewDesc(
|
||||
|
||||
@@ -8,10 +8,10 @@ import (
|
||||
"regexp"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
v1 "github.com/prometheus-community/windows_exporter/internal/perfdata/v1"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
)
|
||||
|
||||
const Name = "smtp"
|
||||
@@ -141,10 +141,10 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(logger *slog.Logger, _ *wmi.Client) error {
|
||||
logger = logger.With(slog.String("collector", Name))
|
||||
|
||||
logger.Info("smtp collector is in an experimental state! Metrics for this collector have not been tested.")
|
||||
func (c *Collector) Build(logger *slog.Logger, _ *mi.Session) error {
|
||||
logger.Info("smtp collector is in an experimental state! Metrics for this collector have not been tested.",
|
||||
slog.String("collector", Name),
|
||||
)
|
||||
|
||||
c.badMailedMessagesBadPickupFileTotal = prometheus.NewDesc(
|
||||
prometheus.BuildFQName(types.Namespace, Name, "badmailed_messages_bad_pickup_file_total"),
|
||||
|
||||
@@ -7,10 +7,10 @@ import (
|
||||
"log/slog"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
v1 "github.com/prometheus-community/windows_exporter/internal/perfdata/v1"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
)
|
||||
|
||||
const Name = "system"
|
||||
@@ -61,7 +61,7 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *wmi.Client) error {
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
|
||||
c.contextSwitchesTotal = prometheus.NewDesc(
|
||||
prometheus.BuildFQName(types.Namespace, Name, "context_switches_total"),
|
||||
"Total number of context switches (WMI source: PerfOS_System.ContextSwitchesPersec)",
|
||||
|
||||
@@ -10,11 +10,11 @@ import (
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/headers/iphlpapi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/perfdata"
|
||||
"github.com/prometheus-community/windows_exporter/internal/perfdata/perftypes"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
@@ -100,7 +100,7 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *wmi.Client) error {
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
|
||||
counters := []string{
|
||||
connectionFailures,
|
||||
connectionsActive,
|
||||
|
||||
@@ -11,10 +11,11 @@ import (
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/headers/wtsapi32"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
v1 "github.com/prometheus-community/windows_exporter/internal/perfdata/v1"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus-community/windows_exporter/internal/utils"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
@@ -31,9 +32,9 @@ type Win32_ServerFeature struct {
|
||||
ID uint32
|
||||
}
|
||||
|
||||
func isConnectionBrokerServer(logger *slog.Logger, wmiClient *wmi.Client) bool {
|
||||
func isConnectionBrokerServer(logger *slog.Logger, miSession *mi.Session) bool {
|
||||
var dst []Win32_ServerFeature
|
||||
if err := wmiClient.Query("SELECT * FROM Win32_ServerFeature", &dst); err != nil {
|
||||
if err := miSession.Query(&dst, mi.NamespaceRootCIMv2, utils.Must(mi.NewQuery("SELECT * FROM Win32_ServerFeature"))); err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -112,10 +113,14 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(logger *slog.Logger, wmiClient *wmi.Client) error {
|
||||
func (c *Collector) Build(logger *slog.Logger, miSession *mi.Session) error {
|
||||
if miSession == nil {
|
||||
return errors.New("miSession is nil")
|
||||
}
|
||||
|
||||
logger = logger.With(slog.String("collector", Name))
|
||||
|
||||
c.connectionBrokerEnabled = isConnectionBrokerServer(logger, wmiClient)
|
||||
c.connectionBrokerEnabled = isConnectionBrokerServer(logger, miSession)
|
||||
|
||||
c.sessionInfo = prometheus.NewDesc(
|
||||
prometheus.BuildFQName(types.Namespace, Name, "session_info"),
|
||||
|
||||
@@ -29,11 +29,11 @@ import (
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/dimchansky/utfbom"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
"github.com/prometheus/common/expfmt"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
)
|
||||
|
||||
const Name = "textfile"
|
||||
@@ -104,7 +104,7 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(logger *slog.Logger, _ *wmi.Client) error {
|
||||
func (c *Collector) Build(logger *slog.Logger, _ *mi.Session) error {
|
||||
logger.Info("textfile Collector directories: "+strings.Join(c.config.TextFileDirectories, ","),
|
||||
slog.String("collector", Name),
|
||||
)
|
||||
|
||||
@@ -4,12 +4,13 @@ package thermalzone
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
)
|
||||
|
||||
const Name = "thermalzone"
|
||||
@@ -21,7 +22,8 @@ var ConfigDefaults = Config{}
|
||||
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_Counters_ThermalZoneInformation metrics.
|
||||
type Collector struct {
|
||||
config Config
|
||||
wmiClient *wmi.Client
|
||||
miSession *mi.Session
|
||||
miQuery mi.Query
|
||||
|
||||
percentPassiveLimit *prometheus.Desc
|
||||
temperature *prometheus.Desc
|
||||
@@ -56,12 +58,19 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(_ *slog.Logger, wmiClient *wmi.Client) error {
|
||||
if wmiClient == nil || wmiClient.SWbemServicesClient == nil {
|
||||
return errors.New("wmiClient or SWbemServicesClient is nil")
|
||||
func (c *Collector) Build(_ *slog.Logger, miSession *mi.Session) error {
|
||||
if miSession == nil {
|
||||
return errors.New("miSession is nil")
|
||||
}
|
||||
|
||||
c.wmiClient = wmiClient
|
||||
miQuery, err := mi.NewQuery("SELECT Name, HighPrecisionTemperature, PercentPassiveLimit, ThrottleReasons FROM Win32_PerfRawData_Counters_ThermalZoneInformation")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create WMI query: %w", err)
|
||||
}
|
||||
|
||||
c.miQuery = miQuery
|
||||
c.miSession = miSession
|
||||
|
||||
c.temperature = prometheus.NewDesc(
|
||||
prometheus.BuildFQName(types.Namespace, Name, "temperature_celsius"),
|
||||
"(Temperature)",
|
||||
@@ -108,22 +117,20 @@ func (c *Collector) Collect(_ *types.ScrapeContext, logger *slog.Logger, ch chan
|
||||
// Win32_PerfRawData_Counters_ThermalZoneInformation docs:
|
||||
// https://wutils.com/wmi/root/cimv2/win32_perfrawdata_counters_thermalzoneinformation/
|
||||
type Win32_PerfRawData_Counters_ThermalZoneInformation struct {
|
||||
Name string
|
||||
|
||||
HighPrecisionTemperature uint32
|
||||
PercentPassiveLimit uint32
|
||||
ThrottleReasons uint32
|
||||
Name string `mi:"Name"`
|
||||
HighPrecisionTemperature uint32 `mi:"HighPrecisionTemperature"`
|
||||
PercentPassiveLimit uint32 `mi:"PercentPassiveLimit"`
|
||||
ThrottleReasons uint32 `mi:"ThrottleReasons"`
|
||||
}
|
||||
|
||||
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||
var dst []Win32_PerfRawData_Counters_ThermalZoneInformation
|
||||
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_Counters_ThermalZoneInformation", &dst); err != nil {
|
||||
return err
|
||||
if err := c.miSession.Query(&dst, mi.NamespaceRootCIMv2, c.miQuery); err != nil {
|
||||
return fmt.Errorf("WMI query failed: %w", err)
|
||||
}
|
||||
|
||||
// ThermalZone collector has been known to 'successfully' return an empty result.
|
||||
if len(dst) == 0 {
|
||||
return errors.New("empty results set for collector")
|
||||
return errors.New("WMI query returned empty result set")
|
||||
}
|
||||
|
||||
for _, info := range dst {
|
||||
|
||||
@@ -9,10 +9,10 @@ import (
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/headers/kernel32"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
v1 "github.com/prometheus-community/windows_exporter/internal/perfdata/v1"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
@@ -64,7 +64,7 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *wmi.Client) error {
|
||||
func (c *Collector) Build(_ *slog.Logger, _ *mi.Session) error {
|
||||
c.currentTime = prometheus.NewDesc(
|
||||
prometheus.BuildFQName(types.Namespace, Name, "current_timestamp_seconds"),
|
||||
"OperatingSystem.LocalDateTime",
|
||||
|
||||
@@ -15,9 +15,9 @@ import (
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/go-ole/go-ole"
|
||||
"github.com/go-ole/go-ole/oleutil"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
)
|
||||
|
||||
const Name = "update"
|
||||
@@ -80,7 +80,7 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(logger *slog.Logger, _ *wmi.Client) error {
|
||||
func (c *Collector) Build(logger *slog.Logger, _ *mi.Session) error {
|
||||
logger = logger.With(slog.String("collector", Name))
|
||||
|
||||
logger.Info("update collector is in an experimental state! The configuration and metrics may change in future. Please report any issues.")
|
||||
@@ -147,7 +147,7 @@ func (c *Collector) scheduleUpdateStatus(logger *slog.Logger, initErrCh chan<- e
|
||||
|
||||
if err := ole.CoInitializeEx(0, ole.COINIT_MULTITHREADED); err != nil {
|
||||
var oleCode *ole.OleError
|
||||
if errors.As(err, &oleCode) && oleCode.Code() != ole.S_OK && oleCode.Code() != wmi.S_FALSE {
|
||||
if errors.As(err, &oleCode) && oleCode.Code() != ole.S_OK && oleCode.Code() != 0x00000001 {
|
||||
initErrCh <- fmt.Errorf("CoInitializeEx: %w", err)
|
||||
|
||||
return
|
||||
|
||||
@@ -4,13 +4,14 @@ package vmware
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"github.com/alecthomas/kingpin/v2"
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/perfdata/perftypes"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
)
|
||||
|
||||
const Name = "vmware"
|
||||
@@ -21,8 +22,10 @@ var ConfigDefaults = Config{}
|
||||
|
||||
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_vmGuestLib_VMem/Win32_PerfRawData_vmGuestLib_VCPU metrics.
|
||||
type Collector struct {
|
||||
config Config
|
||||
wmiClient *wmi.Client
|
||||
config Config
|
||||
miSession *mi.Session
|
||||
miQueryCPU mi.Query
|
||||
miQueryMem mi.Query
|
||||
|
||||
memActive *prometheus.Desc
|
||||
memBallooned *prometheus.Desc
|
||||
@@ -74,12 +77,25 @@ func (c *Collector) Close(_ *slog.Logger) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Collector) Build(_ *slog.Logger, wmiClient *wmi.Client) error {
|
||||
if wmiClient == nil || wmiClient.SWbemServicesClient == nil {
|
||||
return errors.New("wmiClient or SWbemServicesClient is nil")
|
||||
func (c *Collector) Build(_ *slog.Logger, miSession *mi.Session) error {
|
||||
if miSession == nil {
|
||||
return errors.New("miSession is nil")
|
||||
}
|
||||
|
||||
c.wmiClient = wmiClient
|
||||
miQuery, err := mi.NewQuery("SELECT * FROM Win32_PerfRawData_vmGuestLib_VCPU")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create WMI query: %w", err)
|
||||
}
|
||||
|
||||
c.miQueryCPU = miQuery
|
||||
|
||||
miQuery, err = mi.NewQuery("SELECT * FROM Win32_PerfRawData_vmGuestLib_VMem")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create WMI query: %w", err)
|
||||
}
|
||||
|
||||
c.miQueryMem = miQuery
|
||||
c.miSession = miSession
|
||||
|
||||
c.memActive = prometheus.NewDesc(
|
||||
prometheus.BuildFQName(types.Namespace, Name, "mem_active_bytes"),
|
||||
@@ -224,34 +240,34 @@ func (c *Collector) Collect(_ *types.ScrapeContext, logger *slog.Logger, ch chan
|
||||
}
|
||||
|
||||
type Win32_PerfRawData_vmGuestLib_VMem struct {
|
||||
MemActiveMB uint64
|
||||
MemBalloonedMB uint64
|
||||
MemLimitMB uint64
|
||||
MemMappedMB uint64
|
||||
MemOverheadMB uint64
|
||||
MemReservationMB uint64
|
||||
MemSharedMB uint64
|
||||
MemSharedSavedMB uint64
|
||||
MemShares uint64
|
||||
MemSwappedMB uint64
|
||||
MemTargetSizeMB uint64
|
||||
MemUsedMB uint64
|
||||
MemActiveMB uint64 `mi:"MemActiveMB"`
|
||||
MemBalloonedMB uint64 `mi:"MemBalloonedMB"`
|
||||
MemLimitMB uint64 `mi:"MemLimitMB"`
|
||||
MemMappedMB uint64 `mi:"MemMappedMB"`
|
||||
MemOverheadMB uint64 `mi:"MemOverheadMB"`
|
||||
MemReservationMB uint64 `mi:"MemReservationMB"`
|
||||
MemSharedMB uint64 `mi:"MemSharedMB"`
|
||||
MemSharedSavedMB uint64 `mi:"MemSharedSavedMB"`
|
||||
MemShares uint64 `mi:"MemShares"`
|
||||
MemSwappedMB uint64 `mi:"MemSwappedMB"`
|
||||
MemTargetSizeMB uint64 `mi:"MemTargetSizeMB"`
|
||||
MemUsedMB uint64 `mi:"MemUsedMB"`
|
||||
}
|
||||
|
||||
type Win32_PerfRawData_vmGuestLib_VCPU struct {
|
||||
CpuLimitMHz uint64
|
||||
CpuReservationMHz uint64
|
||||
CpuShares uint64
|
||||
CpuStolenMs uint64
|
||||
CpuTimePercents uint64
|
||||
EffectiveVMSpeedMHz uint64
|
||||
HostProcessorSpeedMHz uint64
|
||||
CpuLimitMHz uint64 `mi:"CpuLimitMHz"`
|
||||
CpuReservationMHz uint64 `mi:"CpuReservationMHz"`
|
||||
CpuShares uint64 `mi:"CpuShares"`
|
||||
CpuStolenMs uint64 `mi:"CpuStolenMs"`
|
||||
CpuTimePercents uint64 `mi:"CpuTimePercents"`
|
||||
EffectiveVMSpeedMHz uint64 `mi:"EffectiveVMSpeedMHz"`
|
||||
HostProcessorSpeedMHz uint64 `mi:"HostProcessorSpeedMHz"`
|
||||
}
|
||||
|
||||
func (c *Collector) collectMem(ch chan<- prometheus.Metric) error {
|
||||
var dst []Win32_PerfRawData_vmGuestLib_VMem
|
||||
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_vmGuestLib_VMem", &dst); err != nil {
|
||||
return err
|
||||
if err := c.miSession.Query(&dst, mi.NamespaceRootCIMv2, c.miQueryMem); err != nil {
|
||||
return fmt.Errorf("WMI query failed: %w", err)
|
||||
}
|
||||
|
||||
if len(dst) == 0 {
|
||||
@@ -333,14 +349,15 @@ func (c *Collector) collectMem(ch chan<- prometheus.Metric) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// mbToBytes moved to utils package
|
||||
func mbToBytes(mb uint64) float64 {
|
||||
return float64(mb * 1024 * 1024)
|
||||
}
|
||||
|
||||
func (c *Collector) collectCpu(ch chan<- prometheus.Metric) error {
|
||||
var dst []Win32_PerfRawData_vmGuestLib_VCPU
|
||||
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_vmGuestLib_VCPU", &dst); err != nil {
|
||||
return err
|
||||
if err := c.miSession.Query(&dst, mi.NamespaceRootCIMv2, c.miQueryCPU); err != nil {
|
||||
return fmt.Errorf("WMI query failed: %w", err)
|
||||
}
|
||||
|
||||
if len(dst) == 0 {
|
||||
|
||||
Reference in New Issue
Block a user