Override 3 sec. WMI timeout in gopsutil
The default timeout is too short for some overburdened or resource constrained machines to complete the WMI query before the context deadline expires. This causes them to be unable to fingerprint the CPU properly.
This commit is contained in:
parent
c42340ca48
commit
d64b02f07d
|
@ -1,14 +1,21 @@
|
|||
package stats
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
multierror "github.com/hashicorp/go-multierror"
|
||||
"github.com/shirou/gopsutil/cpu"
|
||||
)
|
||||
|
||||
const (
|
||||
// We use this constant to override the built in 3 second timeout in gopsutil
|
||||
cpuInfoTimeout = 10 * time.Second
|
||||
)
|
||||
|
||||
var (
|
||||
cpuMhzPerCore float64
|
||||
cpuModelName string
|
||||
|
@ -28,7 +35,9 @@ 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", initErr))
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue