mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-03-04 01:26:37 +00:00
Fix memory leak by updating go-ole and adding wbem initialization (#82)
This commit is contained in:
committed by
Martin Lindhe
parent
22a9c96ffd
commit
175c54acf1
15
exporter.go
15
exporter.go
@@ -13,6 +13,7 @@ import (
|
||||
|
||||
"golang.org/x/sys/windows/svc"
|
||||
|
||||
"github.com/StackExchange/wmi"
|
||||
"github.com/martinlindhe/wmi_exporter/collector"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
@@ -130,6 +131,18 @@ func init() {
|
||||
prometheus.MustRegister(version.NewCollector("wmi_exporter"))
|
||||
}
|
||||
|
||||
func initWbem() {
|
||||
// This initialization prevents a memory leak on WMF 5+. See
|
||||
// https://github.com/martinlindhe/wmi_exporter/issues/77 and linked issues
|
||||
// for details.
|
||||
log.Debugf("Initializing SWbemServices")
|
||||
s, err := wmi.InitializeSWbemServices(wmi.DefaultClient)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
wmi.DefaultClient.SWbemServicesClient = s
|
||||
}
|
||||
|
||||
func main() {
|
||||
var (
|
||||
showVersion = flag.Bool("version", false, "Print version information.")
|
||||
@@ -158,6 +171,8 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
initWbem()
|
||||
|
||||
isInteractive, err := svc.IsAnInteractiveSession()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
||||
Reference in New Issue
Block a user