File tree 1 file changed +4
-3
lines changed
1 file changed +4
-3
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ import (
15
15
16
16
const procOneCgroup = "/proc/1/cgroup"
17
17
18
+ var nproc = float64 (runtime .NumCPU ())
19
+
18
20
// Result is a generic result type for a statistic.
19
21
// Total is the total amount of the resource available.
20
22
// It is nil if the resource is not a finite quantity.
@@ -83,9 +85,9 @@ func New(opts ...Option) (*Statter, error) {
83
85
// and scaling it by the number of cores.
84
86
// Units are in "cores".
85
87
func (s * Statter ) HostCPU () (* Result , error ) {
86
- nproc := float64 (runtime .NumCPU ())
87
88
r := & Result {
88
- Unit : "cores" ,
89
+ Unit : "cores" ,
90
+ Total : ptr .To (nproc ),
89
91
}
90
92
c1 , err := s .hi .CPUTime ()
91
93
if err != nil {
@@ -96,7 +98,6 @@ func (s *Statter) HostCPU() (*Result, error) {
96
98
if err != nil {
97
99
return nil , xerrors .Errorf ("get second cpu sample: %w" , err )
98
100
}
99
- r .Total = ptr .To (nproc )
100
101
total := c2 .Total () - c1 .Total ()
101
102
idle := c2 .Idle - c1 .Idle
102
103
used := total - idle
You can’t perform that action at this time.
0 commit comments