From e8ffb736d00513fa40703f4408f801ef9da34094 Mon Sep 17 00:00:00 2001 From: Steve Zook Date: Fri, 20 Jul 2018 11:05:04 -0400 Subject: [PATCH] add worker process name to w3wp processes modify the `process` collector so that the IIS worker process name is appended to the corresponding `w3wp` process. before: ``` wmi_process_private_bytes{creating_process_id="2068",process="w3wp",process_id="12308"} 7.18204928e+08 ``` after: ``` wmi_process_private_bytes{creating_process_id="2068",process="w3wp_our.website.com",process_id="12308"} 7.18204928e+08 ``` reason: We have some IIS servers hosting many .NET applications. When there is resource contention on one of those servers, it's nice to know which IIS application pool is the culprit. Having only the process_id to differentiate between w3wp processes requires additional work to figure out which is which. Also it does not allow for historial trending as the process_id can change across restarts. --- collector/process.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/collector/process.go b/collector/process.go index f3bc2b04..20c7ce52 100644 --- a/collector/process.go +++ b/collector/process.go @@ -177,6 +177,11 @@ type Win32_PerfRawData_PerfProc_Process struct { WorkingSetPrivate uint64 } +type WorkerProcess struct { + AppPoolName string + ProcessId uint32 +} + func (c *ProcessCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) { var dst []Win32_PerfRawData_PerfProc_Process q := queryAllWhere(&dst, c.queryWhereClause) @@ -184,6 +189,10 @@ func (c *ProcessCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Des return nil, err } + var dst_wp []WorkerProcess + q_wp := queryAll(&dst_wp) + wmi.QueryNamespace(q_wp, &dst_wp, "root\\WebAdministration") + for _, process := range dst { if process.Name == "_Total" { @@ -194,6 +203,13 @@ func (c *ProcessCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Des pid := strconv.FormatUint(uint64(process.IDProcess), 10) cpid := strconv.FormatUint(uint64(process.CreatingProcessID), 10) + for _, wp := range dst_wp { + if wp.ProcessId == process.IDProcess { + processName = strings.Join([]string{processName, wp.AppPoolName}, "_") + break + } + } + ch <- prometheus.MustNewConstMetric( c.StartTime, prometheus.GaugeValue,