File tree 1 file changed +6
-3
lines changed 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -178,8 +178,9 @@ func New(opts ...Option) (*Statter, error) {
178
178
// Units are in "cores".
179
179
func (s * Statter ) HostCPU (m Prefix ) (* Result , error ) {
180
180
r := & Result {
181
- Unit : "cores" ,
182
- Total : ptr .To (float64 (s .nproc )),
181
+ Unit : "cores" ,
182
+ Total : ptr .To (float64 (s .nproc )),
183
+ Prefix : m ,
183
184
}
184
185
c1 , err := s .hi .CPUTime ()
185
186
if err != nil {
@@ -191,11 +192,13 @@ func (s *Statter) HostCPU(m Prefix) (*Result, error) {
191
192
return nil , xerrors .Errorf ("get second cpu sample: %w" , err )
192
193
}
193
194
total := c2 .Total () - c1 .Total ()
195
+ if total == 0 {
196
+ return r , nil // no change
197
+ }
194
198
idle := c2 .Idle - c1 .Idle
195
199
used := total - idle
196
200
scaleFactor := float64 (s .nproc ) / total .Seconds ()
197
201
r .Used = used .Seconds () * scaleFactor
198
- r .Prefix = m
199
202
return r , nil
200
203
}
201
204
You can’t perform that action at this time.
0 commit comments