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>
Using perflib is substantially faster and more reliable than using WMI to
retrieve Windows performance counter data.
Signed-off-by: Michael Allen <MAllen@laserfiche.com>
While the ConnectionsEstablished property in the
Win32_PerfRawData_Tcpip_TCP class is listed as a counter, real-world
metric values have been shown to increase *and* decrease.
Documentation for the property states "Number of TCP connections for
which the *current* state is either ESTABLISHED or CLOSE-WAIT" which
would imply the metric is a gauge.
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