mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-10-17 10:09:05 +02:00
1.8 KiB
1.8 KiB
PDH package
internal/pdh wraps the Performance Data Helper API for the typed collectors
(NewCollector, NewQueryCollector) and the configurable performancecounter
collector (NewDynamicCollector).
Ownership
- Constructors return either a value and a nil error, or nil and an error.
NewCollectorandNewDynamicCollectorclose the query they opened, andNewQueryCollectorremoves the counters it added to the shared query, before they return an error. Callers never close a value they did not receive;Collector.CloseandQuery.Closeaccept nil receivers. - Collectors usually assign the result to a field before checking the error,
so after an error the field is nil. A
Buildthat tolerates the error must check the field for nil inCollect; the parentClosecan close the field unconditionally. newCollectorholds the lock of a shared query while it adds counters, so its error paths useCollector.release, which expects the caller to hold the locks or be the only user.Closetakes the locks and calls it.- Close collectors of a
Querybefore the query itself.
Struct tags
perfdata:"Counter"marks afloat64field;perfdata:"Counter,secondvalue"receives the second raw value (the base of a ratio or average).perfdata_min_build:"<build>"skips a counter that is missing on an older Windows build. The value must be a decimal build number that fits auint16; anything else is a constructor error, so a typo cannot silently disable the check.
Native calls
- The wrappers return PDH status codes. A path that cannot be converted to
UTF-16 (it contains a NUL character) returns
CstatusBadCounternameinstead of passing a NULL path to PDH. - Build a
pdh.ErrorwithNewPdhErroronly for a status that is reported as an error: it formats the message text withFormatMessage.