Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override 3 sec. WMI timeout in gopsutil #4268

Merged
merged 3 commits into from
May 9, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion helper/stats/cpu.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
package stats

import (
"context"
"fmt"
"math"
"sync"
"time"

multierror "github.com/hashicorp/go-multierror"
"github.com/shirou/gopsutil/cpu"
)

const (
// cpuInfoTimeout is the timeout used when gathering CPU info. This is used
// to override the default timeout in gopsutil which has a tendency to
// timeout on Windows.
cpuInfoTimeout = 10 * time.Second
)

var (
cpuMhzPerCore float64
cpuModelName string
Expand All @@ -28,7 +37,8 @@ func Init() error {
}

var cpuInfo []cpu.InfoStat
if cpuInfo, err = cpu.Info(); err != nil {
ctx, _ := context.WithTimeout(context.Background(), cpuInfoTimeout)
if cpuInfo, err = cpu.InfoWithContext(ctx); err != nil {
merrs = multierror.Append(merrs, fmt.Errorf("Unable to obtain CPU information: %v", err))
}

Expand Down