We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent fc591fd commit a11df02Copy full SHA for a11df02
src/process_collector.rs
@@ -165,7 +165,10 @@ impl Collector for ProcessCollector {
165
// cpu
166
let total = (stat.utime + stat.stime) / *CLK_TCK as u64;
167
let past = self.cpu_total.get();
168
- self.cpu_total.inc_by(total - past);
+ // If two threads are collecting metrics at the same time,
169
+ // the cpu_total counter may have already been updated,
170
+ // and the subtraction may underflow.
171
+ self.cpu_total.inc_by(total.saturating_sub(past));
172
cpu_total_mfs = Some(self.cpu_total.collect());
173
174
// threads
0 commit comments