Skip to content

Commit

Permalink
Fix memory leak by updating go-ole and adding wbem initialization (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlpett authored and martinlindhe committed Jun 26, 2017
1 parent 22a9c96 commit 175c54a
Show file tree
Hide file tree
Showing 6 changed files with 320 additions and 8 deletions.
15 changes: 15 additions & 0 deletions exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -158,6 +171,8 @@ func main() {
return
}

initWbem()

isInteractive, err := svc.IsAnInteractiveSession()
if err != nil {
log.Fatal(err)
Expand Down
4 changes: 3 additions & 1 deletion vendor/github.com/StackExchange/wmi/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

260 changes: 260 additions & 0 deletions vendor/github.com/StackExchange/wmi/swbemservices.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 24 additions & 1 deletion vendor/github.com/StackExchange/wmi/wmi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions vendor/github.com/go-ole/go-ole/variant_s390x.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions vendor/vendor.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
"revisionTime": "2016-08-29T20:23:21Z"
},
{
"checksumSHA1": "9NR0rrcAT5J76C5xMS4AVksS9o0=",
"checksumSHA1": "qtjd74+bErubh+qyv3s+lWmn9wc=",
"path": "github.com/StackExchange/wmi",
"revision": "e54cbda6595d7293a7a468ccf9525f6bc8887f99",
"revisionTime": "2016-08-11T21:45:55Z"
"revision": "ea383cf3ba6ec950874b8486cd72356d007c768f",
"revisionTime": "2017-04-10T19:29:09Z"
},
{
"checksumSHA1": "spyv5/YFBjYyZLZa1U2LBfDR8PM=",
Expand All @@ -21,10 +21,10 @@
"revisionTime": "2016-08-04T10:47:26Z"
},
{
"checksumSHA1": "wDZdTaY9JiqqqnF4c3pHP71nWmk=",
"checksumSHA1": "oyULO1B/l2OLy2xereo+2w3hYk4=",
"path": "github.com/go-ole/go-ole",
"revision": "7dfdcf409020452e29b4babcbb22f984d2aa308a",
"revisionTime": "2016-07-29T03:38:29Z"
"revision": "02d3668a0cf01f58411cc85cd37c174c257ec7c2",
"revisionTime": "2017-06-01T13:56:11Z"
},
{
"checksumSHA1": "qLYVTQDhgrVIeZ2KI9eZV51mmug=",
Expand Down

0 comments on commit 175c54a

Please sign in to comment.