Collector builder functions are only used internally in the `collector`
package, and shouldn't needlessly be exposed as part of the package API
to downstream clients.
Signed-off-by: Ben Reedy <breed808@breed808.com>
Behaviour of init functions has been centralised in `collector/init.go`,
and can be called during exporter startup. This allows the exporter to
control the timing of collector initialisation, rather than relying on
the import & `init()` method.
This should reduce unexpected behaviour arising from the use of
`init()`, such as #551.
Signed-off-by: Ben Reedy <breed808@breed808.com>
Inactive or missing paging file should not be cause for OS collector to
fail.
Instead, log the error and continue with OS collection.
Signed-off-by: Ben Reedy <breed808@breed808.com>
See,
```
$ GOOS=windows GOARCH=amd64 golangci-lint run ./... 2>1 | grep var-declaration
collector/os.go:205:22: var-declaration: should drop = 0 from declaration of var fsipf; it is the zero value (revive)
collector/os.go:226:23: var-declaration: should drop = 0 from declaration of var pfbRaw; it is the zero value (revive)
```
Signed-off-by: Mario Trangoni <mjtrangoni@gmail.com>
Some collectors were missed when migrating to the local
github.com/prometheus-community/windows_exporter/log library.
Signed-off-by: Ben Reedy <breed808@breed808.com>
- Defer registry close calls
- Ensure size parameter in GetComputerName is properly specified
- Clean up some comments to ensure correctness
Signed-off-by: Ben Ridley <benridley29@gmail.com>
If an WMI query were to return an empty result set, trying to access the
first element in the result set would result in a `panic: runtime error:
index out of range` error.
add logic to explicitly check if the result set size is 0 and return an
error rather.
Fixes https://github.com/martinlindhe/wmi_exporter/issues/240