mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-22 12:46:36 +00:00
Add flag to specify "where" in process WMI query
This flag can be used to limit the Win32_PerfRawData_PerfProc_Process response and pull metrics for only the desired processes.
This commit is contained in:
@@ -3,6 +3,8 @@
|
|||||||
package collector
|
package collector
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"flag"
|
||||||
"log"
|
"log"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
@@ -14,6 +16,10 @@ func init() {
|
|||||||
Factories["process"] = NewProcessCollector
|
Factories["process"] = NewProcessCollector
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
processWhereClause = flag.String("collector.process.processes-where", "", "WQL 'where' clause to use in WMI metrics query. Limits the response to the processes you specify and reduces the size of the response.")
|
||||||
|
)
|
||||||
|
|
||||||
// A ProcessCollector is a Prometheus collector for WMI Win32_PerfRawData_PerfProc_Process metrics
|
// A ProcessCollector is a Prometheus collector for WMI Win32_PerfRawData_PerfProc_Process metrics
|
||||||
type ProcessCollector struct {
|
type ProcessCollector struct {
|
||||||
StartTime *prometheus.Desc
|
StartTime *prometheus.Desc
|
||||||
@@ -29,6 +35,8 @@ type ProcessCollector struct {
|
|||||||
ThreadCount *prometheus.Desc
|
ThreadCount *prometheus.Desc
|
||||||
VirtualBytes *prometheus.Desc
|
VirtualBytes *prometheus.Desc
|
||||||
WorkingSet *prometheus.Desc
|
WorkingSet *prometheus.Desc
|
||||||
|
|
||||||
|
queryWhereClause string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewProcessCollector ...
|
// NewProcessCollector ...
|
||||||
@@ -113,6 +121,7 @@ func NewProcessCollector() (Collector, error) {
|
|||||||
[]string{"process", "process_id", "creating_process_id"},
|
[]string{"process", "process_id", "creating_process_id"},
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
|
queryWhereClause: *processWhereClause,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,7 +171,16 @@ type Win32_PerfRawData_PerfProc_Process struct {
|
|||||||
|
|
||||||
func (c *ProcessCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *ProcessCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []Win32_PerfRawData_PerfProc_Process
|
var dst []Win32_PerfRawData_PerfProc_Process
|
||||||
q := wmi.CreateQuery(&dst, "")
|
|
||||||
|
var wc bytes.Buffer
|
||||||
|
|
||||||
|
if c.queryWhereClause != "" {
|
||||||
|
wc.WriteString("WHERE ")
|
||||||
|
wc.WriteString(c.queryWhereClause)
|
||||||
|
}
|
||||||
|
|
||||||
|
q := wmi.CreateQuery(&dst, wc.String())
|
||||||
|
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err := wmi.Query(q, &dst); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user