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.
This commit is contained in:
Steve Zook 2018-07-20 11:05:04 -04:00
parent 21e0f926a3
commit e8ffb736d0

View File

@ -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,