mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-18 02:36:36 +00:00
Rename misc variables wmi->windows
This commit is contained in:
40
exporter.go
40
exporter.go
@@ -23,8 +23,7 @@ import (
|
|||||||
"gopkg.in/alecthomas/kingpin.v2"
|
"gopkg.in/alecthomas/kingpin.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// WmiCollector implements the prometheus.Collector interface.
|
type windowsCollector struct {
|
||||||
type WmiCollector struct {
|
|
||||||
maxScrapeDuration time.Duration
|
maxScrapeDuration time.Duration
|
||||||
collectors map[string]collector.Collector
|
collectors map[string]collector.Collector
|
||||||
}
|
}
|
||||||
@@ -32,7 +31,7 @@ type WmiCollector struct {
|
|||||||
const (
|
const (
|
||||||
defaultCollectors = "cpu,cs,logical_disk,net,os,service,system,textfile"
|
defaultCollectors = "cpu,cs,logical_disk,net,os,service,system,textfile"
|
||||||
defaultCollectorsPlaceholder = "[defaults]"
|
defaultCollectorsPlaceholder = "[defaults]"
|
||||||
serviceName = "wmi_exporter"
|
serviceName = "windows_exporter"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -74,7 +73,7 @@ var (
|
|||||||
|
|
||||||
// Describe sends all the descriptors of the collectors included to
|
// Describe sends all the descriptors of the collectors included to
|
||||||
// the provided channel.
|
// the provided channel.
|
||||||
func (coll WmiCollector) Describe(ch chan<- *prometheus.Desc) {
|
func (coll windowsCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||||
ch <- scrapeDurationDesc
|
ch <- scrapeDurationDesc
|
||||||
ch <- scrapeSuccessDesc
|
ch <- scrapeSuccessDesc
|
||||||
}
|
}
|
||||||
@@ -89,7 +88,7 @@ const (
|
|||||||
|
|
||||||
// Collect sends the collected metrics from each of the collectors to
|
// Collect sends the collected metrics from each of the collectors to
|
||||||
// prometheus.
|
// prometheus.
|
||||||
func (coll WmiCollector) Collect(ch chan<- prometheus.Metric) {
|
func (coll windowsCollector) Collect(ch chan<- prometheus.Metric) {
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
startTimeDesc,
|
startTimeDesc,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
@@ -244,8 +243,8 @@ func loadCollectors(list string) (map[string]collector.Collector, error) {
|
|||||||
|
|
||||||
func initWbem() {
|
func initWbem() {
|
||||||
// This initialization prevents a memory leak on WMF 5+. See
|
// This initialization prevents a memory leak on WMF 5+. See
|
||||||
// https://github.com/martinlindhe/wmi_exporter/issues/77 and linked issues
|
// https://github.com/prometheus-community/windows_exporter/issues/77 and
|
||||||
// for details.
|
// linked issues for details.
|
||||||
log.Debugf("Initializing SWbemServices")
|
log.Debugf("Initializing SWbemServices")
|
||||||
s, err := wmi.InitializeSWbemServices(wmi.DefaultClient)
|
s, err := wmi.InitializeSWbemServices(wmi.DefaultClient)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -259,7 +258,7 @@ func main() {
|
|||||||
var (
|
var (
|
||||||
listenAddress = kingpin.Flag(
|
listenAddress = kingpin.Flag(
|
||||||
"telemetry.addr",
|
"telemetry.addr",
|
||||||
"host:port for WMI exporter.",
|
"host:port for exporter.",
|
||||||
).Default(":9182").String()
|
).Default(":9182").String()
|
||||||
metricsPath = kingpin.Flag(
|
metricsPath = kingpin.Flag(
|
||||||
"telemetry.path",
|
"telemetry.path",
|
||||||
@@ -284,7 +283,7 @@ func main() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
log.AddFlags(kingpin.CommandLine)
|
log.AddFlags(kingpin.CommandLine)
|
||||||
kingpin.Version(version.Print("wmi_exporter"))
|
kingpin.Version(version.Print("windows_exporter"))
|
||||||
kingpin.HelpFlag.Short('h')
|
kingpin.HelpFlag.Short('h')
|
||||||
kingpin.Parse()
|
kingpin.Parse()
|
||||||
|
|
||||||
@@ -312,7 +311,7 @@ func main() {
|
|||||||
stopCh := make(chan bool)
|
stopCh := make(chan bool)
|
||||||
if !isInteractive {
|
if !isInteractive {
|
||||||
go func() {
|
go func() {
|
||||||
err = svc.Run(serviceName, &wmiExporterService{stopCh: stopCh})
|
err = svc.Run(serviceName, &windowsExporterService{stopCh: stopCh})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Failed to start service: %v", err)
|
log.Errorf("Failed to start service: %v", err)
|
||||||
}
|
}
|
||||||
@@ -328,8 +327,8 @@ func main() {
|
|||||||
|
|
||||||
h := &metricsHandler{
|
h := &metricsHandler{
|
||||||
timeoutMargin: *timeoutMargin,
|
timeoutMargin: *timeoutMargin,
|
||||||
collectorFactory: func(timeout time.Duration) *WmiCollector {
|
collectorFactory: func(timeout time.Duration) *windowsCollector {
|
||||||
return &WmiCollector{
|
return &windowsCollector{
|
||||||
collectors: collectors,
|
collectors: collectors,
|
||||||
maxScrapeDuration: timeout,
|
maxScrapeDuration: timeout,
|
||||||
}
|
}
|
||||||
@@ -340,25 +339,26 @@ func main() {
|
|||||||
http.HandleFunc("/health", healthCheck)
|
http.HandleFunc("/health", healthCheck)
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
_, _ = w.Write([]byte(`<html>
|
_, _ = w.Write([]byte(`<html>
|
||||||
<head><title>WMI Exporter</title></head>
|
<head><title>windows_exporter</title></head>
|
||||||
<body>
|
<body>
|
||||||
<h1>WMI Exporter</h1>
|
<h1>windows_exporter</h1>
|
||||||
<p><a href="` + *metricsPath + `">Metrics</a></p>
|
<p><a href="` + *metricsPath + `">Metrics</a></p>
|
||||||
|
<p><i>` + version.Info() + `</i></p>
|
||||||
</body>
|
</body>
|
||||||
</html>`))
|
</html>`))
|
||||||
})
|
})
|
||||||
|
|
||||||
log.Infoln("Starting WMI exporter", version.Info())
|
log.Infoln("Starting windows_exporter", version.Info())
|
||||||
log.Infoln("Build context", version.BuildContext())
|
log.Infoln("Build context", version.BuildContext())
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
log.Infoln("Starting server on", *listenAddress)
|
log.Infoln("Starting server on", *listenAddress)
|
||||||
log.Fatalf("cannot start WMI exporter: %s", http.ListenAndServe(*listenAddress, nil))
|
log.Fatalf("cannot start windows_exporter: %s", http.ListenAndServe(*listenAddress, nil))
|
||||||
}()
|
}()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
if <-stopCh {
|
if <-stopCh {
|
||||||
log.Info("Shutting down WMI exporter")
|
log.Info("Shutting down windows_exporter")
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -399,11 +399,11 @@ func withConcurrencyLimit(n int, next http.HandlerFunc) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type wmiExporterService struct {
|
type windowsExporterService struct {
|
||||||
stopCh chan<- bool
|
stopCh chan<- bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *wmiExporterService) Execute(args []string, r <-chan svc.ChangeRequest, changes chan<- svc.Status) (ssec bool, errno uint32) {
|
func (s *windowsExporterService) Execute(args []string, r <-chan svc.ChangeRequest, changes chan<- svc.Status) (ssec bool, errno uint32) {
|
||||||
const cmdsAccepted = svc.AcceptStop | svc.AcceptShutdown
|
const cmdsAccepted = svc.AcceptStop | svc.AcceptShutdown
|
||||||
changes <- svc.Status{State: svc.StartPending}
|
changes <- svc.Status{State: svc.StartPending}
|
||||||
changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted}
|
changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted}
|
||||||
@@ -428,7 +428,7 @@ loop:
|
|||||||
|
|
||||||
type metricsHandler struct {
|
type metricsHandler struct {
|
||||||
timeoutMargin float64
|
timeoutMargin float64
|
||||||
collectorFactory func(timeout time.Duration) *WmiCollector
|
collectorFactory func(timeout time.Duration) *windowsCollector
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mh *metricsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (mh *metricsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
Reference in New Issue
Block a user