Skip to content

Commit 19771aa

Browse files
authored
Merge pull request #1296 from Lomanic/issue1094
[disk][windows] Set EnableCounterForIoctl reg key to 1 in init() to automatically enable diskperf on Server editions
2 parents def6865 + 2318b5e commit 19771aa

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

disk/disk_windows.go

+9
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"github.com/shirou/gopsutil/v3/internal/common"
1414
"golang.org/x/sys/windows"
15+
"golang.org/x/sys/windows/registry"
1516
)
1617

1718
var (
@@ -44,6 +45,14 @@ type diskPerformance struct {
4445
alignmentPadding uint32 // necessary for 32bit support, see https://github.com/elastic/beats/pull/16553
4546
}
4647

48+
func init() {
49+
// enable disk performance counters on Windows Server editions (needs to run as admin)
50+
key, err := registry.OpenKey(registry.LOCAL_MACHINE, `SYSTEM\CurrentControlSet\Services\PartMgr`, registry.SET_VALUE)
51+
if err == nil {
52+
key.SetDWordValue("EnableCounterForIoctl", 1)
53+
}
54+
}
55+
4756
func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) {
4857
lpFreeBytesAvailable := int64(0)
4958
lpTotalNumberOfBytes := int64(0)

0 commit comments

Comments
 (0)