mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-03-02 00:26:35 +00:00
Remove process index from name label, add README
This commit is contained in:
@@ -16,6 +16,7 @@ iis | [Win32_PerfRawData_W3SVC_WebService](https://msdn.microsoft.com/en-us/libr
|
|||||||
logical_disk | [Win32_PerfRawData_PerfDisk_LogicalDisk](https://msdn.microsoft.com/en-us/windows/hardware/aa394307(v=vs.71)) metrics (disk I/O) | ✓
|
logical_disk | [Win32_PerfRawData_PerfDisk_LogicalDisk](https://msdn.microsoft.com/en-us/windows/hardware/aa394307(v=vs.71)) metrics (disk I/O) | ✓
|
||||||
net | [Win32_PerfRawData_Tcpip_NetworkInterface](https://technet.microsoft.com/en-us/security/aa394340(v=vs.80)) metrics (network interface I/O) | ✓
|
net | [Win32_PerfRawData_Tcpip_NetworkInterface](https://technet.microsoft.com/en-us/security/aa394340(v=vs.80)) metrics (network interface I/O) | ✓
|
||||||
os | [Win32_OperatingSystem](https://msdn.microsoft.com/en-us/library/aa394239) metrics (memory, processes, users) | ✓
|
os | [Win32_OperatingSystem](https://msdn.microsoft.com/en-us/library/aa394239) metrics (memory, processes, users) | ✓
|
||||||
|
process | [Win32_PerfRawData_PerfProc_Process](https://msdn.microsoft.com/en-us/library/aa394323(v=vs.85).aspx) metrics (per-process stats) |
|
||||||
service | [Win32_Service](https://msdn.microsoft.com/en-us/library/aa394418(v=vs.85).aspx) metrics (service states) | ✓
|
service | [Win32_Service](https://msdn.microsoft.com/en-us/library/aa394418(v=vs.85).aspx) metrics (service states) | ✓
|
||||||
system | Win32_PerfRawData_PerfOS_System metrics (system calls) | ✓
|
system | Win32_PerfRawData_PerfOS_System metrics (system calls) | ✓
|
||||||
|
|
||||||
|
|||||||
@@ -5,11 +5,12 @@ package collector
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"flag"
|
"flag"
|
||||||
"log"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/StackExchange/wmi"
|
"github.com/StackExchange/wmi"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/prometheus/common/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -22,26 +23,35 @@ var (
|
|||||||
|
|
||||||
// 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
|
||||||
CPUTimeTotal *prometheus.Desc
|
CPUTimeTotal *prometheus.Desc
|
||||||
HandleCount *prometheus.Desc
|
HandleCount *prometheus.Desc
|
||||||
IOBytesTotal *prometheus.Desc
|
IOBytesTotal *prometheus.Desc
|
||||||
IOOperationsTotal *prometheus.Desc
|
IOOperationsTotal *prometheus.Desc
|
||||||
PageFaultsTotal *prometheus.Desc
|
PageFaultsTotal *prometheus.Desc
|
||||||
PageFileBytes *prometheus.Desc
|
PageFileBytes *prometheus.Desc
|
||||||
PoolBytes *prometheus.Desc
|
PoolBytes *prometheus.Desc
|
||||||
PriorityBase *prometheus.Desc
|
PriorityBase *prometheus.Desc
|
||||||
PrivateBytes *prometheus.Desc
|
PrivateBytes *prometheus.Desc
|
||||||
ThreadCount *prometheus.Desc
|
ThreadCount *prometheus.Desc
|
||||||
VirtualBytes *prometheus.Desc
|
VirtualBytes *prometheus.Desc
|
||||||
WorkingSet *prometheus.Desc
|
WorkingSet *prometheus.Desc
|
||||||
|
|
||||||
queryWhereClause string
|
queryWhereClause string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewProcessCollector ...
|
// NewProcessCollector ...
|
||||||
func NewProcessCollector() (Collector, error) {
|
func NewProcessCollector() (Collector, error) {
|
||||||
const subsystem = "process"
|
const subsystem = "process"
|
||||||
|
|
||||||
|
var wc bytes.Buffer
|
||||||
|
if *processWhereClause != "" {
|
||||||
|
wc.WriteString("WHERE ")
|
||||||
|
wc.WriteString(*processWhereClause)
|
||||||
|
} else {
|
||||||
|
log.Warn("No where-clause specified for process collector. This will generate a very large number of metrics!")
|
||||||
|
}
|
||||||
|
|
||||||
return &ProcessCollector{
|
return &ProcessCollector{
|
||||||
StartTime: prometheus.NewDesc(
|
StartTime: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(Namespace, subsystem, "start_time"),
|
prometheus.BuildFQName(Namespace, subsystem, "start_time"),
|
||||||
@@ -121,7 +131,7 @@ func NewProcessCollector() (Collector, error) {
|
|||||||
[]string{"process", "process_id", "creating_process_id"},
|
[]string{"process", "process_id", "creating_process_id"},
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
queryWhereClause: *processWhereClause,
|
queryWhereClause: wc.String(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,7 +139,7 @@ func NewProcessCollector() (Collector, error) {
|
|||||||
// to the provided prometheus Metric channel.
|
// to the provided prometheus Metric channel.
|
||||||
func (c *ProcessCollector) Collect(ch chan<- prometheus.Metric) error {
|
func (c *ProcessCollector) Collect(ch chan<- prometheus.Metric) error {
|
||||||
if desc, err := c.collect(ch); err != nil {
|
if desc, err := c.collect(ch); err != nil {
|
||||||
log.Println("[ERROR] failed collecting process metrics:", desc, err)
|
log.Errorln("[ERROR] failed collecting process metrics:", desc, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -171,16 +181,7 @@ 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, c.queryWhereClause)
|
||||||
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
|
||||||
}
|
}
|
||||||
@@ -190,7 +191,8 @@ func (c *ProcessCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Des
|
|||||||
if process.Name == "_Total" {
|
if process.Name == "_Total" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
// Duplicate processes are suffixed # and an index number. Remove those.
|
||||||
|
processName := strings.Split(process.Name, "#")[0]
|
||||||
pid := strconv.FormatUint(uint64(process.IDProcess), 10)
|
pid := strconv.FormatUint(uint64(process.IDProcess), 10)
|
||||||
cpid := strconv.FormatUint(uint64(process.CreatingProcessID), 10)
|
cpid := strconv.FormatUint(uint64(process.CreatingProcessID), 10)
|
||||||
|
|
||||||
@@ -199,7 +201,7 @@ func (c *ProcessCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Des
|
|||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
// convert from Windows timestamp (1 jan 1601) to unix timestamp (1 jan 1970)
|
// convert from Windows timestamp (1 jan 1601) to unix timestamp (1 jan 1970)
|
||||||
float64(process.ElapsedTime-116444736000000000)/float64(process.Frequency_Object),
|
float64(process.ElapsedTime-116444736000000000)/float64(process.Frequency_Object),
|
||||||
process.Name,
|
processName,
|
||||||
pid,
|
pid,
|
||||||
cpid,
|
cpid,
|
||||||
)
|
)
|
||||||
@@ -208,7 +210,7 @@ func (c *ProcessCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Des
|
|||||||
c.HandleCount,
|
c.HandleCount,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(process.HandleCount),
|
float64(process.HandleCount),
|
||||||
process.Name,
|
processName,
|
||||||
pid,
|
pid,
|
||||||
cpid,
|
cpid,
|
||||||
)
|
)
|
||||||
@@ -217,7 +219,7 @@ func (c *ProcessCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Des
|
|||||||
c.CPUTimeTotal,
|
c.CPUTimeTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(process.PercentPrivilegedTime)*ticksToSecondsScaleFactor,
|
float64(process.PercentPrivilegedTime)*ticksToSecondsScaleFactor,
|
||||||
process.Name,
|
processName,
|
||||||
pid,
|
pid,
|
||||||
cpid,
|
cpid,
|
||||||
"privileged",
|
"privileged",
|
||||||
@@ -227,7 +229,7 @@ func (c *ProcessCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Des
|
|||||||
c.CPUTimeTotal,
|
c.CPUTimeTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(process.PercentUserTime)*ticksToSecondsScaleFactor,
|
float64(process.PercentUserTime)*ticksToSecondsScaleFactor,
|
||||||
process.Name,
|
processName,
|
||||||
pid,
|
pid,
|
||||||
cpid,
|
cpid,
|
||||||
"user",
|
"user",
|
||||||
@@ -237,7 +239,7 @@ func (c *ProcessCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Des
|
|||||||
c.IOBytesTotal,
|
c.IOBytesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(process.IOOtherBytesPersec),
|
float64(process.IOOtherBytesPersec),
|
||||||
process.Name,
|
processName,
|
||||||
pid,
|
pid,
|
||||||
cpid,
|
cpid,
|
||||||
"other",
|
"other",
|
||||||
@@ -247,7 +249,7 @@ func (c *ProcessCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Des
|
|||||||
c.IOOperationsTotal,
|
c.IOOperationsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(process.IOOtherOperationsPersec),
|
float64(process.IOOtherOperationsPersec),
|
||||||
process.Name,
|
processName,
|
||||||
pid,
|
pid,
|
||||||
cpid,
|
cpid,
|
||||||
"other",
|
"other",
|
||||||
@@ -257,7 +259,7 @@ func (c *ProcessCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Des
|
|||||||
c.IOBytesTotal,
|
c.IOBytesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(process.IOReadBytesPersec),
|
float64(process.IOReadBytesPersec),
|
||||||
process.Name,
|
processName,
|
||||||
pid,
|
pid,
|
||||||
cpid,
|
cpid,
|
||||||
"read",
|
"read",
|
||||||
@@ -267,7 +269,7 @@ func (c *ProcessCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Des
|
|||||||
c.IOOperationsTotal,
|
c.IOOperationsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(process.IOReadOperationsPersec),
|
float64(process.IOReadOperationsPersec),
|
||||||
process.Name,
|
processName,
|
||||||
pid,
|
pid,
|
||||||
cpid,
|
cpid,
|
||||||
"read",
|
"read",
|
||||||
@@ -277,7 +279,7 @@ func (c *ProcessCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Des
|
|||||||
c.IOBytesTotal,
|
c.IOBytesTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(process.IOWriteBytesPersec),
|
float64(process.IOWriteBytesPersec),
|
||||||
process.Name,
|
processName,
|
||||||
pid,
|
pid,
|
||||||
cpid,
|
cpid,
|
||||||
"write",
|
"write",
|
||||||
@@ -287,7 +289,7 @@ func (c *ProcessCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Des
|
|||||||
c.IOOperationsTotal,
|
c.IOOperationsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(process.IOWriteOperationsPersec),
|
float64(process.IOWriteOperationsPersec),
|
||||||
process.Name,
|
processName,
|
||||||
pid,
|
pid,
|
||||||
cpid,
|
cpid,
|
||||||
"write",
|
"write",
|
||||||
@@ -297,7 +299,7 @@ func (c *ProcessCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Des
|
|||||||
c.PageFaultsTotal,
|
c.PageFaultsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(process.PageFaultsPersec),
|
float64(process.PageFaultsPersec),
|
||||||
process.Name,
|
processName,
|
||||||
pid,
|
pid,
|
||||||
cpid,
|
cpid,
|
||||||
)
|
)
|
||||||
@@ -306,7 +308,7 @@ func (c *ProcessCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Des
|
|||||||
c.PageFileBytes,
|
c.PageFileBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(process.PageFileBytes),
|
float64(process.PageFileBytes),
|
||||||
process.Name,
|
processName,
|
||||||
pid,
|
pid,
|
||||||
cpid,
|
cpid,
|
||||||
)
|
)
|
||||||
@@ -315,7 +317,7 @@ func (c *ProcessCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Des
|
|||||||
c.PoolBytes,
|
c.PoolBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(process.PoolNonpagedBytes),
|
float64(process.PoolNonpagedBytes),
|
||||||
process.Name,
|
processName,
|
||||||
pid,
|
pid,
|
||||||
cpid,
|
cpid,
|
||||||
"nonpaged",
|
"nonpaged",
|
||||||
@@ -325,7 +327,7 @@ func (c *ProcessCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Des
|
|||||||
c.PoolBytes,
|
c.PoolBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(process.PoolPagedBytes),
|
float64(process.PoolPagedBytes),
|
||||||
process.Name,
|
processName,
|
||||||
pid,
|
pid,
|
||||||
cpid,
|
cpid,
|
||||||
"paged",
|
"paged",
|
||||||
@@ -335,7 +337,7 @@ func (c *ProcessCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Des
|
|||||||
c.PriorityBase,
|
c.PriorityBase,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(process.PriorityBase),
|
float64(process.PriorityBase),
|
||||||
process.Name,
|
processName,
|
||||||
pid,
|
pid,
|
||||||
cpid,
|
cpid,
|
||||||
)
|
)
|
||||||
@@ -344,7 +346,7 @@ func (c *ProcessCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Des
|
|||||||
c.PrivateBytes,
|
c.PrivateBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(process.PrivateBytes),
|
float64(process.PrivateBytes),
|
||||||
process.Name,
|
processName,
|
||||||
pid,
|
pid,
|
||||||
cpid,
|
cpid,
|
||||||
)
|
)
|
||||||
@@ -353,7 +355,7 @@ func (c *ProcessCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Des
|
|||||||
c.ThreadCount,
|
c.ThreadCount,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(process.ThreadCount),
|
float64(process.ThreadCount),
|
||||||
process.Name,
|
processName,
|
||||||
pid,
|
pid,
|
||||||
cpid,
|
cpid,
|
||||||
)
|
)
|
||||||
@@ -362,7 +364,7 @@ func (c *ProcessCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Des
|
|||||||
c.VirtualBytes,
|
c.VirtualBytes,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(process.VirtualBytes),
|
float64(process.VirtualBytes),
|
||||||
process.Name,
|
processName,
|
||||||
pid,
|
pid,
|
||||||
cpid,
|
cpid,
|
||||||
)
|
)
|
||||||
@@ -371,7 +373,7 @@ func (c *ProcessCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Des
|
|||||||
c.WorkingSet,
|
c.WorkingSet,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(process.WorkingSet),
|
float64(process.WorkingSet),
|
||||||
process.Name,
|
processName,
|
||||||
pid,
|
pid,
|
||||||
cpid,
|
cpid,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user