[disk][windows] Set EnableCounterForIoctl reg key to 1 in init() to automatically enable diskperf on Server editions

Fixes #1094
pull/1296/head
Lomanic 3 years ago
parent 24a1ae54b4
commit 2318b5e69f

@ -12,6 +12,7 @@ import (
"github.com/shirou/gopsutil/v3/internal/common"
"golang.org/x/sys/windows"
"golang.org/x/sys/windows/registry"
)
var (
@ -44,6 +45,14 @@ type diskPerformance struct {
alignmentPadding uint32 // necessary for 32bit support, see https://github.com/elastic/beats/pull/16553
}
func init() {
// enable disk performance counters on Windows Server editions (needs to run as admin)
key, err := registry.OpenKey(registry.LOCAL_MACHINE, `SYSTEM\CurrentControlSet\Services\PartMgr`, registry.SET_VALUE)
if err == nil {
key.SetDWordValue("EnableCounterForIoctl", 1)
}
}
func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) {
lpFreeBytesAvailable := int64(0)
lpTotalNumberOfBytes := int64(0)

Loading…
Cancel
Save