Skip to content

Commit

Permalink
build(deps): update procfs requirement from ^0.12 to ^0.14 (#452)
Browse files Browse the repository at this point in the history
* 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] <support@github.com>

* process: update to new procfs-0.14 API

Signed-off-by: Luca BRUNO <luca.bruno@coreos.com>

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Luca BRUNO <luca.bruno@coreos.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Luca BRUNO <luca.bruno@coreos.com>
  • Loading branch information
dependabot[bot] and lucab committed Sep 9, 2022
1 parent 4e552ee commit e38ac6b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ reqwest = { version = "^0.11", features = ["blocking"], optional = true }
thiserror = "^1.0"

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

[dev-dependencies]
criterion = "0.3"
Expand Down
30 changes: 16 additions & 14 deletions src/process_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ impl ProcessCollector {
.unwrap();
// proc_start_time init once because it is immutable
if let Ok(boot_time) = procfs::boot_time_secs() {
if let Ok(p) = procfs::process::Process::myself() {
start_time.set(p.stat.starttime as i64 / *CLK_TCK + boot_time as i64);
if let Ok(stat) = procfs::process::Process::myself().and_then(|p| p.stat()) {
start_time.set(stat.starttime as i64 / *CLK_TCK + boot_time as i64);
}
}
descs.extend(start_time.desc().into_iter().cloned());
Expand Down Expand Up @@ -156,25 +156,27 @@ impl Collector for ProcessCollector {
}
}

// memory
self.vsize.set(p.stat.vsize as i64);
self.rss.set(p.stat.rss * *PAGESIZE);
let mut cpu_total_mfs = None;
if let Ok(stat) = p.stat() {
// memory
self.vsize.set(stat.vsize as i64);
self.rss.set((stat.rss as i64) * *PAGESIZE);

// cpu
let cpu_total_mfs = {
let total = (p.stat.utime + p.stat.stime) / *CLK_TCK as u64;
// cpu
let total = (stat.utime + stat.stime) / *CLK_TCK as u64;
let past = self.cpu_total.get();
self.cpu_total.inc_by(total - past);
cpu_total_mfs = Some(self.cpu_total.collect());

self.cpu_total.collect()
};

// threads
self.threads.set(p.stat.num_threads);
// threads
self.threads.set(stat.num_threads);
}

// collect MetricFamilys.
let mut mfs = Vec::with_capacity(METRICS_NUMBER);
mfs.extend(cpu_total_mfs);
if let Some(cpu) = cpu_total_mfs {
mfs.extend(cpu);
}
mfs.extend(self.open_fds.collect());
mfs.extend(self.max_fds.collect());
mfs.extend(self.vsize.collect());
Expand Down

0 comments on commit e38ac6b

Please sign in to comment.