Fix memory leak by updating go-ole and adding wbem initialization (#82)

This commit is contained in:
Calle Pettersson
2017-06-26 21:03:17 +02:00
committed by Martin Lindhe
parent 22a9c96ffd
commit 175c54acf1
6 changed files with 320 additions and 8 deletions

View File

@@ -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)