Skip to content

Commit

Permalink
Merge pull request #1296 from Lomanic/issue1094
Browse files Browse the repository at this point in the history
[disk][windows] Set EnableCounterForIoctl reg key to 1 in init() to automatically enable diskperf on Server editions
  • Loading branch information
shirou committed May 8, 2022
2 parents def6865 + 2318b5e commit 19771aa
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions disk/disk_windows.go
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/shirou/gopsutil/v3/internal/common"
"golang.org/x/sys/windows"
"golang.org/x/sys/windows/registry"
)

var (
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 19771aa

Please sign in to comment.