mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-03-11 04:56:35 +00:00
Added flag to filter services (like the one for processes). Added example for said flag in README.md (#109)
This commit is contained in:
committed by
Martin Lindhe
parent
96faedf481
commit
44c39405c7
@@ -60,6 +60,14 @@ See [open issues](https://github.com/martinlindhe/wmi_exporter/issues)
|
|||||||
|
|
||||||
The prometheus metrics will be exposed on [localhost:9182](http://localhost:9182)
|
The prometheus metrics will be exposed on [localhost:9182](http://localhost:9182)
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
Please note: The quotes in the parameter names are required because of how Powershell parses command line arguments.
|
||||||
|
|
||||||
|
### Enable only service collector and specify a custom query
|
||||||
|
|
||||||
|
.\wmi_exporter.exe "-collectors.enabled" "service" "-collector.service.services-where" "Name='wmi_exporter'"
|
||||||
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
package collector
|
package collector
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"flag"
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -14,15 +16,30 @@ func init() {
|
|||||||
Factories["service"] = NewserviceCollector
|
Factories["service"] = NewserviceCollector
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
serviceWhereClause = flag.String("collector.service.services-where", "", "WQL 'where' clause to use in WMI metrics query. Limits the response to the services you specify and reduces the size of the response.")
|
||||||
|
)
|
||||||
|
|
||||||
// A serviceCollector is a Prometheus collector for WMI Win32_Service metrics
|
// A serviceCollector is a Prometheus collector for WMI Win32_Service metrics
|
||||||
type serviceCollector struct {
|
type serviceCollector struct {
|
||||||
State *prometheus.Desc
|
State *prometheus.Desc
|
||||||
StartMode *prometheus.Desc
|
StartMode *prometheus.Desc
|
||||||
|
|
||||||
|
queryWhereClause string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewserviceCollector ...
|
// NewserviceCollector ...
|
||||||
func NewserviceCollector() (Collector, error) {
|
func NewserviceCollector() (Collector, error) {
|
||||||
const subsystem = "service"
|
const subsystem = "service"
|
||||||
|
|
||||||
|
var wc bytes.Buffer
|
||||||
|
if *serviceWhereClause != "" {
|
||||||
|
wc.WriteString("WHERE ")
|
||||||
|
wc.WriteString(*serviceWhereClause)
|
||||||
|
} else {
|
||||||
|
log.Println("warning: No where-clause specified for process collector. This will generate a very large number of metrics!")
|
||||||
|
}
|
||||||
|
|
||||||
return &serviceCollector{
|
return &serviceCollector{
|
||||||
State: prometheus.NewDesc(
|
State: prometheus.NewDesc(
|
||||||
prometheus.BuildFQName(Namespace, subsystem, "state"),
|
prometheus.BuildFQName(Namespace, subsystem, "state"),
|
||||||
@@ -36,6 +53,7 @@ func NewserviceCollector() (Collector, error) {
|
|||||||
[]string{"name", "start_mode"},
|
[]string{"name", "start_mode"},
|
||||||
nil,
|
nil,
|
||||||
),
|
),
|
||||||
|
queryWhereClause: wc.String(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,7 +95,7 @@ var (
|
|||||||
|
|
||||||
func (c *serviceCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
func (c *serviceCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
|
||||||
var dst []Win32_Service
|
var dst []Win32_Service
|
||||||
q := wmi.CreateQuery(&dst, "")
|
q := wmi.CreateQuery(&dst, c.queryWhereClause)
|
||||||
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