mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-08 05:56:37 +00:00
process: do not fail, if collector.process.iis is enabled and WMI WebAdministration is not present. (#2082)
This commit is contained in:
@@ -180,20 +180,6 @@ func (c *Collector) Build(logger *slog.Logger, miSession *mi.Session) error {
|
||||
|
||||
var err error
|
||||
|
||||
if c.config.EnableWorkerProcess {
|
||||
if miSession == nil {
|
||||
return errors.New("miSession is nil")
|
||||
}
|
||||
|
||||
miQuery, err := mi.NewQuery("SELECT AppPoolName, ProcessId FROM WorkerProcess")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create WMI query: %w", err)
|
||||
}
|
||||
|
||||
c.workerProcessMIQueryQuery = miQuery
|
||||
c.miSession = miSession
|
||||
}
|
||||
|
||||
switch c.config.CounterVersion {
|
||||
case 2:
|
||||
c.perfDataCollector, err = pdh.NewCollector[perfDataCounterValues](pdh.CounterTypeRaw, "Process V2", pdh.InstancesAll)
|
||||
@@ -333,6 +319,28 @@ func (c *Collector) Build(logger *slog.Logger, miSession *mi.Session) error {
|
||||
nil,
|
||||
)
|
||||
|
||||
if c.config.EnableWorkerProcess {
|
||||
if miSession == nil {
|
||||
return errors.New("miSession is nil")
|
||||
}
|
||||
|
||||
miQuery, err := mi.NewQuery("SELECT AppPoolName, ProcessId FROM WorkerProcess")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create WMI query: %w", err)
|
||||
}
|
||||
|
||||
c.workerProcessMIQueryQuery = miQuery
|
||||
c.miSession = miSession
|
||||
|
||||
var workerProcesses []WorkerProcess
|
||||
|
||||
if err = c.miSession.Query(&workerProcesses, mi.NamespaceRootWebAdministration, c.workerProcessMIQueryQuery); err != nil {
|
||||
c.config.EnableWorkerProcess = false
|
||||
|
||||
return fmt.Errorf("WMI query for collector.process.iis failed: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -45,10 +45,12 @@ func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||
return fmt.Errorf("failed to collect metrics: %w", err)
|
||||
}
|
||||
|
||||
err = nil
|
||||
|
||||
var workerProcesses []WorkerProcess
|
||||
if c.config.EnableWorkerProcess {
|
||||
if err := c.miSession.Query(&workerProcesses, mi.NamespaceRootWebAdministration, c.workerProcessMIQueryQuery); err != nil {
|
||||
return fmt.Errorf("WMI query failed: %w", err)
|
||||
if err = c.miSession.Query(&workerProcesses, mi.NamespaceRootWebAdministration, c.workerProcessMIQueryQuery); err != nil {
|
||||
err = fmt.Errorf("WMI query for collector.process.iis failed: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +90,7 @@ func (c *Collector) collect(ch chan<- prometheus.Metric) error {
|
||||
|
||||
wg.Wait()
|
||||
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Collector) collectWorker() {
|
||||
|
||||
@@ -27,7 +27,6 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus-community/windows_exporter/internal/mi"
|
||||
"github.com/prometheus-community/windows_exporter/internal/pdh"
|
||||
"github.com/prometheus-community/windows_exporter/internal/types"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
@@ -215,7 +214,7 @@ func (c *Collection) collectCollector(ch chan<- prometheus.Metric, logger *slog.
|
||||
|
||||
if err != nil {
|
||||
if !errors.Is(err, pdh.ErrNoData) && !errors.Is(err, types.ErrNoData) && !errors.Is(err, windows.EPT_S_NOT_REGISTERED) {
|
||||
if errors.Is(err, pdh.ErrPerformanceCounterNotInitialized) || errors.Is(err, mi.MI_RESULT_INVALID_NAMESPACE) {
|
||||
if errors.Is(err, pdh.ErrPerformanceCounterNotInitialized) {
|
||||
err = fmt.Errorf("%w. Check application logs from initialization pharse for more information", err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user