From 6832fd7fd7642056ffdf892c1c20bacf25a72b91 Mon Sep 17 00:00:00 2001 From: Ben Reedy Date: Sun, 29 May 2022 11:00:37 +1000 Subject: [PATCH] feat!: Disable IIS queries in `process` collector IIS queries are disabled by default, and can be enabled with the `--collector.process.iis=true` flag. These WMI queries are suspected to be one source of virtual memory leaks in the exporter. These WMI queries are also responsible for timeouts on some hosts. Signed-off-by: Ben Reedy --- collector/process.go | 25 ++++++++++++++++++------- docs/collector.process.md | 7 +++++++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/collector/process.go b/collector/process.go index 7ce5f23d..2fb2846d 100644 --- a/collector/process.go +++ b/collector/process.go @@ -34,6 +34,8 @@ var ( processIncludeSet bool processExcludeSet bool + + enableWorkerProcess *bool ) type processCollector struct { @@ -77,6 +79,11 @@ func newProcessCollectorFlags(app *kingpin.Application) { return nil }).String() + enableWorkerProcess = kingpin.Flag( + "collector.process.iis", + "Enable IIS worker process name queries. May cause the collector to leak memory.", + ).Default("false").Bool() + processOldInclude = app.Flag( FlagProcessOldInclude, "DEPRECATED: Use --collector.process.include", @@ -255,9 +262,11 @@ func (c *processCollector) Collect(ctx *ScrapeContext, ch chan<- prometheus.Metr } var dst_wp []WorkerProcess - q_wp := queryAll(&dst_wp, c.logger) - if err := wmi.QueryNamespace(q_wp, &dst_wp, "root\\WebAdministration"); err != nil { - _ = level.Debug(c.logger).Log("msg", fmt.Sprintf("Could not query WebAdministration namespace for IIS worker processes: %v. Skipping", err)) + if *enableWorkerProcess { + q_wp := queryAll(&dst_wp, c.logger) + if err := wmi.QueryNamespace(q_wp, &dst_wp, "root\\WebAdministration"); err != nil { + _ = level.Debug(c.logger).Log(fmt.Sprintf("Could not query WebAdministration namespace for IIS worker processes: %v. Skipping\n", err)) + } } for _, process := range data { @@ -271,10 +280,12 @@ func (c *processCollector) Collect(ctx *ScrapeContext, ch chan<- prometheus.Metr pid := strconv.FormatUint(uint64(process.IDProcess), 10) cpid := strconv.FormatUint(uint64(process.CreatingProcessID), 10) - for _, wp := range dst_wp { - if wp.ProcessId == uint64(process.IDProcess) { - processName = strings.Join([]string{processName, wp.AppPoolName}, "_") - break + if *enableWorkerProcess { + for _, wp := range dst_wp { + if wp.ProcessId == uint64(process.IDProcess) { + processName = strings.Join([]string{processName, wp.AppPoolName}, "_") + break + } } } diff --git a/docs/collector.process.md b/docs/collector.process.md index fc970482..51109d9a 100644 --- a/docs/collector.process.md +++ b/docs/collector.process.md @@ -11,6 +11,7 @@ Enabled by default? | No ## Flags +<<<<<<< HEAD ### `--collector.process.include` Regexp of processes to include. Process name must both match `include` and not @@ -23,6 +24,12 @@ Regexp of processes to exclude. Process name must both match `include` and not match `exclude` to be included. Recommended to keep down number of returned metrics. +### `--collector.process.iis` + +Enables IIS process name queries. IIS process names are combined with their app pool name to form the `process` label. + +Disabled by default, and can be enabled with `--collector.process.iis=true`. + ### Example To match all firefox processes: `--collector.process.include="firefox.*"`. Note that multiple processes with the same name will be disambiguated by