mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-03-02 16:46:35 +00:00
*: avoid using default wmi client. (#1590)
This commit is contained in:
4
.github/workflows/lint.yml
vendored
4
.github/workflows/lint.yml
vendored
@@ -100,5 +100,5 @@ jobs:
|
|||||||
- name: golangci-lint
|
- name: golangci-lint
|
||||||
uses: golangci/golangci-lint-action@v6
|
uses: golangci/golangci-lint-action@v6
|
||||||
with:
|
with:
|
||||||
version: v1.59
|
version: v1.60
|
||||||
args: "--timeout=5m"
|
args: "--timeout=5m --max-same-issues=0"
|
||||||
@@ -10,6 +10,7 @@ linters:
|
|||||||
- err113
|
- err113
|
||||||
- exhaustive
|
- exhaustive
|
||||||
- exhaustruct
|
- exhaustruct
|
||||||
|
- exportloopref
|
||||||
- fatcontext
|
- fatcontext
|
||||||
- funlen
|
- funlen
|
||||||
- gochecknoglobals
|
- gochecknoglobals
|
||||||
@@ -33,6 +34,10 @@ linters:
|
|||||||
- maintidx
|
- maintidx
|
||||||
|
|
||||||
linters-settings:
|
linters-settings:
|
||||||
|
gosec:
|
||||||
|
excludes:
|
||||||
|
- G115 # integer overflow conversion
|
||||||
|
|
||||||
gci:
|
gci:
|
||||||
sections:
|
sections:
|
||||||
- prefix(github.com/prometheus-community/windows_exporter/pkg/initiate)
|
- prefix(github.com/prometheus-community/windows_exporter/pkg/initiate)
|
||||||
|
|||||||
10
exporter.go
10
exporter.go
@@ -32,7 +32,6 @@ import (
|
|||||||
"github.com/prometheus-community/windows_exporter/pkg/log/flag"
|
"github.com/prometheus-community/windows_exporter/pkg/log/flag"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/utils"
|
"github.com/prometheus-community/windows_exporter/pkg/utils"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
"github.com/prometheus/common/version"
|
"github.com/prometheus/common/version"
|
||||||
"github.com/prometheus/exporter-toolkit/web"
|
"github.com/prometheus/exporter-toolkit/web"
|
||||||
webflag "github.com/prometheus/exporter-toolkit/web/kingpinflag"
|
webflag "github.com/prometheus/exporter-toolkit/web/kingpinflag"
|
||||||
@@ -88,7 +87,7 @@ func main() {
|
|||||||
"config.file",
|
"config.file",
|
||||||
"YAML configuration file to use. Values set in this file will be overridden by CLI flags.",
|
"YAML configuration file to use. Values set in this file will be overridden by CLI flags.",
|
||||||
).String()
|
).String()
|
||||||
insecure_skip_verify = app.Flag(
|
insecureSkipVerify = app.Flag(
|
||||||
"config.file.insecure-skip-verify",
|
"config.file.insecure-skip-verify",
|
||||||
"Skip TLS verification in loading YAML configuration.",
|
"Skip TLS verification in loading YAML configuration.",
|
||||||
).Default("false").Bool()
|
).Default("false").Bool()
|
||||||
@@ -148,7 +147,7 @@ func main() {
|
|||||||
_ = level.Debug(logger).Log("msg", "Logging has Started")
|
_ = level.Debug(logger).Log("msg", "Logging has Started")
|
||||||
|
|
||||||
if *configFile != "" {
|
if *configFile != "" {
|
||||||
resolver, err := config.NewResolver(*configFile, logger, *insecure_skip_verify)
|
resolver, err := config.NewResolver(*configFile, logger, *insecureSkipVerify)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "could not load config file", "err", err)
|
_ = level.Error(logger).Log("msg", "could not load config file", "err", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@@ -196,11 +195,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = wmi.InitWbem(logger); err != nil {
|
|
||||||
_ = level.Error(logger).Log("err", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
enabledCollectorList := utils.ExpandEnabledCollectors(*enabledCollectors)
|
enabledCollectorList := utils.ExpandEnabledCollectors(*enabledCollectors)
|
||||||
collectors.Enable(enabledCollectorList)
|
collectors.Enable(enabledCollectorList)
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import (
|
|||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "ad"
|
const Name = "ad"
|
||||||
@@ -21,7 +21,8 @@ var ConfigDefaults = Config{}
|
|||||||
|
|
||||||
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_DirectoryServices_DirectoryServices metrics.
|
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_DirectoryServices_DirectoryServices metrics.
|
||||||
type Collector struct {
|
type Collector struct {
|
||||||
config Config
|
config Config
|
||||||
|
wmiClient *wmi.Client
|
||||||
|
|
||||||
addressBookClientSessions *prometheus.Desc
|
addressBookClientSessions *prometheus.Desc
|
||||||
addressBookOperationsTotal *prometheus.Desc
|
addressBookOperationsTotal *prometheus.Desc
|
||||||
@@ -115,7 +116,13 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, wmiClient *wmi.Client) error {
|
||||||
|
if wmiClient == nil || wmiClient.SWbemServicesClient == nil {
|
||||||
|
return errors.New("wmiClient or SWbemServicesClient is nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
c.wmiClient = wmiClient
|
||||||
|
|
||||||
c.addressBookOperationsTotal = prometheus.NewDesc(
|
c.addressBookOperationsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "address_book_operations_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "address_book_operations_total"),
|
||||||
"",
|
"",
|
||||||
@@ -497,7 +504,7 @@ func (c *Collector) Build(_ log.Logger) error {
|
|||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
||||||
logger = log.With(logger, "collector", Name)
|
logger = log.With(logger, "collector", Name)
|
||||||
if err := c.collect(logger, ch); err != nil {
|
if err := c.collect(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting ad metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting ad metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -656,10 +663,9 @@ type Win32_PerfRawData_DirectoryServices_DirectoryServices struct {
|
|||||||
TransitivesuboperationsPersec uint32
|
TransitivesuboperationsPersec uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collect(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_DirectoryServices_DirectoryServices
|
var dst []Win32_PerfRawData_DirectoryServices_DirectoryServices
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_DirectoryServices_DirectoryServices", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(dst) == 0 {
|
if len(dst) == 0 {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/utils"
|
"github.com/prometheus-community/windows_exporter/pkg/utils"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "adcs"
|
const Name = "adcs"
|
||||||
@@ -67,7 +68,7 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, _ *wmi.Client) error {
|
||||||
c.requestsPerSecond = prometheus.NewDesc(
|
c.requestsPerSecond = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "requests_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "requests_total"),
|
||||||
"Total certificate requests processed",
|
"Total certificate requests processed",
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "adfs"
|
const Name = "adfs"
|
||||||
@@ -94,7 +95,7 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, _ *wmi.Client) error {
|
||||||
c.adLoginConnectionFailures = prometheus.NewDesc(
|
c.adLoginConnectionFailures = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "ad_login_connection_failures_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "ad_login_connection_failures_total"),
|
||||||
"Total number of connection failures to an Active Directory domain controller",
|
"Total number of connection failures to an Active Directory domain controller",
|
||||||
|
|||||||
3
pkg/collector/cache/cache.go
vendored
3
pkg/collector/cache/cache.go
vendored
@@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "cache"
|
const Name = "cache"
|
||||||
@@ -81,7 +82,7 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, _ *wmi.Client) error {
|
||||||
c.asyncCopyReadsTotal = prometheus.NewDesc(
|
c.asyncCopyReadsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "async_copy_reads_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "async_copy_reads_total"),
|
||||||
"(AsyncCopyReadsTotal)",
|
"(AsyncCopyReadsTotal)",
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ package collector
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -63,10 +64,11 @@ import (
|
|||||||
"github.com/prometheus-community/windows_exporter/pkg/collector/vmware_blast"
|
"github.com/prometheus-community/windows_exporter/pkg/collector/vmware_blast"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewWithFlags To be called by the exporter for collector initialization before running kingpin.Parse.
|
// NewWithFlags To be called by the exporter for collector initialization before running kingpin.Parse.
|
||||||
func NewWithFlags(app *kingpin.Application) Collectors {
|
func NewWithFlags(app *kingpin.Application) *Collectors {
|
||||||
collectors := map[string]Collector{}
|
collectors := map[string]Collector{}
|
||||||
|
|
||||||
for name, builder := range BuildersWithFlags {
|
for name, builder := range BuildersWithFlags {
|
||||||
@@ -76,16 +78,10 @@ func NewWithFlags(app *kingpin.Application) Collectors {
|
|||||||
return New(collectors)
|
return New(collectors)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBuilderWithFlags[C Collector](fn BuilderWithFlags[C]) BuilderWithFlags[Collector] {
|
|
||||||
return func(app *kingpin.Application) Collector {
|
|
||||||
return fn(app)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewWithConfig To be called by the external libraries for collector initialization without running kingpin.Parse
|
// NewWithConfig To be called by the external libraries for collector initialization without running kingpin.Parse
|
||||||
//
|
//
|
||||||
//goland:noinspection GoUnusedExportedFunction
|
//goland:noinspection GoUnusedExportedFunction
|
||||||
func NewWithConfig(config Config) Collectors {
|
func NewWithConfig(config Config) *Collectors {
|
||||||
collectors := map[string]Collector{}
|
collectors := map[string]Collector{}
|
||||||
collectors[ad.Name] = ad.New(&config.AD)
|
collectors[ad.Name] = ad.New(&config.AD)
|
||||||
collectors[adcs.Name] = adcs.New(&config.ADCS)
|
collectors[adcs.Name] = adcs.New(&config.ADCS)
|
||||||
@@ -144,9 +140,12 @@ func NewWithConfig(config Config) Collectors {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New To be called by the external libraries for collector initialization.
|
// New To be called by the external libraries for collector initialization.
|
||||||
func New(collectors Map) Collectors {
|
func New(collectors Map) *Collectors {
|
||||||
return Collectors{
|
return &Collectors{
|
||||||
collectors: collectors,
|
collectors: collectors,
|
||||||
|
wmiClient: &wmi.Client{
|
||||||
|
AllowMissingFields: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,9 +191,14 @@ func (c *Collectors) Enable(enabledCollectors []string) {
|
|||||||
func (c *Collectors) Build(logger log.Logger) error {
|
func (c *Collectors) Build(logger log.Logger) error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
c.wmiClient.SWbemServicesClient, err = wmi.InitializeSWbemServices(c.wmiClient)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("initialize SWbemServices: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
for _, collector := range c.collectors {
|
for _, collector := range c.collectors {
|
||||||
if err = collector.Build(logger); err != nil {
|
if err = collector.Build(logger, c.wmiClient); err != nil {
|
||||||
return err
|
return fmt.Errorf("error build collector %s: %w", collector.GetName(), err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,5 +225,11 @@ func (c *Collectors) Close() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.wmiClient != nil && c.wmiClient.SWbemServicesClient != nil {
|
||||||
|
if err := c.wmiClient.SWbemServicesClient.Close(); err != nil {
|
||||||
|
errs = append(errs, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return errors.Join(errs...)
|
return errors.Join(errs...)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "container"
|
const Name = "container"
|
||||||
@@ -84,7 +85,7 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, _ *wmi.Client) error {
|
||||||
c.containerAvailable = prometheus.NewDesc(
|
c.containerAvailable = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "available"),
|
prometheus.BuildFQName(types.Namespace, Name, "available"),
|
||||||
"Available",
|
"Available",
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/winversion"
|
"github.com/prometheus-community/windows_exporter/pkg/winversion"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "cpu"
|
const Name = "cpu"
|
||||||
@@ -58,7 +59,7 @@ func (c *Collector) GetName() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) GetPerfCounter(_ log.Logger) ([]string, error) {
|
func (c *Collector) GetPerfCounter(_ log.Logger) ([]string, error) {
|
||||||
if winversion.WindowsVersionFloat > 6.05 {
|
if winversion.WindowsVersionFloat() > 6.05 {
|
||||||
return []string{"Processor Information"}, nil
|
return []string{"Processor Information"}, nil
|
||||||
}
|
}
|
||||||
return []string{"Processor"}, nil
|
return []string{"Processor"}, nil
|
||||||
@@ -68,7 +69,7 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, _ *wmi.Client) error {
|
||||||
c.cStateSecondsTotal = prometheus.NewDesc(
|
c.cStateSecondsTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "cstate_seconds_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "cstate_seconds_total"),
|
||||||
"Time spent in low-power idle state",
|
"Time spent in low-power idle state",
|
||||||
@@ -100,7 +101,7 @@ func (c *Collector) Build(_ log.Logger) error {
|
|||||||
// are added in later versions, so we aren't guaranteed to get all of
|
// are added in later versions, so we aren't guaranteed to get all of
|
||||||
// them).
|
// them).
|
||||||
// Value 6.05 was selected to split between Windows versions.
|
// Value 6.05 was selected to split between Windows versions.
|
||||||
if winversion.WindowsVersionFloat < 6.05 {
|
if winversion.WindowsVersionFloat() < 6.05 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,7 +189,7 @@ func (c *Collector) Build(_ log.Logger) error {
|
|||||||
|
|
||||||
func (c *Collector) Collect(ctx *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(ctx *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
||||||
logger = log.With(logger, "collector", Name)
|
logger = log.With(logger, "collector", Name)
|
||||||
if winversion.WindowsVersionFloat > 6.05 {
|
if winversion.WindowsVersionFloat() > 6.05 {
|
||||||
return c.CollectFull(ctx, logger, ch)
|
return c.CollectFull(ctx, logger, ch)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ import (
|
|||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -29,7 +29,8 @@ var ConfigDefaults = Config{}
|
|||||||
type Collector struct {
|
type Collector struct {
|
||||||
config Config
|
config Config
|
||||||
|
|
||||||
cpuInfo *prometheus.Desc
|
wmiClient *wmi.Client
|
||||||
|
cpuInfo *prometheus.Desc
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(config *Config) *Collector {
|
func New(config *Config) *Collector {
|
||||||
@@ -60,7 +61,12 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, wmiClient *wmi.Client) error {
|
||||||
|
if wmiClient == nil || wmiClient.SWbemServicesClient == nil {
|
||||||
|
return errors.New("wmiClient or SWbemServicesClient is nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
c.wmiClient = wmiClient
|
||||||
c.cpuInfo = prometheus.NewDesc(
|
c.cpuInfo = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, "", Name),
|
prometheus.BuildFQName(types.Namespace, "", Name),
|
||||||
"Labelled CPU information as provided by Win32_Processor",
|
"Labelled CPU information as provided by Win32_Processor",
|
||||||
@@ -105,7 +111,7 @@ func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
|||||||
// We use a static query here because the provided methods in wmi.go all issue a SELECT *;
|
// 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
|
// 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
|
// serially over a 1 second interval, so the scrape time is at least 1s * num_sockets
|
||||||
if err := wmi.Query(win32ProcessorQuery, &dst); err != nil {
|
if err := c.wmiClient.Query(win32ProcessorQuery, &dst); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(dst) == 0 {
|
if len(dst) == 0 {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/prometheus-community/windows_exporter/pkg/headers/sysinfoapi"
|
"github.com/prometheus-community/windows_exporter/pkg/headers/sysinfoapi"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "cs"
|
const Name = "cs"
|
||||||
@@ -54,7 +55,7 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, _ *wmi.Client) error {
|
||||||
c.logicalProcessors = prometheus.NewDesc(
|
c.logicalProcessors = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "logical_processors"),
|
prometheus.BuildFQName(types.Namespace, Name, "logical_processors"),
|
||||||
"ComputerSystem.NumberOfLogicalProcessors",
|
"ComputerSystem.NumberOfLogicalProcessors",
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "dfsr"
|
const Name = "dfsr"
|
||||||
@@ -152,7 +153,7 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(logger log.Logger) error {
|
func (c *Collector) Build(logger log.Logger, _ *wmi.Client) error {
|
||||||
logger = log.With(logger, "collector", Name)
|
logger = log.With(logger, "collector", Name)
|
||||||
|
|
||||||
_ = level.Info(logger).Log("msg", "dfsr collector is in an experimental state! Metrics for this collector have not been tested.")
|
_ = level.Info(logger).Log("msg", "dfsr collector is in an experimental state! Metrics for this collector have not been tested.")
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "dhcp"
|
const Name = "dhcp"
|
||||||
@@ -75,7 +76,7 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, _ *wmi.Client) error {
|
||||||
c.packetsReceivedTotal = prometheus.NewDesc(
|
c.packetsReceivedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "packets_received_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "packets_received_total"),
|
||||||
"Total number of packets received by the DHCP server (PacketsReceivedTotal)",
|
"Total number of packets received by the DHCP server (PacketsReceivedTotal)",
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ import (
|
|||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -25,7 +25,8 @@ var ConfigDefaults = Config{}
|
|||||||
|
|
||||||
// A Collector is a Prometheus Collector for a few WMI metrics in Win32_DiskDrive.
|
// A Collector is a Prometheus Collector for a few WMI metrics in Win32_DiskDrive.
|
||||||
type Collector struct {
|
type Collector struct {
|
||||||
config Config
|
config Config
|
||||||
|
wmiClient *wmi.Client
|
||||||
|
|
||||||
availability *prometheus.Desc
|
availability *prometheus.Desc
|
||||||
diskInfo *prometheus.Desc
|
diskInfo *prometheus.Desc
|
||||||
@@ -62,7 +63,12 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, wmiClient *wmi.Client) error {
|
||||||
|
if wmiClient == nil || wmiClient.SWbemServicesClient == nil {
|
||||||
|
return errors.New("wmiClient or SWbemServicesClient is nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
c.wmiClient = wmiClient
|
||||||
c.diskInfo = prometheus.NewDesc(
|
c.diskInfo = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "info"),
|
prometheus.BuildFQName(types.Namespace, Name, "info"),
|
||||||
"General drive information",
|
"General drive information",
|
||||||
@@ -167,7 +173,7 @@ func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<-
|
|||||||
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||||
var dst []win32_DiskDrive
|
var dst []win32_DiskDrive
|
||||||
|
|
||||||
if err := wmi.Query(win32DiskQuery, &dst); err != nil {
|
if err := c.wmiClient.Query(win32DiskQuery, &dst); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(dst) == 0 {
|
if len(dst) == 0 {
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import (
|
|||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "dns"
|
const Name = "dns"
|
||||||
@@ -21,7 +21,8 @@ var ConfigDefaults = Config{}
|
|||||||
|
|
||||||
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_DNS_DNS metrics.
|
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_DNS_DNS metrics.
|
||||||
type Collector struct {
|
type Collector struct {
|
||||||
config Config
|
config Config
|
||||||
|
wmiClient *wmi.Client
|
||||||
|
|
||||||
dynamicUpdatesFailures *prometheus.Desc
|
dynamicUpdatesFailures *prometheus.Desc
|
||||||
dynamicUpdatesQueued *prometheus.Desc
|
dynamicUpdatesQueued *prometheus.Desc
|
||||||
@@ -75,7 +76,13 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, wmiClient *wmi.Client) error {
|
||||||
|
if wmiClient == nil || wmiClient.SWbemServicesClient == nil {
|
||||||
|
return errors.New("wmiClient or SWbemServicesClient is nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
c.wmiClient = wmiClient
|
||||||
|
|
||||||
c.zoneTransferRequestsReceived = prometheus.NewDesc(
|
c.zoneTransferRequestsReceived = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "zone_transfer_requests_received_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "zone_transfer_requests_received_total"),
|
||||||
"Number of zone transfer requests (AXFR/IXFR) received by the master DNS server",
|
"Number of zone transfer requests (AXFR/IXFR) received by the master DNS server",
|
||||||
@@ -215,7 +222,7 @@ func (c *Collector) Build(_ log.Logger) error {
|
|||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
||||||
logger = log.With(logger, "collector", Name)
|
logger = log.With(logger, "collector", Name)
|
||||||
if err := c.collect(logger, ch); err != nil {
|
if err := c.collect(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting dns metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting dns metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -268,10 +275,9 @@ type Win32_PerfRawData_DNS_DNS struct {
|
|||||||
ZoneTransferSOARequestSent uint32
|
ZoneTransferSOARequestSent uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collect(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_DNS_DNS
|
var dst []Win32_PerfRawData_DNS_DNS
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_DNS_DNS", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(dst) == 0 {
|
if len(dst) == 0 {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "exchange"
|
const Name = "exchange"
|
||||||
@@ -176,7 +177,7 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, _ *wmi.Client) error {
|
||||||
// desc creates a new prometheus description
|
// desc creates a new prometheus description
|
||||||
desc := func(metricName string, description string, labels ...string) *prometheus.Desc {
|
desc := func(metricName string, description string, labels ...string) *prometheus.Desc {
|
||||||
return prometheus.NewDesc(
|
return prometheus.NewDesc(
|
||||||
|
|||||||
@@ -3,13 +3,15 @@
|
|||||||
package fsrmquota
|
package fsrmquota
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
"github.com/alecthomas/kingpin/v2"
|
"github.com/alecthomas/kingpin/v2"
|
||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/utils"
|
"github.com/prometheus-community/windows_exporter/pkg/utils"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "fsrmquota"
|
const Name = "fsrmquota"
|
||||||
@@ -19,7 +21,8 @@ type Config struct{}
|
|||||||
var ConfigDefaults = Config{}
|
var ConfigDefaults = Config{}
|
||||||
|
|
||||||
type Collector struct {
|
type Collector struct {
|
||||||
config Config
|
config Config
|
||||||
|
wmiClient *wmi.Client
|
||||||
|
|
||||||
quotasCount *prometheus.Desc
|
quotasCount *prometheus.Desc
|
||||||
peakUsage *prometheus.Desc
|
peakUsage *prometheus.Desc
|
||||||
@@ -61,7 +64,13 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, wmiClient *wmi.Client) error {
|
||||||
|
if wmiClient == nil || wmiClient.SWbemServicesClient == nil {
|
||||||
|
return errors.New("wmiClient or SWbemServicesClient is nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
c.wmiClient = wmiClient
|
||||||
|
|
||||||
c.quotasCount = prometheus.NewDesc(
|
c.quotasCount = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "count"),
|
prometheus.BuildFQName(types.Namespace, Name, "count"),
|
||||||
"Number of Quotas",
|
"Number of Quotas",
|
||||||
@@ -123,7 +132,7 @@ func (c *Collector) Build(_ log.Logger) error {
|
|||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
||||||
logger = log.With(logger, "collector", Name)
|
logger = log.With(logger, "collector", Name)
|
||||||
if err := c.collect(logger, ch); err != nil {
|
if err := c.collect(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting fsrmquota metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting fsrmquota metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -147,13 +156,11 @@ type MSFT_FSRMQuota struct {
|
|||||||
SoftLimit bool
|
SoftLimit bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collect(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||||
var dst []MSFT_FSRMQuota
|
var dst []MSFT_FSRMQuota
|
||||||
q := wmi.QueryAll(&dst, logger)
|
|
||||||
|
|
||||||
var count int
|
var count int
|
||||||
|
|
||||||
if err := wmi.QueryNamespace(q, &dst, "root/microsoft/windows/fsrm"); err != nil {
|
if err := c.wmiClient.Query("SELECT * FROM MSFT_FSRMQuota", &dst, nil, "root/microsoft/windows/fsrm"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ func (c *Collectors) BuildServeHTTP(logger log.Logger, disableExporterMetrics bo
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
_ = level.Warn(logger).Log("msg", "Couldn't create filtered metrics handler", "err", err)
|
_ = level.Warn(logger).Log("msg", "Couldn't create filtered metrics handler", "err", err)
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
w.Write([]byte(fmt.Sprintf("Couldn't create filtered metrics handler: %s", err))) //nolint:errcheck
|
_, _ = w.Write([]byte(fmt.Sprintf("Couldn't create filtered metrics handler: %s", err)))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
package hyperv
|
package hyperv
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -10,8 +11,8 @@ import (
|
|||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "hyperv"
|
const Name = "hyperv"
|
||||||
@@ -22,7 +23,8 @@ var ConfigDefaults = Config{}
|
|||||||
|
|
||||||
// Collector is a Prometheus Collector for hyper-v.
|
// Collector is a Prometheus Collector for hyper-v.
|
||||||
type Collector struct {
|
type Collector struct {
|
||||||
config Config
|
config Config
|
||||||
|
wmiClient *wmi.Client
|
||||||
|
|
||||||
// Win32_PerfRawData_VmmsVirtualMachineStats_HyperVVirtualMachineHealthSummary
|
// Win32_PerfRawData_VmmsVirtualMachineStats_HyperVVirtualMachineHealthSummary
|
||||||
healthCritical *prometheus.Desc
|
healthCritical *prometheus.Desc
|
||||||
@@ -167,7 +169,13 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, wmiClient *wmi.Client) error {
|
||||||
|
if wmiClient == nil || wmiClient.SWbemServicesClient == nil {
|
||||||
|
return errors.New("wmiClient or SWbemServicesClient is nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
c.wmiClient = wmiClient
|
||||||
|
|
||||||
buildSubsystemName := func(component string) string { return "hyperv_" + component }
|
buildSubsystemName := func(component string) string { return "hyperv_" + component }
|
||||||
|
|
||||||
c.healthCritical = prometheus.NewDesc(
|
c.healthCritical = prometheus.NewDesc(
|
||||||
@@ -749,22 +757,22 @@ func (c *Collector) Build(_ log.Logger) error {
|
|||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
||||||
logger = log.With(logger, "collector", Name)
|
logger = log.With(logger, "collector", Name)
|
||||||
if err := c.collectVmHealth(logger, ch); err != nil {
|
if err := c.collectVmHealth(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting hyperV health status metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting hyperV health status metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.collectVmVid(logger, ch); err != nil {
|
if err := c.collectVmVid(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting hyperV pages metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting hyperV pages metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.collectVmHv(logger, ch); err != nil {
|
if err := c.collectVmHv(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting hyperV hv status metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting hyperV hv status metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.collectVmProcessor(logger, ch); err != nil {
|
if err := c.collectVmProcessor(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting hyperV processor metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting hyperV processor metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -784,27 +792,27 @@ func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<-
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.collectVmSwitch(logger, ch); err != nil {
|
if err := c.collectVmSwitch(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting hyperV switch metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting hyperV switch metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.collectVmEthernet(logger, ch); err != nil {
|
if err := c.collectVmEthernet(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting hyperV ethernet metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting hyperV ethernet metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.collectVmStorage(logger, ch); err != nil {
|
if err := c.collectVmStorage(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting hyperV virtual storage metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting hyperV virtual storage metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.collectVmNetwork(logger, ch); err != nil {
|
if err := c.collectVmNetwork(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting hyperV virtual network metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting hyperV virtual network metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.collectVmMemory(logger, ch); err != nil {
|
if err := c.collectVmMemory(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting hyperV virtual memory metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting hyperV virtual memory metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -818,10 +826,9 @@ type Win32_PerfRawData_VmmsVirtualMachineStats_HyperVVirtualMachineHealthSummary
|
|||||||
HealthOk uint32
|
HealthOk uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collectVmHealth(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectVmHealth(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_VmmsVirtualMachineStats_HyperVVirtualMachineHealthSummary
|
var dst []Win32_PerfRawData_VmmsVirtualMachineStats_HyperVVirtualMachineHealthSummary
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_VmmsVirtualMachineStats_HyperVVirtualMachineHealthSummary", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -850,10 +857,9 @@ type Win32_PerfRawData_VidPerfProvider_HyperVVMVidPartition struct {
|
|||||||
RemotePhysicalPages uint64
|
RemotePhysicalPages uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collectVmVid(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectVmVid(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_VidPerfProvider_HyperVVMVidPartition
|
var dst []Win32_PerfRawData_VidPerfProvider_HyperVVMVidPartition
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_VidPerfProvider_HyperVVMVidPartition", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -913,10 +919,9 @@ type Win32_PerfRawData_HvStats_HyperVHypervisorRootPartition struct {
|
|||||||
VirtualTLBPages uint64
|
VirtualTLBPages uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collectVmHv(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectVmHv(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_HvStats_HyperVHypervisorRootPartition
|
var dst []Win32_PerfRawData_HvStats_HyperVHypervisorRootPartition
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_HvStats_HyperVHypervisorRootPartition", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1050,10 +1055,9 @@ type Win32_PerfRawData_HvStats_HyperVHypervisor struct {
|
|||||||
VirtualProcessors uint64
|
VirtualProcessors uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collectVmProcessor(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectVmProcessor(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_HvStats_HyperVHypervisor
|
var dst []Win32_PerfRawData_HvStats_HyperVHypervisor
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_HvStats_HyperVHypervisor", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1084,8 +1088,7 @@ type Win32_PerfRawData_HvStats_HyperVHypervisorLogicalProcessor struct {
|
|||||||
|
|
||||||
func (c *Collector) collectHostLPUsage(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectHostLPUsage(logger log.Logger, ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_HvStats_HyperVHypervisorLogicalProcessor
|
var dst []Win32_PerfRawData_HvStats_HyperVHypervisorLogicalProcessor
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_HvStats_HyperVHypervisorLogicalProcessor", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1138,8 +1141,7 @@ type Win32_PerfRawData_HvStats_HyperVHypervisorRootVirtualProcessor struct {
|
|||||||
|
|
||||||
func (c *Collector) collectHostCpuUsage(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectHostCpuUsage(logger log.Logger, ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_HvStats_HyperVHypervisorRootVirtualProcessor
|
var dst []Win32_PerfRawData_HvStats_HyperVHypervisorRootVirtualProcessor
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_HvStats_HyperVHypervisorRootVirtualProcessor", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1206,8 +1208,7 @@ type Win32_PerfRawData_HvStats_HyperVHypervisorVirtualProcessor struct {
|
|||||||
|
|
||||||
func (c *Collector) collectVmCpuUsage(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectVmCpuUsage(logger log.Logger, ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_HvStats_HyperVHypervisorVirtualProcessor
|
var dst []Win32_PerfRawData_HvStats_HyperVHypervisorVirtualProcessor
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_HvStats_HyperVHypervisorVirtualProcessor", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1297,10 +1298,9 @@ type Win32_PerfRawData_NvspSwitchStats_HyperVVirtualSwitch struct {
|
|||||||
PurgedMacAddressesPersec uint64
|
PurgedMacAddressesPersec uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collectVmSwitch(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectVmSwitch(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_NvspSwitchStats_HyperVVirtualSwitch
|
var dst []Win32_PerfRawData_NvspSwitchStats_HyperVVirtualSwitch
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_NvspSwitchStats_HyperVVirtualSwitch", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1462,10 +1462,9 @@ type Win32_PerfRawData_EthernetPerfProvider_HyperVLegacyNetworkAdapter struct {
|
|||||||
FramesSentPersec uint64
|
FramesSentPersec uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collectVmEthernet(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectVmEthernet(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_EthernetPerfProvider_HyperVLegacyNetworkAdapter
|
var dst []Win32_PerfRawData_EthernetPerfProvider_HyperVLegacyNetworkAdapter
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_EthernetPerfProvider_HyperVLegacyNetworkAdapter", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1531,10 +1530,9 @@ type Win32_PerfRawData_Counters_HyperVVirtualStorageDevice struct {
|
|||||||
WriteOperationsPerSec uint64
|
WriteOperationsPerSec uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collectVmStorage(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectVmStorage(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_Counters_HyperVVirtualStorageDevice
|
var dst []Win32_PerfRawData_Counters_HyperVVirtualStorageDevice
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_Counters_HyperVVirtualStorageDevice", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1600,10 +1598,9 @@ type Win32_PerfRawData_NvspNicStats_HyperVVirtualNetworkAdapter struct {
|
|||||||
PacketsSentPersec uint64
|
PacketsSentPersec uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collectVmNetwork(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectVmNetwork(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_NvspNicStats_HyperVVirtualNetworkAdapter
|
var dst []Win32_PerfRawData_NvspNicStats_HyperVVirtualNetworkAdapter
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_NvspNicStats_HyperVVirtualNetworkAdapter", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1673,10 +1670,9 @@ type Win32_PerfRawData_BalancerStats_HyperVDynamicMemoryVM struct {
|
|||||||
RemovedMemory uint64
|
RemovedMemory uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collectVmMemory(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectVmMemory(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_BalancerStats_HyperVDynamicMemoryVM
|
var dst []Win32_PerfRawData_BalancerStats_HyperVDynamicMemoryVM
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_BalancerStats_HyperVDynamicMemoryVM", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
"golang.org/x/sys/windows/registry"
|
"golang.org/x/sys/windows/registry"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -262,7 +263,7 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(logger log.Logger) error {
|
func (c *Collector) Build(logger log.Logger, _ *wmi.Client) error {
|
||||||
logger = log.With(logger, "collector", Name)
|
logger = log.With(logger, "collector", Name)
|
||||||
|
|
||||||
c.iisVersion = getIISVersion(logger)
|
c.iisVersion = getIISVersion(logger)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/prometheus-community/windows_exporter/pkg/headers/slc"
|
"github.com/prometheus-community/windows_exporter/pkg/headers/slc"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "license"
|
const Name = "license"
|
||||||
@@ -60,7 +61,7 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, _ *wmi.Client) error {
|
||||||
c.licenseStatus = prometheus.NewDesc(
|
c.licenseStatus = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "status"),
|
prometheus.BuildFQName(types.Namespace, Name, "status"),
|
||||||
"Status of windows license",
|
"Status of windows license",
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import (
|
|||||||
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
"golang.org/x/sys/windows"
|
"golang.org/x/sys/windows"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -131,7 +132,7 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, _ *wmi.Client) error {
|
||||||
c.information = prometheus.NewDesc(
|
c.information = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "info"),
|
prometheus.BuildFQName(types.Namespace, Name, "info"),
|
||||||
"A metric with a constant '1' value labeled with logical disk information",
|
"A metric with a constant '1' value labeled with logical disk information",
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import (
|
|||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "logon"
|
const Name = "logon"
|
||||||
@@ -21,7 +21,8 @@ var ConfigDefaults = Config{}
|
|||||||
|
|
||||||
// A Collector is a Prometheus Collector for WMI metrics.
|
// A Collector is a Prometheus Collector for WMI metrics.
|
||||||
type Collector struct {
|
type Collector struct {
|
||||||
config Config
|
config Config
|
||||||
|
wmiClient *wmi.Client
|
||||||
|
|
||||||
logonType *prometheus.Desc
|
logonType *prometheus.Desc
|
||||||
}
|
}
|
||||||
@@ -54,7 +55,12 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, wmiClient *wmi.Client) error {
|
||||||
|
if wmiClient == nil || wmiClient.SWbemServicesClient == nil {
|
||||||
|
return errors.New("wmiClient or SWbemServicesClient is nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
c.wmiClient = wmiClient
|
||||||
c.logonType = prometheus.NewDesc(
|
c.logonType = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "logon_type"),
|
prometheus.BuildFQName(types.Namespace, Name, "logon_type"),
|
||||||
"Number of active logon sessions (LogonSession.LogonType)",
|
"Number of active logon sessions (LogonSession.LogonType)",
|
||||||
@@ -68,7 +74,7 @@ func (c *Collector) Build(_ log.Logger) error {
|
|||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
||||||
logger = log.With(logger, "collector", Name)
|
logger = log.With(logger, "collector", Name)
|
||||||
if err := c.collect(logger, ch); err != nil {
|
if err := c.collect(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting user metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting user metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -81,10 +87,9 @@ type Win32_LogonSession struct {
|
|||||||
LogonType uint32
|
LogonType uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collect(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_LogonSession
|
var dst []Win32_LogonSession
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM Win32_LogonSession", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(dst) == 0 {
|
if len(dst) == 0 {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package collector
|
package collector
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/alecthomas/kingpin/v2"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/collector/ad"
|
"github.com/prometheus-community/windows_exporter/pkg/collector/ad"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/collector/adcs"
|
"github.com/prometheus-community/windows_exporter/pkg/collector/adcs"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/collector/adfs"
|
"github.com/prometheus-community/windows_exporter/pkg/collector/adfs"
|
||||||
@@ -56,6 +57,12 @@ import (
|
|||||||
"golang.org/x/exp/maps"
|
"golang.org/x/exp/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func NewBuilderWithFlags[C Collector](fn BuilderWithFlags[C]) BuilderWithFlags[Collector] {
|
||||||
|
return func(app *kingpin.Application) Collector {
|
||||||
|
return fn(app)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var BuildersWithFlags = map[string]BuilderWithFlags[Collector]{
|
var BuildersWithFlags = map[string]BuilderWithFlags[Collector]{
|
||||||
ad.Name: NewBuilderWithFlags(ad.NewWithFlags),
|
ad.Name: NewBuilderWithFlags(ad.NewWithFlags),
|
||||||
adcs.Name: NewBuilderWithFlags(adcs.NewWithFlags),
|
adcs.Name: NewBuilderWithFlags(adcs.NewWithFlags),
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "memory"
|
const Name = "memory"
|
||||||
@@ -86,7 +87,7 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, _ *wmi.Client) error {
|
||||||
c.availableBytes = prometheus.NewDesc(
|
c.availableBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "available_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "available_bytes"),
|
||||||
"The amount of physical memory immediately available for allocation to a process or for system use. It is equal to the sum of memory assigned to"+
|
"The amount of physical memory immediately available for allocation to a process or for system use. It is equal to the sum of memory assigned to"+
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "mscluster"
|
const Name = "mscluster"
|
||||||
@@ -30,7 +31,8 @@ var ConfigDefaults = Config{
|
|||||||
|
|
||||||
// A Collector is a Prometheus Collector for WMI MSCluster_Cluster metrics.
|
// A Collector is a Prometheus Collector for WMI MSCluster_Cluster metrics.
|
||||||
type Collector struct {
|
type Collector struct {
|
||||||
config Config
|
config Config
|
||||||
|
wmiClient *wmi.Client
|
||||||
|
|
||||||
// cluster
|
// cluster
|
||||||
clusterAddEvictDelay *prometheus.Desc
|
clusterAddEvictDelay *prometheus.Desc
|
||||||
@@ -219,11 +221,17 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, wmiClient *wmi.Client) error {
|
||||||
if len(c.config.CollectorsEnabled) == 0 {
|
if len(c.config.CollectorsEnabled) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if wmiClient == nil || wmiClient.SWbemServicesClient == nil {
|
||||||
|
return errors.New("wmiClient or SWbemServicesClient is nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
c.wmiClient = wmiClient
|
||||||
|
|
||||||
if slices.Contains(c.config.CollectorsEnabled, "cluster") {
|
if slices.Contains(c.config.CollectorsEnabled, "cluster") {
|
||||||
c.buildCluster()
|
c.buildCluster()
|
||||||
}
|
}
|
||||||
@@ -249,8 +257,7 @@ func (c *Collector) Build(_ log.Logger) error {
|
|||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, _ log.Logger, ch chan<- prometheus.Metric) error {
|
||||||
logger = log.With(logger, "collector", Name)
|
|
||||||
if len(c.config.CollectorsEnabled) == 0 {
|
if len(c.config.CollectorsEnabled) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -262,31 +269,31 @@ func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<-
|
|||||||
)
|
)
|
||||||
|
|
||||||
if slices.Contains(c.config.CollectorsEnabled, "cluster") {
|
if slices.Contains(c.config.CollectorsEnabled, "cluster") {
|
||||||
if err = c.collectCluster(logger, ch); err != nil {
|
if err = c.collectCluster(ch); err != nil {
|
||||||
errs = append(errs, fmt.Errorf("failed to collect cluster metrics: %w", err))
|
errs = append(errs, fmt.Errorf("failed to collect cluster metrics: %w", err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if slices.Contains(c.config.CollectorsEnabled, "network") {
|
if slices.Contains(c.config.CollectorsEnabled, "network") {
|
||||||
if err = c.collectNetwork(logger, ch); err != nil {
|
if err = c.collectNetwork(ch); err != nil {
|
||||||
errs = append(errs, fmt.Errorf("failed to collect network metrics: %w", err))
|
errs = append(errs, fmt.Errorf("failed to collect network metrics: %w", err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if slices.Contains(c.config.CollectorsEnabled, "node") {
|
if slices.Contains(c.config.CollectorsEnabled, "node") {
|
||||||
if nodeNames, err = c.collectNode(logger, ch); err != nil {
|
if nodeNames, err = c.collectNode(ch); err != nil {
|
||||||
errs = append(errs, fmt.Errorf("failed to collect node metrics: %w", err))
|
errs = append(errs, fmt.Errorf("failed to collect node metrics: %w", err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if slices.Contains(c.config.CollectorsEnabled, "resource") {
|
if slices.Contains(c.config.CollectorsEnabled, "resource") {
|
||||||
if err = c.collectResource(logger, ch, nodeNames); err != nil {
|
if err = c.collectResource(ch, nodeNames); err != nil {
|
||||||
errs = append(errs, fmt.Errorf("failed to collect resource metrics: %w", err))
|
errs = append(errs, fmt.Errorf("failed to collect resource metrics: %w", err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if slices.Contains(c.config.CollectorsEnabled, "resourcegroup") {
|
if slices.Contains(c.config.CollectorsEnabled, "resourcegroup") {
|
||||||
if err = c.collectResourceGroup(logger, ch, nodeNames); err != nil {
|
if err = c.collectResourceGroup(ch, nodeNames); err != nil {
|
||||||
errs = append(errs, fmt.Errorf("failed to collect resource group metrics: %w", err))
|
errs = append(errs, fmt.Errorf("failed to collect resource group metrics: %w", err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
package mscluster
|
package mscluster
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/go-kit/log"
|
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -558,10 +556,9 @@ func (c *Collector) buildCluster() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collectCluster(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectCluster(ch chan<- prometheus.Metric) error {
|
||||||
var dst []msClusterCluster
|
var dst []msClusterCluster
|
||||||
q := wmi.QueryAllForClass(&dst, "MSCluster_Cluster", logger)
|
if err := c.wmiClient.Query("SELECT * FROM MSCluster_Cluster", &dst, nil, "root/MSCluster"); err != nil {
|
||||||
if err := wmi.QueryNamespace(q, &dst, "root/MSCluster"); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
package mscluster
|
package mscluster
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/go-kit/log"
|
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -56,11 +54,10 @@ func (c *Collector) buildNetwork() {
|
|||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus metric channel.
|
// to the provided prometheus metric channel.
|
||||||
func (c *Collector) collectNetwork(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectNetwork(ch chan<- prometheus.Metric) error {
|
||||||
var dst []msClusterNetwork
|
var dst []msClusterNetwork
|
||||||
|
|
||||||
q := wmi.QueryAllForClass(&dst, "MSCluster_Network", logger)
|
if err := c.wmiClient.Query("SELECT * FROM MSCluster_Network", &dst, nil, "root/MSCluster"); err != nil {
|
||||||
if err := wmi.QueryNamespace(q, &dst, "root/MSCluster"); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
package mscluster
|
package mscluster
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/go-kit/log"
|
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -119,11 +117,10 @@ func (c *Collector) buildNode() {
|
|||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *Collector) collectNode(logger log.Logger, ch chan<- prometheus.Metric) ([]string, error) {
|
func (c *Collector) collectNode(ch chan<- prometheus.Metric) ([]string, error) {
|
||||||
var dst []msClusterNode
|
var dst []msClusterNode
|
||||||
|
|
||||||
q := wmi.QueryAllForClass(&dst, "MSCluster_Node", logger)
|
if err := c.wmiClient.Query("SELECT * FROM MSCluster_Node", &dst, nil, "root/MSCluster"); err != nil {
|
||||||
if err := wmi.QueryNamespace(q, &dst, "root/MSCluster"); err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
package mscluster
|
package mscluster
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/go-kit/log"
|
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -148,11 +146,10 @@ func (c *Collector) buildResource() {
|
|||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *Collector) collectResource(logger log.Logger, ch chan<- prometheus.Metric, nodeNames []string) error {
|
func (c *Collector) collectResource(ch chan<- prometheus.Metric, nodeNames []string) error {
|
||||||
var dst []msClusterResource
|
var dst []msClusterResource
|
||||||
|
|
||||||
q := wmi.QueryAllForClass(&dst, "MSCluster_Resource", logger)
|
if err := c.wmiClient.Query("SELECT * FROM MSCluster_Resource", &dst, nil, "root/MSCluster"); err != nil {
|
||||||
if err := wmi.QueryNamespace(q, &dst, "root/MSCluster"); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
package mscluster
|
package mscluster
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/go-kit/log"
|
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -125,11 +123,10 @@ func (c *Collector) buildResourceGroup() {
|
|||||||
|
|
||||||
// Collect sends the metric values for each metric
|
// Collect sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *Collector) collectResourceGroup(logger log.Logger, ch chan<- prometheus.Metric, nodeNames []string) error {
|
func (c *Collector) collectResourceGroup(ch chan<- prometheus.Metric, nodeNames []string) error {
|
||||||
var dst []msClusterResourceGroup
|
var dst []msClusterResourceGroup
|
||||||
|
|
||||||
q := wmi.QueryAllForClass(&dst, "MSCluster_ResourceGroup", logger)
|
if err := c.wmiClient.Query("SELECT * FROM MSCluster_ResourceGroup", &dst, nil, "root/MSCluster"); err != nil {
|
||||||
if err := wmi.QueryNamespace(q, &dst, "root/MSCluster"); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
package msmq
|
package msmq
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/alecthomas/kingpin/v2"
|
"github.com/alecthomas/kingpin/v2"
|
||||||
@@ -10,8 +11,8 @@ import (
|
|||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/utils"
|
"github.com/prometheus-community/windows_exporter/pkg/utils"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "msmq"
|
const Name = "msmq"
|
||||||
@@ -26,7 +27,8 @@ var ConfigDefaults = Config{
|
|||||||
|
|
||||||
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_MSMQ_MSMQQueue metrics.
|
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_MSMQ_MSMQQueue metrics.
|
||||||
type Collector struct {
|
type Collector struct {
|
||||||
config Config
|
config Config
|
||||||
|
wmiClient *wmi.Client
|
||||||
|
|
||||||
bytesInJournalQueue *prometheus.Desc
|
bytesInJournalQueue *prometheus.Desc
|
||||||
bytesInQueue *prometheus.Desc
|
bytesInQueue *prometheus.Desc
|
||||||
@@ -74,9 +76,15 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(logger log.Logger) error {
|
func (c *Collector) Build(logger log.Logger, wmiClient *wmi.Client) error {
|
||||||
logger = log.With(logger, "collector", Name)
|
logger = log.With(logger, "collector", Name)
|
||||||
|
|
||||||
|
if wmiClient == nil || wmiClient.SWbemServicesClient == nil {
|
||||||
|
return errors.New("wmiClient or SWbemServicesClient is nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
c.wmiClient = wmiClient
|
||||||
|
|
||||||
if *c.config.QueryWhereClause == "" {
|
if *c.config.QueryWhereClause == "" {
|
||||||
_ = level.Warn(logger).Log("msg", "No where-clause specified for msmq collector. This will generate a very large number of metrics!")
|
_ = level.Warn(logger).Log("msg", "No where-clause specified for msmq collector. This will generate a very large number of metrics!")
|
||||||
}
|
}
|
||||||
@@ -112,7 +120,7 @@ func (c *Collector) Build(logger log.Logger) error {
|
|||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
||||||
logger = log.With(logger, "collector", Name)
|
logger = log.With(logger, "collector", Name)
|
||||||
if err := c.collect(logger, ch); err != nil {
|
if err := c.collect(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting msmq metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting msmq metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -128,11 +136,15 @@ type msmqQueue struct {
|
|||||||
MessagesInQueue uint64
|
MessagesInQueue uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collect(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||||
var dst []msmqQueue
|
var dst []msmqQueue
|
||||||
|
|
||||||
q := wmi.QueryAllForClassWhere(&dst, "Win32_PerfRawData_MSMQ_MSMQQueue", *c.config.QueryWhereClause, logger)
|
query := "SELECT * FROM Win32_PerfRawData_MSMQ_MSMQQueue"
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if *c.config.QueryWhereClause != "" {
|
||||||
|
query += " WHERE " + *c.config.QueryWhereClause
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := c.wmiClient.Query(query, &dst); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import (
|
|||||||
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
"golang.org/x/sys/windows/registry"
|
"golang.org/x/sys/windows/registry"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -494,7 +495,7 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, _ *wmi.Client) error {
|
||||||
// Result must order, to prevent test failures.
|
// Result must order, to prevent test failures.
|
||||||
sort.Strings(c.config.CollectorsEnabled)
|
sort.Strings(c.config.CollectorsEnabled)
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "net"
|
const Name = "net"
|
||||||
@@ -115,7 +116,7 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, _ *wmi.Client) error {
|
||||||
c.bytesReceivedTotal = prometheus.NewDesc(
|
c.bytesReceivedTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "bytes_received_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "bytes_received_total"),
|
||||||
"(Network.BytesReceivedPerSec)",
|
"(Network.BytesReceivedPerSec)",
|
||||||
|
|||||||
@@ -3,12 +3,14 @@
|
|||||||
package netframework_clrexceptions
|
package netframework_clrexceptions
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
"github.com/alecthomas/kingpin/v2"
|
"github.com/alecthomas/kingpin/v2"
|
||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "netframework_clrexceptions"
|
const Name = "netframework_clrexceptions"
|
||||||
@@ -19,7 +21,8 @@ var ConfigDefaults = Config{}
|
|||||||
|
|
||||||
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRExceptions metrics.
|
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRExceptions metrics.
|
||||||
type Collector struct {
|
type Collector struct {
|
||||||
config Config
|
config Config
|
||||||
|
wmiClient *wmi.Client
|
||||||
|
|
||||||
numberOfExceptionsThrown *prometheus.Desc
|
numberOfExceptionsThrown *prometheus.Desc
|
||||||
numberOfFilters *prometheus.Desc
|
numberOfFilters *prometheus.Desc
|
||||||
@@ -55,7 +58,12 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, wmiClient *wmi.Client) error {
|
||||||
|
if wmiClient == nil || wmiClient.SWbemServicesClient == nil {
|
||||||
|
return errors.New("wmiClient or SWbemServicesClient is nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
c.wmiClient = wmiClient
|
||||||
c.numberOfExceptionsThrown = prometheus.NewDesc(
|
c.numberOfExceptionsThrown = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "exceptions_thrown_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "exceptions_thrown_total"),
|
||||||
"Displays the total number of exceptions thrown since the application started. This includes both .NET exceptions and unmanaged exceptions that are converted into .NET exceptions.",
|
"Displays the total number of exceptions thrown since the application started. This includes both .NET exceptions and unmanaged exceptions that are converted into .NET exceptions.",
|
||||||
@@ -87,7 +95,7 @@ func (c *Collector) Build(_ log.Logger) error {
|
|||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
||||||
logger = log.With(logger, "collector", Name)
|
logger = log.With(logger, "collector", Name)
|
||||||
if err := c.collect(logger, ch); err != nil {
|
if err := c.collect(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting win32_perfrawdata_netframework_netclrexceptions metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting win32_perfrawdata_netframework_netclrexceptions metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -104,10 +112,9 @@ type Win32_PerfRawData_NETFramework_NETCLRExceptions struct {
|
|||||||
ThrowToCatchDepthPersec uint32
|
ThrowToCatchDepthPersec uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collect(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_NETFramework_NETCLRExceptions
|
var dst []Win32_PerfRawData_NETFramework_NETCLRExceptions
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_NETFramework_NETCLRExceptions", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,14 @@
|
|||||||
package netframework_clrinterop
|
package netframework_clrinterop
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
"github.com/alecthomas/kingpin/v2"
|
"github.com/alecthomas/kingpin/v2"
|
||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "netframework_clrinterop"
|
const Name = "netframework_clrinterop"
|
||||||
@@ -19,7 +21,8 @@ var ConfigDefaults = Config{}
|
|||||||
|
|
||||||
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRInterop metrics.
|
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRInterop metrics.
|
||||||
type Collector struct {
|
type Collector struct {
|
||||||
config Config
|
config Config
|
||||||
|
wmiClient *wmi.Client
|
||||||
|
|
||||||
numberOfCCWs *prometheus.Desc
|
numberOfCCWs *prometheus.Desc
|
||||||
numberOfMarshalling *prometheus.Desc
|
numberOfMarshalling *prometheus.Desc
|
||||||
@@ -54,7 +57,12 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, wmiClient *wmi.Client) error {
|
||||||
|
if wmiClient == nil || wmiClient.SWbemServicesClient == nil {
|
||||||
|
return errors.New("wmiClient or SWbemServicesClient is nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
c.wmiClient = wmiClient
|
||||||
c.numberOfCCWs = prometheus.NewDesc(
|
c.numberOfCCWs = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "com_callable_wrappers_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "com_callable_wrappers_total"),
|
||||||
"Displays the current number of COM callable wrappers (CCWs). A CCW is a proxy for a managed object being referenced from an unmanaged COM client.",
|
"Displays the current number of COM callable wrappers (CCWs). A CCW is a proxy for a managed object being referenced from an unmanaged COM client.",
|
||||||
@@ -80,7 +88,7 @@ func (c *Collector) Build(_ log.Logger) error {
|
|||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
||||||
logger = log.With(logger, "collector", Name)
|
logger = log.With(logger, "collector", Name)
|
||||||
if err := c.collect(logger, ch); err != nil {
|
if err := c.collect(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting win32_perfrawdata_netframework_netclrinterop metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting win32_perfrawdata_netframework_netclrinterop metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -97,10 +105,9 @@ type Win32_PerfRawData_NETFramework_NETCLRInterop struct {
|
|||||||
NumberofTLBimportsPersec uint32
|
NumberofTLBimportsPersec uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collect(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_NETFramework_NETCLRInterop
|
var dst []Win32_PerfRawData_NETFramework_NETCLRInterop
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_NETFramework_NETCLRInterop", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ import (
|
|||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "netframework_clrjit"
|
const Name = "netframework_clrjit"
|
||||||
@@ -19,7 +19,8 @@ var ConfigDefaults = Config{}
|
|||||||
|
|
||||||
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRJit metrics.
|
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRJit metrics.
|
||||||
type Collector struct {
|
type Collector struct {
|
||||||
config Config
|
config Config
|
||||||
|
wmiClient *wmi.Client
|
||||||
|
|
||||||
numberOfMethodsJitted *prometheus.Desc
|
numberOfMethodsJitted *prometheus.Desc
|
||||||
timeInJit *prometheus.Desc
|
timeInJit *prometheus.Desc
|
||||||
@@ -55,7 +56,7 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, _ *wmi.Client) error {
|
||||||
c.numberOfMethodsJitted = prometheus.NewDesc(
|
c.numberOfMethodsJitted = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "jit_methods_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "jit_methods_total"),
|
||||||
"Displays the total number of methods JIT-compiled since the application started. This counter does not include pre-JIT-compiled methods.",
|
"Displays the total number of methods JIT-compiled since the application started. This counter does not include pre-JIT-compiled methods.",
|
||||||
@@ -87,7 +88,7 @@ func (c *Collector) Build(_ log.Logger) error {
|
|||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
||||||
logger = log.With(logger, "collector", Name)
|
logger = log.With(logger, "collector", Name)
|
||||||
if err := c.collect(logger, ch); err != nil {
|
if err := c.collect(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting win32_perfrawdata_netframework_netclrjit metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting win32_perfrawdata_netframework_netclrjit metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -106,10 +107,9 @@ type Win32_PerfRawData_NETFramework_NETCLRJit struct {
|
|||||||
TotalNumberofILBytesJitted uint32
|
TotalNumberofILBytesJitted uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collect(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_NETFramework_NETCLRJit
|
var dst []Win32_PerfRawData_NETFramework_NETCLRJit
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_NETFramework_NETCLRJit", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,14 @@
|
|||||||
package netframework_clrloading
|
package netframework_clrloading
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
"github.com/alecthomas/kingpin/v2"
|
"github.com/alecthomas/kingpin/v2"
|
||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "netframework_clrloading"
|
const Name = "netframework_clrloading"
|
||||||
@@ -19,7 +21,8 @@ var ConfigDefaults = Config{}
|
|||||||
|
|
||||||
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRLoading metrics.
|
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRLoading metrics.
|
||||||
type Collector struct {
|
type Collector struct {
|
||||||
config Config
|
config Config
|
||||||
|
wmiClient *wmi.Client
|
||||||
|
|
||||||
bytesInLoaderHeap *prometheus.Desc
|
bytesInLoaderHeap *prometheus.Desc
|
||||||
currentAppDomains *prometheus.Desc
|
currentAppDomains *prometheus.Desc
|
||||||
@@ -60,7 +63,13 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, wmiClient *wmi.Client) error {
|
||||||
|
if wmiClient == nil || wmiClient.SWbemServicesClient == nil {
|
||||||
|
return errors.New("wmiClient or SWbemServicesClient is nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
c.wmiClient = wmiClient
|
||||||
|
|
||||||
c.bytesInLoaderHeap = prometheus.NewDesc(
|
c.bytesInLoaderHeap = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "loader_heap_size_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "loader_heap_size_bytes"),
|
||||||
"Displays the current size, in bytes, of the memory committed by the class loader across all application domains. Committed memory is the physical space reserved in the disk paging file.",
|
"Displays the current size, in bytes, of the memory committed by the class loader across all application domains. Committed memory is the physical space reserved in the disk paging file.",
|
||||||
@@ -122,7 +131,7 @@ func (c *Collector) Build(_ log.Logger) error {
|
|||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
||||||
logger = log.With(logger, "collector", Name)
|
logger = log.With(logger, "collector", Name)
|
||||||
if err := c.collect(logger, ch); err != nil {
|
if err := c.collect(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting win32_perfrawdata_netframework_netclrloading metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting win32_perfrawdata_netframework_netclrloading metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -150,10 +159,9 @@ type Win32_PerfRawData_NETFramework_NETCLRLoading struct {
|
|||||||
TotalNumberofLoadFailures uint32
|
TotalNumberofLoadFailures uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collect(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_NETFramework_NETCLRLoading
|
var dst []Win32_PerfRawData_NETFramework_NETCLRLoading
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_NETFramework_NETCLRLoading", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,14 @@
|
|||||||
package netframework_clrlocksandthreads
|
package netframework_clrlocksandthreads
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
"github.com/alecthomas/kingpin/v2"
|
"github.com/alecthomas/kingpin/v2"
|
||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "netframework_clrlocksandthreads"
|
const Name = "netframework_clrlocksandthreads"
|
||||||
@@ -19,7 +21,8 @@ var ConfigDefaults = Config{}
|
|||||||
|
|
||||||
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRLocksAndThreads metrics.
|
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRLocksAndThreads metrics.
|
||||||
type Collector struct {
|
type Collector struct {
|
||||||
config Config
|
config Config
|
||||||
|
wmiClient *wmi.Client
|
||||||
|
|
||||||
currentQueueLength *prometheus.Desc
|
currentQueueLength *prometheus.Desc
|
||||||
numberOfCurrentLogicalThreads *prometheus.Desc
|
numberOfCurrentLogicalThreads *prometheus.Desc
|
||||||
@@ -58,7 +61,13 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, wmiClient *wmi.Client) error {
|
||||||
|
if wmiClient == nil || wmiClient.SWbemServicesClient == nil {
|
||||||
|
return errors.New("wmiClient or SWbemServicesClient is nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
c.wmiClient = wmiClient
|
||||||
|
|
||||||
c.currentQueueLength = prometheus.NewDesc(
|
c.currentQueueLength = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "current_queue_length"),
|
prometheus.BuildFQName(types.Namespace, Name, "current_queue_length"),
|
||||||
"Displays the total number of threads that are currently waiting to acquire a managed lock in the application.",
|
"Displays the total number of threads that are currently waiting to acquire a managed lock in the application.",
|
||||||
@@ -108,7 +117,7 @@ func (c *Collector) Build(_ log.Logger) error {
|
|||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
||||||
logger = log.With(logger, "collector", Name)
|
logger = log.With(logger, "collector", Name)
|
||||||
if err := c.collect(logger, ch); err != nil {
|
if err := c.collect(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting win32_perfrawdata_netframework_netclrlocksandthreads metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting win32_perfrawdata_netframework_netclrlocksandthreads metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -130,10 +139,9 @@ type Win32_PerfRawData_NETFramework_NETCLRLocksAndThreads struct {
|
|||||||
TotalNumberofContentions uint32
|
TotalNumberofContentions uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collect(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_NETFramework_NETCLRLocksAndThreads
|
var dst []Win32_PerfRawData_NETFramework_NETCLRLocksAndThreads
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_NETFramework_NETCLRLocksAndThreads", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,14 @@
|
|||||||
package netframework_clrmemory
|
package netframework_clrmemory
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
"github.com/alecthomas/kingpin/v2"
|
"github.com/alecthomas/kingpin/v2"
|
||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "netframework_clrmemory"
|
const Name = "netframework_clrmemory"
|
||||||
@@ -19,7 +21,8 @@ var ConfigDefaults = Config{}
|
|||||||
|
|
||||||
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRMemory metrics.
|
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRMemory metrics.
|
||||||
type Collector struct {
|
type Collector struct {
|
||||||
config Config
|
config Config
|
||||||
|
wmiClient *wmi.Client
|
||||||
|
|
||||||
allocatedBytes *prometheus.Desc
|
allocatedBytes *prometheus.Desc
|
||||||
finalizationSurvivors *prometheus.Desc
|
finalizationSurvivors *prometheus.Desc
|
||||||
@@ -63,7 +66,13 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, wmiClient *wmi.Client) error {
|
||||||
|
if wmiClient == nil || wmiClient.SWbemServicesClient == nil {
|
||||||
|
return errors.New("wmiClient or SWbemServicesClient is nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
c.wmiClient = wmiClient
|
||||||
|
|
||||||
c.allocatedBytes = prometheus.NewDesc(
|
c.allocatedBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "allocated_bytes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "allocated_bytes_total"),
|
||||||
"Displays the total number of bytes allocated on the garbage collection heap.",
|
"Displays the total number of bytes allocated on the garbage collection heap.",
|
||||||
@@ -143,7 +152,7 @@ func (c *Collector) Build(_ log.Logger) error {
|
|||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
||||||
logger = log.With(logger, "collector", Name)
|
logger = log.With(logger, "collector", Name)
|
||||||
if err := c.collect(logger, ch); err != nil {
|
if err := c.collect(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting win32_perfrawdata_netframework_netclrmemory metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting win32_perfrawdata_netframework_netclrmemory metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -184,10 +193,9 @@ type Win32_PerfRawData_NETFramework_NETCLRMemory struct {
|
|||||||
PromotedMemoryfromGen1 uint64
|
PromotedMemoryfromGen1 uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collect(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_NETFramework_NETCLRMemory
|
var dst []Win32_PerfRawData_NETFramework_NETCLRMemory
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_NETFramework_NETCLRMemory", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,14 @@
|
|||||||
package netframework_clrremoting
|
package netframework_clrremoting
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
"github.com/alecthomas/kingpin/v2"
|
"github.com/alecthomas/kingpin/v2"
|
||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "netframework_clrremoting"
|
const Name = "netframework_clrremoting"
|
||||||
@@ -19,7 +21,8 @@ var ConfigDefaults = Config{}
|
|||||||
|
|
||||||
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRRemoting metrics.
|
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRRemoting metrics.
|
||||||
type Collector struct {
|
type Collector struct {
|
||||||
config Config
|
config Config
|
||||||
|
wmiClient *wmi.Client
|
||||||
|
|
||||||
channels *prometheus.Desc
|
channels *prometheus.Desc
|
||||||
contextBoundClassesLoaded *prometheus.Desc
|
contextBoundClassesLoaded *prometheus.Desc
|
||||||
@@ -57,7 +60,13 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, wmiClient *wmi.Client) error {
|
||||||
|
if wmiClient == nil || wmiClient.SWbemServicesClient == nil {
|
||||||
|
return errors.New("wmiClient or SWbemServicesClient is nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
c.wmiClient = wmiClient
|
||||||
|
|
||||||
c.channels = prometheus.NewDesc(
|
c.channels = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "channels_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "channels_total"),
|
||||||
"Displays the total number of remoting channels registered across all application domains since application started.",
|
"Displays the total number of remoting channels registered across all application domains since application started.",
|
||||||
@@ -101,7 +110,7 @@ func (c *Collector) Build(_ log.Logger) error {
|
|||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
||||||
logger = log.With(logger, "collector", Name)
|
logger = log.With(logger, "collector", Name)
|
||||||
if err := c.collect(logger, ch); err != nil {
|
if err := c.collect(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting win32_perfrawdata_netframework_netclrremoting metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting win32_perfrawdata_netframework_netclrremoting metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -120,10 +129,9 @@ type Win32_PerfRawData_NETFramework_NETCLRRemoting struct {
|
|||||||
TotalRemoteCalls uint32
|
TotalRemoteCalls uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collect(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_NETFramework_NETCLRRemoting
|
var dst []Win32_PerfRawData_NETFramework_NETCLRRemoting
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_NETFramework_NETCLRRemoting", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,14 @@
|
|||||||
package netframework_clrsecurity
|
package netframework_clrsecurity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
"github.com/alecthomas/kingpin/v2"
|
"github.com/alecthomas/kingpin/v2"
|
||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "netframework_clrsecurity"
|
const Name = "netframework_clrsecurity"
|
||||||
@@ -19,7 +21,8 @@ var ConfigDefaults = Config{}
|
|||||||
|
|
||||||
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRSecurity metrics.
|
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_NETFramework_NETCLRSecurity metrics.
|
||||||
type Collector struct {
|
type Collector struct {
|
||||||
config Config
|
config Config
|
||||||
|
wmiClient *wmi.Client
|
||||||
|
|
||||||
numberLinkTimeChecks *prometheus.Desc
|
numberLinkTimeChecks *prometheus.Desc
|
||||||
timeInRTChecks *prometheus.Desc
|
timeInRTChecks *prometheus.Desc
|
||||||
@@ -55,7 +58,12 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, wmiClient *wmi.Client) error {
|
||||||
|
if wmiClient == nil || wmiClient.SWbemServicesClient == nil {
|
||||||
|
return errors.New("wmiClient or SWbemServicesClient is nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
c.wmiClient = wmiClient
|
||||||
c.numberLinkTimeChecks = prometheus.NewDesc(
|
c.numberLinkTimeChecks = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "link_time_checks_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "link_time_checks_total"),
|
||||||
"Displays the total number of link-time code access security checks since the application started.",
|
"Displays the total number of link-time code access security checks since the application started.",
|
||||||
@@ -87,7 +95,7 @@ func (c *Collector) Build(_ log.Logger) error {
|
|||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
||||||
logger = log.With(logger, "collector", Name)
|
logger = log.With(logger, "collector", Name)
|
||||||
if err := c.collect(logger, ch); err != nil {
|
if err := c.collect(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting win32_perfrawdata_netframework_netclrsecurity metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting win32_perfrawdata_netframework_netclrsecurity metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -105,10 +113,9 @@ type Win32_PerfRawData_NETFramework_NETCLRSecurity struct {
|
|||||||
TotalRuntimeChecks uint32
|
TotalRuntimeChecks uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collect(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_NETFramework_NETCLRSecurity
|
var dst []Win32_PerfRawData_NETFramework_NETCLRSecurity
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_NETFramework_NETCLRSecurity", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
package nps
|
package nps
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/alecthomas/kingpin/v2"
|
"github.com/alecthomas/kingpin/v2"
|
||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "nps"
|
const Name = "nps"
|
||||||
@@ -19,7 +20,8 @@ var ConfigDefaults = Config{}
|
|||||||
|
|
||||||
// Collector is a Prometheus Collector for WMI Win32_PerfRawData_IAS_NPSAuthenticationServer and Win32_PerfRawData_IAS_NPSAccountingServer metrics.
|
// Collector is a Prometheus Collector for WMI Win32_PerfRawData_IAS_NPSAuthenticationServer and Win32_PerfRawData_IAS_NPSAccountingServer metrics.
|
||||||
type Collector struct {
|
type Collector struct {
|
||||||
config Config
|
config Config
|
||||||
|
wmiClient *wmi.Client
|
||||||
|
|
||||||
accessAccepts *prometheus.Desc
|
accessAccepts *prometheus.Desc
|
||||||
accessChallenges *prometheus.Desc
|
accessChallenges *prometheus.Desc
|
||||||
@@ -77,7 +79,12 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, wmiClient *wmi.Client) error {
|
||||||
|
if wmiClient == nil || wmiClient.SWbemServicesClient == nil {
|
||||||
|
return errors.New("wmiClient or SWbemServicesClient is nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
c.wmiClient = wmiClient
|
||||||
c.accessAccepts = prometheus.NewDesc(
|
c.accessAccepts = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "access_accepts"),
|
prometheus.BuildFQName(types.Namespace, Name, "access_accepts"),
|
||||||
"(AccessAccepts)",
|
"(AccessAccepts)",
|
||||||
@@ -236,11 +243,11 @@ func (c *Collector) Build(_ log.Logger) error {
|
|||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
||||||
logger = log.With(logger, "collector", Name)
|
logger = log.With(logger, "collector", Name)
|
||||||
if err := c.CollectAccept(logger, ch); err != nil {
|
if err := c.CollectAccept(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", fmt.Sprintf("failed collecting NPS accept data: %s", err))
|
_ = level.Error(logger).Log("msg", fmt.Sprintf("failed collecting NPS accept data: %s", err))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := c.CollectAccounting(logger, ch); err != nil {
|
if err := c.CollectAccounting(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", fmt.Sprintf("failed collecting NPS accounting data: %s", err))
|
_ = level.Error(logger).Log("msg", fmt.Sprintf("failed collecting NPS accounting data: %s", err))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -286,10 +293,9 @@ type Win32_PerfRawData_IAS_NPSAccountingServer struct {
|
|||||||
|
|
||||||
// CollectAccept sends the metric values for each metric
|
// CollectAccept sends the metric values for each metric
|
||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *Collector) CollectAccept(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) CollectAccept(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_IAS_NPSAuthenticationServer
|
var dst []Win32_PerfRawData_IAS_NPSAuthenticationServer
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_IAS_NPSAuthenticationServer", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -374,10 +380,9 @@ func (c *Collector) CollectAccept(logger log.Logger, ch chan<- prometheus.Metric
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) CollectAccounting(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) CollectAccounting(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_IAS_NPSAccountingServer
|
var dst []Win32_PerfRawData_IAS_NPSAccountingServer
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_IAS_NPSAccountingServer", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import (
|
|||||||
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
"golang.org/x/sys/windows/registry"
|
"golang.org/x/sys/windows/registry"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -83,7 +84,7 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, _ *wmi.Client) error {
|
||||||
c.osInformation = prometheus.NewDesc(
|
c.osInformation = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "info"),
|
prometheus.BuildFQName(types.Namespace, Name, "info"),
|
||||||
"OperatingSystem.Caption, OperatingSystem.Version",
|
"OperatingSystem.Caption, OperatingSystem.Version",
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "physical_disk"
|
const Name = "physical_disk"
|
||||||
@@ -113,7 +114,7 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, _ *wmi.Client) error {
|
||||||
c.requestsQueued = prometheus.NewDesc(
|
c.requestsQueued = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "requests_queued"),
|
prometheus.BuildFQName(types.Namespace, Name, "requests_queued"),
|
||||||
"The number of requests queued to the disk (PhysicalDisk.CurrentDiskQueueLength)",
|
"The number of requests queued to the disk (PhysicalDisk.CurrentDiskQueueLength)",
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
package printer
|
package printer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -11,8 +12,8 @@ import (
|
|||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "printer"
|
const Name = "printer"
|
||||||
@@ -39,7 +40,8 @@ var ConfigDefaults = Config{
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Collector struct {
|
type Collector struct {
|
||||||
config Config
|
config Config
|
||||||
|
wmiClient *wmi.Client
|
||||||
|
|
||||||
printerStatus *prometheus.Desc
|
printerStatus *prometheus.Desc
|
||||||
printerJobStatus *prometheus.Desc
|
printerJobStatus *prometheus.Desc
|
||||||
@@ -106,7 +108,13 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, wmiClient *wmi.Client) error {
|
||||||
|
if wmiClient == nil || wmiClient.SWbemServicesClient == nil {
|
||||||
|
return errors.New("wmiClient or SWbemServicesClient is nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
c.wmiClient = wmiClient
|
||||||
|
|
||||||
c.printerJobStatus = prometheus.NewDesc(
|
c.printerJobStatus = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "job_status"),
|
prometheus.BuildFQName(types.Namespace, Name, "job_status"),
|
||||||
"A counter of printer jobs by status",
|
"A counter of printer jobs by status",
|
||||||
@@ -147,12 +155,12 @@ type wmiPrintJob struct {
|
|||||||
|
|
||||||
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
||||||
logger = log.With(logger, "collector", Name)
|
logger = log.With(logger, "collector", Name)
|
||||||
if err := c.collectPrinterStatus(logger, ch); err != nil {
|
if err := c.collectPrinterStatus(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed to collect printer status metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed to collect printer status metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.collectPrinterJobStatus(logger, ch); err != nil {
|
if err := c.collectPrinterJobStatus(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed to collect printer job status metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed to collect printer job status metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -160,11 +168,9 @@ func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<-
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collectPrinterStatus(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectPrinterStatus(ch chan<- prometheus.Metric) error {
|
||||||
var printers []wmiPrinter
|
var printers []wmiPrinter
|
||||||
|
if err := c.wmiClient.Query("SELECT * FROM win32_Printer", &printers); err != nil {
|
||||||
q := wmi.QueryAllForClass(&printers, "win32_Printer", logger)
|
|
||||||
if err := wmi.Query(q, &printers); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,11 +206,9 @@ func (c *Collector) collectPrinterStatus(logger log.Logger, ch chan<- prometheus
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collectPrinterJobStatus(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectPrinterJobStatus(ch chan<- prometheus.Metric) error {
|
||||||
var printJobs []wmiPrintJob
|
var printJobs []wmiPrintJob
|
||||||
|
if err := c.wmiClient.Query("SELECT * FROM win32_PrintJob", &printJobs); err != nil {
|
||||||
q := wmi.QueryAllForClass(&printJobs, "win32_PrintJob", logger)
|
|
||||||
if err := wmi.Query(q, &printJobs); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ import (
|
|||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
"golang.org/x/sys/windows"
|
"golang.org/x/sys/windows"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -37,7 +37,8 @@ var ConfigDefaults = Config{
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Collector struct {
|
type Collector struct {
|
||||||
config Config
|
config Config
|
||||||
|
wmiClient *wmi.Client
|
||||||
|
|
||||||
lookupCache map[string]string
|
lookupCache map[string]string
|
||||||
|
|
||||||
@@ -136,9 +137,15 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(logger log.Logger) error {
|
func (c *Collector) Build(logger log.Logger, wmiClient *wmi.Client) error {
|
||||||
logger = log.With(logger, "collector", Name)
|
logger = log.With(logger, "collector", Name)
|
||||||
|
|
||||||
|
if wmiClient == nil || wmiClient.SWbemServicesClient == nil {
|
||||||
|
return errors.New("wmiClient or SWbemServicesClient is nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
c.wmiClient = wmiClient
|
||||||
|
|
||||||
if c.config.ProcessInclude.String() == "^(?:.*)$" && c.config.ProcessExclude.String() == "^(?:)$" {
|
if c.config.ProcessInclude.String() == "^(?:.*)$" && c.config.ProcessExclude.String() == "^(?:)$" {
|
||||||
_ = level.Warn(logger).Log("msg", "No filters specified for process collector. This will generate a very large number of metrics!")
|
_ = level.Warn(logger).Log("msg", "No filters specified for process collector. This will generate a very large number of metrics!")
|
||||||
}
|
}
|
||||||
@@ -291,8 +298,7 @@ func (c *Collector) Collect(ctx *types.ScrapeContext, logger log.Logger, ch chan
|
|||||||
|
|
||||||
var workerProcesses []WorkerProcess
|
var workerProcesses []WorkerProcess
|
||||||
if c.config.EnableWorkerProcess {
|
if c.config.EnableWorkerProcess {
|
||||||
queryWorkerProcess := wmi.QueryAllForClass(&workerProcesses, "WorkerProcess", logger)
|
if err := c.wmiClient.Query("SELECT * FROM WorkerProcess", &workerProcesses, nil, "root\\WebAdministration"); err != nil {
|
||||||
if err := wmi.QueryNamespace(queryWorkerProcess, &workerProcesses, "root\\WebAdministration"); err != nil {
|
|
||||||
_ = level.Debug(logger).Log("msg", "Could not query WebAdministration namespace for IIS worker processes", "err", err)
|
_ = level.Debug(logger).Log("msg", "Could not query WebAdministration namespace for IIS worker processes", "err", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/utils"
|
"github.com/prometheus-community/windows_exporter/pkg/utils"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "remote_fx"
|
const Name = "remote_fx"
|
||||||
@@ -81,7 +82,7 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(log.Logger, *wmi.Client) error {
|
||||||
// net
|
// net
|
||||||
c.baseTCPRTT = prometheus.NewDesc(
|
c.baseTCPRTT = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "net_base_tcp_rtt_seconds"),
|
prometheus.BuildFQName(types.Namespace, Name, "net_base_tcp_rtt_seconds"),
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import (
|
|||||||
"github.com/go-ole/go-ole/oleutil"
|
"github.com/go-ole/go-ole/oleutil"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "scheduled_task"
|
const Name = "scheduled_task"
|
||||||
@@ -136,7 +137,7 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, _ *wmi.Client) error {
|
||||||
c.lastResult = prometheus.NewDesc(
|
c.lastResult = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "last_result"),
|
prometheus.BuildFQName(types.Namespace, Name, "last_result"),
|
||||||
"The result that was returned the last time the registered task was run",
|
"The result that was returned the last time the registered task was run",
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ import (
|
|||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/utils"
|
"github.com/prometheus-community/windows_exporter/pkg/utils"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
"golang.org/x/sys/windows"
|
"golang.org/x/sys/windows"
|
||||||
"golang.org/x/sys/windows/svc/mgr"
|
"golang.org/x/sys/windows/svc/mgr"
|
||||||
)
|
)
|
||||||
@@ -41,6 +41,8 @@ type Collector struct {
|
|||||||
useAPI *bool
|
useAPI *bool
|
||||||
v2 *bool
|
v2 *bool
|
||||||
|
|
||||||
|
wmiClient *wmi.Client
|
||||||
|
|
||||||
Information *prometheus.Desc
|
Information *prometheus.Desc
|
||||||
State *prometheus.Desc
|
State *prometheus.Desc
|
||||||
StartMode *prometheus.Desc
|
StartMode *prometheus.Desc
|
||||||
@@ -90,7 +92,13 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(logger log.Logger) error {
|
func (c *Collector) Build(logger log.Logger, wmiClient *wmi.Client) error {
|
||||||
|
if wmiClient == nil || wmiClient.SWbemServicesClient == nil {
|
||||||
|
return errors.New("wmiClient or SWbemServicesClient is nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
c.wmiClient = wmiClient
|
||||||
|
|
||||||
logger = log.With(logger, "collector", Name)
|
logger = log.With(logger, "collector", Name)
|
||||||
|
|
||||||
if utils.IsEmpty(c.serviceWhereClause) {
|
if utils.IsEmpty(c.serviceWhereClause) {
|
||||||
@@ -150,7 +158,7 @@ func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<-
|
|||||||
_ = level.Error(logger).Log("msg", "failed collecting API service metrics:", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting API service metrics:", "err", err)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
if err = c.collectWMI(logger, ch); err != nil {
|
if err = c.collectWMI(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting WMI service metrics:", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting WMI service metrics:", "err", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -220,10 +228,15 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *Collector) collectWMI(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectWMI(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_Service
|
var dst []Win32_Service
|
||||||
q := wmi.QueryAllWhere(&dst, *c.serviceWhereClause, logger) //nolint:staticcheck
|
query := "SELECT * FROM Win32_Service"
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
|
if *c.serviceWhereClause != "" {
|
||||||
|
query += " WHERE " + *c.serviceWhereClause
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := c.wmiClient.Query(query, &dst); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, service := range dst {
|
for _, service := range dst {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "smb"
|
const Name = "smb"
|
||||||
@@ -56,7 +57,7 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, _ *wmi.Client) error {
|
||||||
// desc creates a new prometheus description
|
// desc creates a new prometheus description
|
||||||
desc := func(metricName string, description string, labels ...string) *prometheus.Desc {
|
desc := func(metricName string, description string, labels ...string) *prometheus.Desc {
|
||||||
return prometheus.NewDesc(
|
return prometheus.NewDesc(
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -78,7 +79,7 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, _ *wmi.Client) error {
|
||||||
// desc creates a new prometheus description
|
// desc creates a new prometheus description
|
||||||
desc := func(metricName string, description string, labels []string) *prometheus.Desc {
|
desc := func(metricName string, description string, labels []string) *prometheus.Desc {
|
||||||
return prometheus.NewDesc(
|
return prometheus.NewDesc(
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "smtp"
|
const Name = "smtp"
|
||||||
@@ -141,7 +142,7 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(logger log.Logger) error {
|
func (c *Collector) Build(logger log.Logger, _ *wmi.Client) error {
|
||||||
logger = log.With(logger, "collector", Name)
|
logger = log.With(logger, "collector", Name)
|
||||||
|
|
||||||
_ = level.Info(logger).Log("msg", "smtp collector is in an experimental state! Metrics for this collector have not been tested.")
|
_ = level.Info(logger).Log("msg", "smtp collector is in an experimental state! Metrics for this collector have not been tested.")
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "system"
|
const Name = "system"
|
||||||
@@ -57,7 +58,7 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, _ *wmi.Client) error {
|
||||||
c.contextSwitchesTotal = prometheus.NewDesc(
|
c.contextSwitchesTotal = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "context_switches_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "context_switches_total"),
|
||||||
"Total number of context switches (WMI source: PerfOS_System.ContextSwitchesPersec)",
|
"Total number of context switches (WMI source: PerfOS_System.ContextSwitchesPersec)",
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "tcp"
|
const Name = "tcp"
|
||||||
@@ -60,7 +61,7 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, _ *wmi.Client) error {
|
||||||
c.connectionFailures = prometheus.NewDesc(
|
c.connectionFailures = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "connection_failures_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "connection_failures_total"),
|
||||||
"(TCP.ConnectionFailures)",
|
"(TCP.ConnectionFailures)",
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import (
|
|||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "teradici_pcoip"
|
const Name = "teradici_pcoip"
|
||||||
@@ -26,7 +26,8 @@ var ConfigDefaults = Config{}
|
|||||||
// win32_PerfRawData_TeradiciPerf_PCoIPSessionNetworkStatistics
|
// win32_PerfRawData_TeradiciPerf_PCoIPSessionNetworkStatistics
|
||||||
// win32_PerfRawData_TeradiciPerf_PCoIPSessionUsbStatistics.
|
// win32_PerfRawData_TeradiciPerf_PCoIPSessionUsbStatistics.
|
||||||
type Collector struct {
|
type Collector struct {
|
||||||
config Config
|
config Config
|
||||||
|
wmiClient *wmi.Client
|
||||||
|
|
||||||
audioBytesReceived *prometheus.Desc
|
audioBytesReceived *prometheus.Desc
|
||||||
audioBytesSent *prometheus.Desc
|
audioBytesSent *prometheus.Desc
|
||||||
@@ -99,10 +100,16 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(logger log.Logger) error {
|
func (c *Collector) Build(logger log.Logger, wmiClient *wmi.Client) error {
|
||||||
_ = level.Warn(logger).
|
_ = level.Warn(logger).
|
||||||
Log("msg", "teradici_pcoip collector is deprecated and will be removed in the future.", "collector", Name)
|
Log("msg", "teradici_pcoip collector is deprecated and will be removed in the future.", "collector", Name)
|
||||||
|
|
||||||
|
if wmiClient == nil || wmiClient.SWbemServicesClient == nil {
|
||||||
|
return errors.New("wmiClient or SWbemServicesClient is nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
c.wmiClient = wmiClient
|
||||||
|
|
||||||
c.audioBytesReceived = prometheus.NewDesc(
|
c.audioBytesReceived = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "audio_bytes_received_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "audio_bytes_received_total"),
|
||||||
"(AudioBytesReceived)",
|
"(AudioBytesReceived)",
|
||||||
@@ -336,23 +343,23 @@ func (c *Collector) Build(logger log.Logger) error {
|
|||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
||||||
logger = log.With(logger, "collector", Name)
|
logger = log.With(logger, "collector", Name)
|
||||||
if err := c.collectAudio(logger, ch); err != nil {
|
if err := c.collectAudio(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting teradici session audio metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting teradici session audio metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := c.collectGeneral(logger, ch); err != nil {
|
if err := c.collectGeneral(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting teradici session general metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting teradici session general metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := c.collectImaging(logger, ch); err != nil {
|
if err := c.collectImaging(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting teradici session imaging metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting teradici session imaging metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := c.collectNetwork(logger, ch); err != nil {
|
if err := c.collectNetwork(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting teradici session network metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting teradici session network metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := c.collectUsb(logger, ch); err != nil {
|
if err := c.collectUsb(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting teradici session USB metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting teradici session USB metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -411,10 +418,9 @@ type win32_PerfRawData_TeradiciPerf_PCoIPSessionUsbStatistics struct {
|
|||||||
USBTXBWKBitPerSec uint64
|
USBTXBWKBitPerSec uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collectAudio(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectAudio(ch chan<- prometheus.Metric) error {
|
||||||
var dst []win32_PerfRawData_TeradiciPerf_PCoIPSessionAudioStatistics
|
var dst []win32_PerfRawData_TeradiciPerf_PCoIPSessionAudioStatistics
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM win32_PerfRawData_TeradiciPerf_PCoIPSessionAudioStatistics", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(dst) == 0 {
|
if len(dst) == 0 {
|
||||||
@@ -454,10 +460,9 @@ func (c *Collector) collectAudio(logger log.Logger, ch chan<- prometheus.Metric)
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collectGeneral(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectGeneral(ch chan<- prometheus.Metric) error {
|
||||||
var dst []win32_PerfRawData_TeradiciPerf_PCoIPSessionGeneralStatistics
|
var dst []win32_PerfRawData_TeradiciPerf_PCoIPSessionGeneralStatistics
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM win32_PerfRawData_TeradiciPerf_PCoIPSessionGeneralStatistics", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(dst) == 0 {
|
if len(dst) == 0 {
|
||||||
@@ -509,10 +514,9 @@ func (c *Collector) collectGeneral(logger log.Logger, ch chan<- prometheus.Metri
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collectImaging(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectImaging(ch chan<- prometheus.Metric) error {
|
||||||
var dst []win32_PerfRawData_TeradiciPerf_PCoIPSessionImagingStatistics
|
var dst []win32_PerfRawData_TeradiciPerf_PCoIPSessionImagingStatistics
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM win32_PerfRawData_TeradiciPerf_PCoIPSessionImagingStatistics", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(dst) == 0 {
|
if len(dst) == 0 {
|
||||||
@@ -588,10 +592,9 @@ func (c *Collector) collectImaging(logger log.Logger, ch chan<- prometheus.Metri
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collectNetwork(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectNetwork(ch chan<- prometheus.Metric) error {
|
||||||
var dst []win32_PerfRawData_TeradiciPerf_PCoIPSessionNetworkStatistics
|
var dst []win32_PerfRawData_TeradiciPerf_PCoIPSessionNetworkStatistics
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM win32_PerfRawData_TeradiciPerf_PCoIPSessionNetworkStatistics", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(dst) == 0 {
|
if len(dst) == 0 {
|
||||||
@@ -661,10 +664,9 @@ func (c *Collector) collectNetwork(logger log.Logger, ch chan<- prometheus.Metri
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collectUsb(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectUsb(ch chan<- prometheus.Metric) error {
|
||||||
var dst []win32_PerfRawData_TeradiciPerf_PCoIPSessionUsbStatistics
|
var dst []win32_PerfRawData_TeradiciPerf_PCoIPSessionUsbStatistics
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM win32_PerfRawData_TeradiciPerf_PCoIPSessionUsbStatistics", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(dst) == 0 {
|
if len(dst) == 0 {
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ import (
|
|||||||
"github.com/prometheus-community/windows_exporter/pkg/headers/wtsapi32"
|
"github.com/prometheus-community/windows_exporter/pkg/headers/wtsapi32"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -32,10 +32,9 @@ type Win32_ServerFeature struct {
|
|||||||
ID uint32
|
ID uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func isConnectionBrokerServer(logger log.Logger) bool {
|
func isConnectionBrokerServer(logger log.Logger, wmiClient *wmi.Client) bool {
|
||||||
var dst []Win32_ServerFeature
|
var dst []Win32_ServerFeature
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := wmiClient.Query("SELECT * FROM Win32_ServerFeature", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
for _, d := range dst {
|
for _, d := range dst {
|
||||||
@@ -111,10 +110,10 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(logger log.Logger) error {
|
func (c *Collector) Build(logger log.Logger, wmiClient *wmi.Client) error {
|
||||||
logger = log.With(logger, "collector", Name)
|
logger = log.With(logger, "collector", Name)
|
||||||
|
|
||||||
c.connectionBrokerEnabled = isConnectionBrokerServer(logger)
|
c.connectionBrokerEnabled = isConnectionBrokerServer(logger, wmiClient)
|
||||||
|
|
||||||
c.sessionInfo = prometheus.NewDesc(
|
c.sessionInfo = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "session_info"),
|
prometheus.BuildFQName(types.Namespace, Name, "session_info"),
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ import (
|
|||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
dto "github.com/prometheus/client_model/go"
|
dto "github.com/prometheus/client_model/go"
|
||||||
"github.com/prometheus/common/expfmt"
|
"github.com/prometheus/common/expfmt"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "textfile"
|
const Name = "textfile"
|
||||||
@@ -104,7 +105,7 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(logger log.Logger) error {
|
func (c *Collector) Build(logger log.Logger, _ *wmi.Client) error {
|
||||||
_ = level.Info(logger).
|
_ = level.Info(logger).
|
||||||
Log("msg", "textfile Collector directories: "+strings.Join(c.config.TextFileDirectories, ","), "collector", Name)
|
Log("msg", "textfile Collector directories: "+strings.Join(c.config.TextFileDirectories, ","), "collector", Name)
|
||||||
|
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ func TestDuplicateMetricEntry(t *testing.T) {
|
|||||||
Metric: []*dto.Metric{&metric1, &metric2},
|
Metric: []*dto.Metric{&metric1, &metric2},
|
||||||
}
|
}
|
||||||
|
|
||||||
duplicateFamily := []*dto.MetricFamily{}
|
var duplicateFamily []*dto.MetricFamily
|
||||||
duplicateFamily = append(duplicateFamily, &duplicate)
|
duplicateFamily = append(duplicateFamily, &duplicate)
|
||||||
|
|
||||||
// Ensure detection for duplicate metrics
|
// Ensure detection for duplicate metrics
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import (
|
|||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "thermalzone"
|
const Name = "thermalzone"
|
||||||
@@ -21,7 +21,8 @@ var ConfigDefaults = Config{}
|
|||||||
|
|
||||||
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_Counters_ThermalZoneInformation metrics.
|
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_Counters_ThermalZoneInformation metrics.
|
||||||
type Collector struct {
|
type Collector struct {
|
||||||
config Config
|
config Config
|
||||||
|
wmiClient *wmi.Client
|
||||||
|
|
||||||
percentPassiveLimit *prometheus.Desc
|
percentPassiveLimit *prometheus.Desc
|
||||||
temperature *prometheus.Desc
|
temperature *prometheus.Desc
|
||||||
@@ -56,7 +57,12 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, wmiClient *wmi.Client) error {
|
||||||
|
if wmiClient == nil || wmiClient.SWbemServicesClient == nil {
|
||||||
|
return errors.New("wmiClient or SWbemServicesClient is nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
c.wmiClient = wmiClient
|
||||||
c.temperature = prometheus.NewDesc(
|
c.temperature = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "temperature_celsius"),
|
prometheus.BuildFQName(types.Namespace, Name, "temperature_celsius"),
|
||||||
"(Temperature)",
|
"(Temperature)",
|
||||||
@@ -88,7 +94,7 @@ func (c *Collector) Build(_ log.Logger) error {
|
|||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
||||||
logger = log.With(logger, "collector", Name)
|
logger = log.With(logger, "collector", Name)
|
||||||
if err := c.collect(logger, ch); err != nil {
|
if err := c.collect(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting thermalzone metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting thermalzone metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -105,16 +111,15 @@ type Win32_PerfRawData_Counters_ThermalZoneInformation struct {
|
|||||||
ThrottleReasons uint32
|
ThrottleReasons uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collect(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_Counters_ThermalZoneInformation
|
var dst []Win32_PerfRawData_Counters_ThermalZoneInformation
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_Counters_ThermalZoneInformation", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// ThermalZone collector has been known to 'successfully' return an empty result.
|
// ThermalZone collector has been known to 'successfully' return an empty result.
|
||||||
if len(dst) == 0 {
|
if len(dst) == 0 {
|
||||||
return errors.New("Empty results set for collector")
|
return errors.New("empty results set for collector")
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, info := range dst {
|
for _, info := range dst {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/winversion"
|
"github.com/prometheus-community/windows_exporter/pkg/winversion"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "time"
|
const Name = "time"
|
||||||
@@ -60,9 +61,9 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, _ *wmi.Client) error {
|
||||||
if winversion.WindowsVersionFloat <= 6.1 {
|
if winversion.WindowsVersionFloat() <= 6.1 {
|
||||||
return errors.New("Windows version older than Server 2016 detected. The time collector will not run and should be disabled via CLI flags or configuration file")
|
return errors.New("windows version older than Server 2016 detected. The time collector will not run and should be disabled via CLI flags or configuration file")
|
||||||
}
|
}
|
||||||
|
|
||||||
c.clockFrequencyAdjustmentPPBTotal = prometheus.NewDesc(
|
c.clockFrequencyAdjustmentPPBTotal = prometheus.NewDesc(
|
||||||
|
|||||||
@@ -5,10 +5,12 @@ import (
|
|||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Collectors struct {
|
type Collectors struct {
|
||||||
collectors Map
|
collectors Map
|
||||||
|
wmiClient *wmi.Client
|
||||||
perfCounterQuery string
|
perfCounterQuery string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,7 +21,7 @@ type (
|
|||||||
|
|
||||||
// Collector interface that a collector has to implement.
|
// Collector interface that a collector has to implement.
|
||||||
type Collector interface {
|
type Collector interface {
|
||||||
Build(logger log.Logger) error
|
Build(logger log.Logger, wmiClient *wmi.Client) error
|
||||||
// Close closes the collector
|
// Close closes the collector
|
||||||
Close() error
|
Close() error
|
||||||
// GetName get the name of the collector
|
// GetName get the name of the collector
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ import (
|
|||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
"github.com/prometheus-community/windows_exporter/pkg/perflib"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "vmware"
|
const Name = "vmware"
|
||||||
@@ -22,7 +22,8 @@ var ConfigDefaults = Config{}
|
|||||||
|
|
||||||
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_vmGuestLib_VMem/Win32_PerfRawData_vmGuestLib_VCPU metrics.
|
// A Collector is a Prometheus Collector for WMI Win32_PerfRawData_vmGuestLib_VMem/Win32_PerfRawData_vmGuestLib_VCPU metrics.
|
||||||
type Collector struct {
|
type Collector struct {
|
||||||
config Config
|
config Config
|
||||||
|
wmiClient *wmi.Client
|
||||||
|
|
||||||
memActive *prometheus.Desc
|
memActive *prometheus.Desc
|
||||||
memBallooned *prometheus.Desc
|
memBallooned *prometheus.Desc
|
||||||
@@ -74,7 +75,13 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(_ log.Logger) error {
|
func (c *Collector) Build(_ log.Logger, wmiClient *wmi.Client) error {
|
||||||
|
if wmiClient == nil || wmiClient.SWbemServicesClient == nil {
|
||||||
|
return errors.New("wmiClient or SWbemServicesClient is nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
c.wmiClient = wmiClient
|
||||||
|
|
||||||
c.memActive = prometheus.NewDesc(
|
c.memActive = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "mem_active_bytes"),
|
prometheus.BuildFQName(types.Namespace, Name, "mem_active_bytes"),
|
||||||
"(MemActiveMB)",
|
"(MemActiveMB)",
|
||||||
@@ -197,11 +204,11 @@ func (c *Collector) Build(_ log.Logger) error {
|
|||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
||||||
logger = log.With(logger, "collector", Name)
|
logger = log.With(logger, "collector", Name)
|
||||||
if err := c.collectMem(logger, ch); err != nil {
|
if err := c.collectMem(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting vmware memory metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting vmware memory metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := c.collectCpu(logger, ch); err != nil {
|
if err := c.collectCpu(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting vmware cpu metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting vmware cpu metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -233,10 +240,9 @@ type Win32_PerfRawData_vmGuestLib_VCPU struct {
|
|||||||
HostProcessorSpeedMHz uint64
|
HostProcessorSpeedMHz uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collectMem(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectMem(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_vmGuestLib_VMem
|
var dst []Win32_PerfRawData_vmGuestLib_VMem
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_vmGuestLib_VMem", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(dst) == 0 {
|
if len(dst) == 0 {
|
||||||
@@ -322,10 +328,9 @@ func mbToBytes(mb uint64) float64 {
|
|||||||
return float64(mb * 1024 * 1024)
|
return float64(mb * 1024 * 1024)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collectCpu(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectCpu(ch chan<- prometheus.Metric) error {
|
||||||
var dst []Win32_PerfRawData_vmGuestLib_VCPU
|
var dst []Win32_PerfRawData_vmGuestLib_VCPU
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM Win32_PerfRawData_vmGuestLib_VCPU", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(dst) == 0 {
|
if len(dst) == 0 {
|
||||||
|
|||||||
@@ -3,12 +3,14 @@
|
|||||||
package vmware_blast
|
package vmware_blast
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
"github.com/alecthomas/kingpin/v2"
|
"github.com/alecthomas/kingpin/v2"
|
||||||
"github.com/go-kit/log"
|
"github.com/go-kit/log"
|
||||||
"github.com/go-kit/log/level"
|
"github.com/go-kit/log/level"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/wmi"
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/yusufpapurcu/wmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Name = "vmware_blast"
|
const Name = "vmware_blast"
|
||||||
@@ -32,7 +34,8 @@ var ConfigDefaults = Config{}
|
|||||||
// win32_PerfRawData_Counters_VMwareBlastWindowsMediaMMRCounters
|
// win32_PerfRawData_Counters_VMwareBlastWindowsMediaMMRCounters
|
||||||
|
|
||||||
type Collector struct {
|
type Collector struct {
|
||||||
config Config
|
config Config
|
||||||
|
wmiClient *wmi.Client
|
||||||
|
|
||||||
audioReceivedBytes *prometheus.Desc
|
audioReceivedBytes *prometheus.Desc
|
||||||
audioReceivedPackets *prometheus.Desc
|
audioReceivedPackets *prometheus.Desc
|
||||||
@@ -144,10 +147,16 @@ func (c *Collector) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) Build(logger log.Logger) error {
|
func (c *Collector) Build(logger log.Logger, wmiClient *wmi.Client) error {
|
||||||
_ = level.Warn(logger).
|
_ = level.Warn(logger).
|
||||||
Log("msg", "vmware_blast collector is deprecated and will be removed in the future.", "collector", Name)
|
Log("msg", "vmware_blast collector is deprecated and will be removed in the future.", "collector", Name)
|
||||||
|
|
||||||
|
if wmiClient == nil || wmiClient.SWbemServicesClient == nil {
|
||||||
|
return errors.New("wmiClient or SWbemServicesClient is nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
c.wmiClient = wmiClient
|
||||||
|
|
||||||
c.audioReceivedBytes = prometheus.NewDesc(
|
c.audioReceivedBytes = prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(types.Namespace, Name, "audio_received_bytes_total"),
|
prometheus.BuildFQName(types.Namespace, Name, "audio_received_bytes_total"),
|
||||||
"(AudioReceivedBytes)",
|
"(AudioReceivedBytes)",
|
||||||
@@ -580,51 +589,51 @@ func (c *Collector) Build(logger log.Logger) error {
|
|||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) Collect(_ *types.ScrapeContext, logger log.Logger, ch chan<- prometheus.Metric) error {
|
||||||
logger = log.With(logger, "collector", Name)
|
logger = log.With(logger, "collector", Name)
|
||||||
if err := c.collectAudio(logger, ch); err != nil {
|
if err := c.collectAudio(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting vmware blast audio metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting vmware blast audio metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := c.collectCdr(logger, ch); err != nil {
|
if err := c.collectCdr(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting vmware blast CDR metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting vmware blast CDR metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := c.collectClipboard(logger, ch); err != nil {
|
if err := c.collectClipboard(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting vmware blast clipboard metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting vmware blast clipboard metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := c.collectHtml5Mmr(logger, ch); err != nil {
|
if err := c.collectHtml5Mmr(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting vmware blast HTML5 MMR metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting vmware blast HTML5 MMR metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := c.collectImaging(logger, ch); err != nil {
|
if err := c.collectImaging(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting vmware blast imaging metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting vmware blast imaging metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := c.collectRtav(logger, ch); err != nil {
|
if err := c.collectRtav(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting vmware blast RTAV metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting vmware blast RTAV metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := c.collectSerialPortandScanner(logger, ch); err != nil {
|
if err := c.collectSerialPortandScanner(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting vmware blast serial port and scanner metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting vmware blast serial port and scanner metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := c.collectSession(logger, ch); err != nil {
|
if err := c.collectSession(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting vmware blast metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting vmware blast metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := c.collectSkypeforBusinessControl(logger, ch); err != nil {
|
if err := c.collectSkypeforBusinessControl(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting vmware blast skype for business control metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting vmware blast skype for business control metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := c.collectThinPrint(logger, ch); err != nil {
|
if err := c.collectThinPrint(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting vmware blast thin print metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting vmware blast thin print metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := c.collectUsb(logger, ch); err != nil {
|
if err := c.collectUsb(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting vmware blast USB metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting vmware blast USB metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := c.collectWindowsMediaMmr(logger, ch); err != nil {
|
if err := c.collectWindowsMediaMmr(ch); err != nil {
|
||||||
_ = level.Error(logger).Log("msg", "failed collecting vmware blast windows media MMR metrics", "err", err)
|
_ = level.Error(logger).Log("msg", "failed collecting vmware blast windows media MMR metrics", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -736,10 +745,9 @@ type win32_PerfRawData_Counters_VMwareBlastWindowsMediaMMRCounters struct {
|
|||||||
TransmittedPackets uint32
|
TransmittedPackets uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collectAudio(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectAudio(ch chan<- prometheus.Metric) error {
|
||||||
var dst []win32_PerfRawData_Counters_VMwareBlastAudioCounters
|
var dst []win32_PerfRawData_Counters_VMwareBlastAudioCounters
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM win32_PerfRawData_Counters_VMwareBlastAudioCounters", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -775,10 +783,9 @@ func (c *Collector) collectAudio(logger log.Logger, ch chan<- prometheus.Metric)
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collectCdr(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectCdr(ch chan<- prometheus.Metric) error {
|
||||||
var dst []win32_PerfRawData_Counters_VMwareBlastCDRCounters
|
var dst []win32_PerfRawData_Counters_VMwareBlastCDRCounters
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM win32_PerfRawData_Counters_VMwareBlastCDRCounters", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -814,10 +821,9 @@ func (c *Collector) collectCdr(logger log.Logger, ch chan<- prometheus.Metric) e
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collectClipboard(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectClipboard(ch chan<- prometheus.Metric) error {
|
||||||
var dst []win32_PerfRawData_Counters_VMwareBlastClipboardCounters
|
var dst []win32_PerfRawData_Counters_VMwareBlastClipboardCounters
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM win32_PerfRawData_Counters_VMwareBlastClipboardCounters", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -853,10 +859,9 @@ func (c *Collector) collectClipboard(logger log.Logger, ch chan<- prometheus.Met
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collectHtml5Mmr(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectHtml5Mmr(ch chan<- prometheus.Metric) error {
|
||||||
var dst []win32_PerfRawData_Counters_VMwareBlastHTML5MMRcounters
|
var dst []win32_PerfRawData_Counters_VMwareBlastHTML5MMRcounters
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM win32_PerfRawData_Counters_VMwareBlastHTML5MMRcounters", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -892,10 +897,9 @@ func (c *Collector) collectHtml5Mmr(logger log.Logger, ch chan<- prometheus.Metr
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collectImaging(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectImaging(ch chan<- prometheus.Metric) error {
|
||||||
var dst []win32_PerfRawData_Counters_VMwareBlastImagingCounters
|
var dst []win32_PerfRawData_Counters_VMwareBlastImagingCounters
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM win32_PerfRawData_Counters_VMwareBlastImagingCounters", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -979,10 +983,9 @@ func (c *Collector) collectImaging(logger log.Logger, ch chan<- prometheus.Metri
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collectRtav(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectRtav(ch chan<- prometheus.Metric) error {
|
||||||
var dst []win32_PerfRawData_Counters_VMwareBlastRTAVCounters
|
var dst []win32_PerfRawData_Counters_VMwareBlastRTAVCounters
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM win32_PerfRawData_Counters_VMwareBlastRTAVCounters", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1018,10 +1021,9 @@ func (c *Collector) collectRtav(logger log.Logger, ch chan<- prometheus.Metric)
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collectSerialPortandScanner(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectSerialPortandScanner(ch chan<- prometheus.Metric) error {
|
||||||
var dst []win32_PerfRawData_Counters_VMwareBlastSerialPortandScannerCounters
|
var dst []win32_PerfRawData_Counters_VMwareBlastSerialPortandScannerCounters
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM win32_PerfRawData_Counters_VMwareBlastSerialPortandScannerCounters", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1057,10 +1059,9 @@ func (c *Collector) collectSerialPortandScanner(logger log.Logger, ch chan<- pro
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collectSession(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectSession(ch chan<- prometheus.Metric) error {
|
||||||
var dst []win32_PerfRawData_Counters_VMwareBlastSessionCounters
|
var dst []win32_PerfRawData_Counters_VMwareBlastSessionCounters
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM win32_PerfRawData_Counters_VMwareBlastSessionCounters", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1174,10 +1175,9 @@ func (c *Collector) collectSession(logger log.Logger, ch chan<- prometheus.Metri
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collectSkypeforBusinessControl(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectSkypeforBusinessControl(ch chan<- prometheus.Metric) error {
|
||||||
var dst []win32_PerfRawData_Counters_VMwareBlastSkypeforBusinessControlCounters
|
var dst []win32_PerfRawData_Counters_VMwareBlastSkypeforBusinessControlCounters
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM win32_PerfRawData_Counters_VMwareBlastSkypeforBusinessControlCounters", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1213,10 +1213,9 @@ func (c *Collector) collectSkypeforBusinessControl(logger log.Logger, ch chan<-
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collectThinPrint(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectThinPrint(ch chan<- prometheus.Metric) error {
|
||||||
var dst []win32_PerfRawData_Counters_VMwareBlastThinPrintCounters
|
var dst []win32_PerfRawData_Counters_VMwareBlastThinPrintCounters
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM win32_PerfRawData_Counters_VMwareBlastThinPrintCounters", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1252,10 +1251,9 @@ func (c *Collector) collectThinPrint(logger log.Logger, ch chan<- prometheus.Met
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collectUsb(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectUsb(ch chan<- prometheus.Metric) error {
|
||||||
var dst []win32_PerfRawData_Counters_VMwareBlastUSBCounters
|
var dst []win32_PerfRawData_Counters_VMwareBlastUSBCounters
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM win32_PerfRawData_Counters_VMwareBlastUSBCounters", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1291,10 +1289,9 @@ func (c *Collector) collectUsb(logger log.Logger, ch chan<- prometheus.Metric) e
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collector) collectWindowsMediaMmr(logger log.Logger, ch chan<- prometheus.Metric) error {
|
func (c *Collector) collectWindowsMediaMmr(ch chan<- prometheus.Metric) error {
|
||||||
var dst []win32_PerfRawData_Counters_VMwareBlastWindowsMediaMMRCounters
|
var dst []win32_PerfRawData_Counters_VMwareBlastWindowsMediaMMRCounters
|
||||||
q := wmi.QueryAll(&dst, logger)
|
if err := c.wmiClient.Query("SELECT * FROM win32_PerfRawData_Counters_VMwareBlastWindowsMediaMMRCounters", &dst); err != nil {
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ type DynamicTimezoneInformation struct {
|
|||||||
func GetDynamicTimeZoneInformation() (DynamicTimezoneInformation, error) {
|
func GetDynamicTimeZoneInformation() (DynamicTimezoneInformation, error) {
|
||||||
var tzi DynamicTimezoneInformation
|
var tzi DynamicTimezoneInformation
|
||||||
|
|
||||||
r0, _, err := syscall.SyscallN(procGetDynamicTimeZoneInformationSys.Addr(), uintptr(unsafe.Pointer(&tzi)))
|
r0, _, err := procGetDynamicTimeZoneInformationSys.Call(uintptr(unsafe.Pointer(&tzi)))
|
||||||
if uint32(r0) == 0xffffffff {
|
if uint32(r0) == 0xffffffff {
|
||||||
return tzi, err
|
return tzi, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,16 +45,16 @@ var NetApiStatus = map[uint32]string{
|
|||||||
2351: "NERR_InvalidComputer",
|
2351: "NERR_InvalidComputer",
|
||||||
// This operation is only allowed on the primary domain controller of the domain.
|
// This operation is only allowed on the primary domain controller of the domain.
|
||||||
2226: "NERR_NotPrimary",
|
2226: "NERR_NotPrimary",
|
||||||
/// This operation is not allowed on this special group.
|
// This operation is not allowed on this special group.
|
||||||
2234: "NERR_SpeGroupOp",
|
2234: "NERR_SpeGroupOp",
|
||||||
/// This operation is not allowed on the last administrative account.
|
// This operation is not allowed on the last administrative account.
|
||||||
2452: "NERR_LastAdmin",
|
2452: "NERR_LastAdmin",
|
||||||
/// The password parameter is invalid.
|
// The password parameter is invalid.
|
||||||
2203: "NERR_BadPassword",
|
2203: "NERR_BadPassword",
|
||||||
/// The password does not meet the password policy requirements.
|
// The password does not meet the password policy requirements.
|
||||||
/// Check the minimum password length, password complexity and password history requirements.
|
// Check the minimum password length, password complexity and password history requirements.
|
||||||
2245: "NERR_PasswordTooShort",
|
2245: "NERR_PasswordTooShort",
|
||||||
/// The user name could not be found.
|
// The user name could not be found.
|
||||||
2221: "NERR_UserNotFound",
|
2221: "NERR_UserNotFound",
|
||||||
// Errors
|
// Errors
|
||||||
5: "ERROR_ACCESS_DENIED",
|
5: "ERROR_ACCESS_DENIED",
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ var (
|
|||||||
procSLIsWindowsGenuineLocal = slc.NewProc("SLIsWindowsGenuineLocal")
|
procSLIsWindowsGenuineLocal = slc.NewProc("SLIsWindowsGenuineLocal")
|
||||||
)
|
)
|
||||||
|
|
||||||
// Define SL_GENUINE_STATE enumeration
|
// SL_GENUINE_STATE enumeration
|
||||||
|
//
|
||||||
// https://learn.microsoft.com/en-us/windows/win32/api/slpublic/ne-slpublic-sl_genuine_state
|
// https://learn.microsoft.com/en-us/windows/win32/api/slpublic/ne-slpublic-sl_genuine_state
|
||||||
type SL_GENUINE_STATE uint32
|
type SL_GENUINE_STATE uint32
|
||||||
|
|
||||||
|
|||||||
@@ -3,24 +3,11 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"slices"
|
|
||||||
"sort"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/prometheus-community/windows_exporter/pkg/types"
|
"github.com/prometheus-community/windows_exporter/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ExpandEnabledChildCollectors used by more complex Collectors where user input specifies enabled child Collectors.
|
|
||||||
// Splits provided child Collectors and deduplicate.
|
|
||||||
func ExpandEnabledChildCollectors(enabled string) []string {
|
|
||||||
result := slices.Compact(strings.Split(enabled, ","))
|
|
||||||
|
|
||||||
// Result must order, to prevent test failures.
|
|
||||||
sort.Strings(result)
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
func ExpandEnabledCollectors(enabled string) []string {
|
func ExpandEnabledCollectors(enabled string) []string {
|
||||||
expanded := strings.ReplaceAll(enabled, types.DefaultCollectorsPlaceholder, types.DefaultCollectors)
|
expanded := strings.ReplaceAll(enabled, types.DefaultCollectorsPlaceholder, types.DefaultCollectors)
|
||||||
separated := strings.Split(expanded, ",")
|
separated := strings.Split(expanded, ",")
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package utils_test
|
package utils_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -10,38 +9,6 @@ import (
|
|||||||
"github.com/prometheus-community/windows_exporter/pkg/utils"
|
"github.com/prometheus-community/windows_exporter/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestExpandChildCollectors(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
cases := []struct {
|
|
||||||
name string
|
|
||||||
input string
|
|
||||||
expectedOutput []string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "simple",
|
|
||||||
input: "testing1,testing2,testing3",
|
|
||||||
expectedOutput: []string{"testing1", "testing2", "testing3"},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "duplicate",
|
|
||||||
input: "testing1,testing2,testing2,testing3",
|
|
||||||
expectedOutput: []string{"testing1", "testing2", "testing3"},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, c := range cases {
|
|
||||||
t.Run(c.name, func(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
output := utils.ExpandEnabledChildCollectors(c.input)
|
|
||||||
if !reflect.DeepEqual(output, c.expectedOutput) {
|
|
||||||
t.Errorf("Output mismatch, expected %+v, got %+v", c.expectedOutput, output)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestExpandEnabled(t *testing.T) {
|
func TestExpandEnabled(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|||||||
@@ -13,10 +13,6 @@ func BoolToFloat(b bool) float64 {
|
|||||||
return 0.0
|
return 0.0
|
||||||
}
|
}
|
||||||
|
|
||||||
func HasValue(v *string) bool {
|
|
||||||
return !IsEmpty(v)
|
|
||||||
}
|
|
||||||
|
|
||||||
func IsEmpty(v *string) bool {
|
func IsEmpty(v *string) bool {
|
||||||
return v == nil || *v == ""
|
return v == nil || *v == ""
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,43 +5,39 @@ package winversion
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"golang.org/x/sys/windows/registry"
|
"golang.org/x/sys/windows/registry"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var WindowsVersionFloat = sync.OnceValue[float64](func() float64 {
|
||||||
WindowsVersion string
|
version, err := getWindowsVersion()
|
||||||
WindowsVersionFloat float64
|
|
||||||
)
|
|
||||||
|
|
||||||
//nolint:gochecknoinits
|
|
||||||
func init() {
|
|
||||||
var err error
|
|
||||||
WindowsVersion, WindowsVersionFloat, err = GetWindowsVersion()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
return version
|
||||||
|
})
|
||||||
|
|
||||||
// GetWindowsVersion reads the version number of the OS from the Registry
|
// GetWindowsVersion reads the version number of the OS from the Registry
|
||||||
// See https://docs.microsoft.com/en-us/windows/desktop/sysinfo/operating-system-version
|
// See https://docs.microsoft.com/en-us/windows/desktop/sysinfo/operating-system-version
|
||||||
func GetWindowsVersion() (string, float64, error) {
|
func getWindowsVersion() (float64, error) {
|
||||||
reg, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.QUERY_VALUE)
|
reg, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.QUERY_VALUE)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", 0, fmt.Errorf("couldn't open registry: %w", err)
|
return 0, fmt.Errorf("couldn't open registry: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer reg.Close()
|
defer reg.Close()
|
||||||
|
|
||||||
windowsVersion, _, err := reg.GetStringValue("CurrentVersion")
|
windowsVersion, _, err := reg.GetStringValue("CurrentVersion")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", 0, fmt.Errorf("couldn't open registry: %w", err)
|
return 0, fmt.Errorf("couldn't open registry: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
windowsVersionFloat, err := strconv.ParseFloat(windowsVersion, 64)
|
windowsVersionFloat, err := strconv.ParseFloat(windowsVersion, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", 0, fmt.Errorf("couldn't open registry: %w", err)
|
return 0, fmt.Errorf("couldn't open registry: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return windowsVersion, windowsVersionFloat, nil
|
return windowsVersionFloat, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,92 +0,0 @@
|
|||||||
package wmi
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"reflect"
|
|
||||||
|
|
||||||
"github.com/go-kit/log"
|
|
||||||
"github.com/go-kit/log/level"
|
|
||||||
"github.com/yusufpapurcu/wmi"
|
|
||||||
)
|
|
||||||
|
|
||||||
func InitWbem(logger log.Logger) error {
|
|
||||||
// This initialization prevents a memory leak on WMF 5+. See
|
|
||||||
// https://github.com/prometheus-community/windows_exporter/issues/77 and
|
|
||||||
// linked issues for details.
|
|
||||||
_ = level.Debug(logger).Log("msg", "Initializing SWbemServices")
|
|
||||||
s, err := wmi.InitializeSWbemServices(wmi.DefaultClient)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
wmi.DefaultClient.AllowMissingFields = true
|
|
||||||
wmi.DefaultClient.SWbemServicesClient = s
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func className(src interface{}) string {
|
|
||||||
s := reflect.Indirect(reflect.ValueOf(src))
|
|
||||||
t := s.Type()
|
|
||||||
if s.Kind() == reflect.Slice {
|
|
||||||
t = t.Elem()
|
|
||||||
}
|
|
||||||
return t.Name()
|
|
||||||
}
|
|
||||||
|
|
||||||
func Query(query string, dst interface{}, connectServerArgs ...interface{}) error {
|
|
||||||
return wmi.Query(query, dst, connectServerArgs...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func QueryNamespace(query string, dst interface{}, namespace string) error {
|
|
||||||
return wmi.QueryNamespace(query, dst, namespace)
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryAll returns a query string that selects all fields from the given
|
|
||||||
// struct type.
|
|
||||||
// Deprecated: Use QueryAllForClass instead.
|
|
||||||
func QueryAll(src interface{}, logger log.Logger) string {
|
|
||||||
var b bytes.Buffer
|
|
||||||
b.WriteString("SELECT * FROM ")
|
|
||||||
b.WriteString(className(src))
|
|
||||||
|
|
||||||
_ = level.Debug(logger).Log("msg", "Generated WMI query "+b.String())
|
|
||||||
return b.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
func QueryAllForClass(_ interface{}, class string, logger log.Logger) string {
|
|
||||||
var b bytes.Buffer
|
|
||||||
b.WriteString("SELECT * FROM ")
|
|
||||||
b.WriteString(class)
|
|
||||||
|
|
||||||
_ = level.Debug(logger).Log("msg", "Generated WMI query "+b.String())
|
|
||||||
return b.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deprecated: Use QueryAllForClassWhere instead.
|
|
||||||
func QueryAllWhere(src interface{}, where string, logger log.Logger) string {
|
|
||||||
var b bytes.Buffer
|
|
||||||
b.WriteString("SELECT * FROM ")
|
|
||||||
b.WriteString(className(src))
|
|
||||||
|
|
||||||
if where != "" {
|
|
||||||
b.WriteString(" WHERE ")
|
|
||||||
b.WriteString(where)
|
|
||||||
}
|
|
||||||
|
|
||||||
_ = level.Debug(logger).Log("msg", "Generated WMI query "+b.String())
|
|
||||||
return b.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
func QueryAllForClassWhere(_ interface{}, class string, where string, logger log.Logger) string {
|
|
||||||
var b bytes.Buffer
|
|
||||||
b.WriteString("SELECT * FROM ")
|
|
||||||
b.WriteString(class)
|
|
||||||
|
|
||||||
if where != "" {
|
|
||||||
b.WriteString(" WHERE ")
|
|
||||||
b.WriteString(where)
|
|
||||||
}
|
|
||||||
|
|
||||||
_ = level.Debug(logger).Log("msg", "Generated WMI query "+b.String())
|
|
||||||
return b.String()
|
|
||||||
}
|
|
||||||
@@ -1,121 +0,0 @@
|
|||||||
package wmi
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/go-kit/log"
|
|
||||||
)
|
|
||||||
|
|
||||||
type fakeWmiClass struct {
|
|
||||||
Name string
|
|
||||||
SomeProperty int
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
mapQueryAll = func(src interface{}, _ string, _ string) string {
|
|
||||||
return QueryAll(src, log.NewNopLogger())
|
|
||||||
}
|
|
||||||
mapQueryAllWhere = func(src interface{}, _ string, where string) string {
|
|
||||||
return QueryAllWhere(src, where, log.NewNopLogger())
|
|
||||||
}
|
|
||||||
mapQueryAllForClass = func(src interface{}, class string, _ string) string {
|
|
||||||
return QueryAllForClass(src, class, log.NewNopLogger())
|
|
||||||
}
|
|
||||||
mapQueryAllForClassWhere = func(src interface{}, class string, where string) string {
|
|
||||||
return QueryAllForClassWhere(src, class, where, log.NewNopLogger())
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
type queryFunc func(src interface{}, class string, where string) string
|
|
||||||
|
|
||||||
func TestCreateQuery(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
cases := []struct {
|
|
||||||
desc string
|
|
||||||
dst interface{}
|
|
||||||
class string
|
|
||||||
where string
|
|
||||||
queryFunc queryFunc
|
|
||||||
expected string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
desc: "queryAll on single instance",
|
|
||||||
dst: fakeWmiClass{},
|
|
||||||
queryFunc: mapQueryAll,
|
|
||||||
expected: "SELECT * FROM fakeWmiClass",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
desc: "queryAll on slice",
|
|
||||||
dst: []fakeWmiClass{},
|
|
||||||
queryFunc: mapQueryAll,
|
|
||||||
expected: "SELECT * FROM fakeWmiClass",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
desc: "queryAllWhere on single instance",
|
|
||||||
dst: fakeWmiClass{},
|
|
||||||
where: "foo = bar",
|
|
||||||
queryFunc: mapQueryAllWhere,
|
|
||||||
expected: "SELECT * FROM fakeWmiClass WHERE foo = bar",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
desc: "queryAllWhere on slice",
|
|
||||||
dst: []fakeWmiClass{},
|
|
||||||
where: "foo = bar",
|
|
||||||
queryFunc: mapQueryAllWhere,
|
|
||||||
expected: "SELECT * FROM fakeWmiClass WHERE foo = bar",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
desc: "queryAllWhere on single instance with empty where",
|
|
||||||
dst: fakeWmiClass{},
|
|
||||||
queryFunc: mapQueryAllWhere,
|
|
||||||
expected: "SELECT * FROM fakeWmiClass",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
desc: "queryAllForClass on single instance",
|
|
||||||
dst: fakeWmiClass{},
|
|
||||||
class: "someClass",
|
|
||||||
queryFunc: mapQueryAllForClass,
|
|
||||||
expected: "SELECT * FROM someClass",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
desc: "queryAllForClass on slice",
|
|
||||||
dst: []fakeWmiClass{},
|
|
||||||
class: "someClass",
|
|
||||||
queryFunc: mapQueryAllForClass,
|
|
||||||
expected: "SELECT * FROM someClass",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
desc: "queryAllForClassWhere on single instance",
|
|
||||||
dst: fakeWmiClass{},
|
|
||||||
class: "someClass",
|
|
||||||
where: "foo = bar",
|
|
||||||
queryFunc: mapQueryAllForClassWhere,
|
|
||||||
expected: "SELECT * FROM someClass WHERE foo = bar",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
desc: "queryAllForClassWhere on slice",
|
|
||||||
dst: []fakeWmiClass{},
|
|
||||||
class: "someClass",
|
|
||||||
where: "foo = bar",
|
|
||||||
queryFunc: mapQueryAllForClassWhere,
|
|
||||||
expected: "SELECT * FROM someClass WHERE foo = bar",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
desc: "queryAllForClassWhere on single instance with empty where",
|
|
||||||
dst: fakeWmiClass{},
|
|
||||||
class: "someClass",
|
|
||||||
queryFunc: mapQueryAllForClassWhere,
|
|
||||||
expected: "SELECT * FROM someClass",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, c := range cases {
|
|
||||||
t.Run(c.desc, func(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
if q := c.queryFunc(c.dst, c.class, c.where); q != c.expected {
|
|
||||||
t.Errorf("Case %q failed: Expected %q, got %q", c.desc, c.expected, q)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user