Skip to content

Commit e38ac6b

Browse files
build(deps): update procfs requirement from ^0.12 to ^0.14 (#452)
* build(deps): update procfs requirement from ^0.12 to ^0.14 Updates the requirements on [procfs](https://github.com/eminence/procfs) to permit the latest version. - [Release notes](https://github.com/eminence/procfs/releases) - [Commits](eminence/procfs@v0.12.0...v0.14.0) --- updated-dependencies: - dependency-name: procfs dependency-type: direct:production ... Signed-off-by: dependabot[bot] <[email protected]> * process: update to new procfs-0.14 API Signed-off-by: Luca BRUNO <[email protected]> Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: Luca BRUNO <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Luca BRUNO <[email protected]>
1 parent 4e552ee commit e38ac6b

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ reqwest = { version = "^0.11", features = ["blocking"], optional = true }
3636
thiserror = "^1.0"
3737

3838
[target.'cfg(target_os = "linux")'.dependencies]
39-
procfs = { version = "^0.12", optional = true, default-features = false }
39+
procfs = { version = "^0.14", optional = true, default-features = false }
4040

4141
[dev-dependencies]
4242
criterion = "0.3"

src/process_collector.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ impl ProcessCollector {
9999
.unwrap();
100100
// proc_start_time init once because it is immutable
101101
if let Ok(boot_time) = procfs::boot_time_secs() {
102-
if let Ok(p) = procfs::process::Process::myself() {
103-
start_time.set(p.stat.starttime as i64 / *CLK_TCK + boot_time as i64);
102+
if let Ok(stat) = procfs::process::Process::myself().and_then(|p| p.stat()) {
103+
start_time.set(stat.starttime as i64 / *CLK_TCK + boot_time as i64);
104104
}
105105
}
106106
descs.extend(start_time.desc().into_iter().cloned());
@@ -156,25 +156,27 @@ impl Collector for ProcessCollector {
156156
}
157157
}
158158

159-
// memory
160-
self.vsize.set(p.stat.vsize as i64);
161-
self.rss.set(p.stat.rss * *PAGESIZE);
159+
let mut cpu_total_mfs = None;
160+
if let Ok(stat) = p.stat() {
161+
// memory
162+
self.vsize.set(stat.vsize as i64);
163+
self.rss.set((stat.rss as i64) * *PAGESIZE);
162164

163-
// cpu
164-
let cpu_total_mfs = {
165-
let total = (p.stat.utime + p.stat.stime) / *CLK_TCK as u64;
165+
// cpu
166+
let total = (stat.utime + stat.stime) / *CLK_TCK as u64;
166167
let past = self.cpu_total.get();
167168
self.cpu_total.inc_by(total - past);
169+
cpu_total_mfs = Some(self.cpu_total.collect());
168170

169-
self.cpu_total.collect()
170-
};
171-
172-
// threads
173-
self.threads.set(p.stat.num_threads);
171+
// threads
172+
self.threads.set(stat.num_threads);
173+
}
174174

175175
// collect MetricFamilys.
176176
let mut mfs = Vec::with_capacity(METRICS_NUMBER);
177-
mfs.extend(cpu_total_mfs);
177+
if let Some(cpu) = cpu_total_mfs {
178+
mfs.extend(cpu);
179+
}
178180
mfs.extend(self.open_fds.collect());
179181
mfs.extend(self.max_fds.collect());
180182
mfs.extend(self.vsize.collect());

0 commit comments

Comments
 (0)