Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding optional --prefix option #64

Closed
wants to merge 13 commits into from
100 changes: 95 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ loggerv = "0.7.2"
log = "0.4"
clap = "2.33.3"
regex = "1"
procfs = "0.12.0"
procfs = "0.13.2"
riemann_client = { version = "0.9.0", optional = true }
hostname = "0.3.1"
protobuf = "2.20.0"
Expand Down
40 changes: 39 additions & 1 deletion docs_src/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ On ubuntu 20.01 and 20.10, try to install `linux-modules-extra-$(uname-r)` with

We verified that scaphandre (and especially the powercap_rapl sensor) works on AMD Zen processors with a Linux kernel **5.11 or later**. Before that kernel version, it won't probably work as the [drivers](https://www.phoronix.com/scan.php?page=news_item&px=AMD-Zen-PowerCap-RAPL-5.11) needed to feed powercap with rapl data are not present.

### Trying to build the project I get this error
### Trying to build the project I get "linker `cc` not found"

error: linker `cc` not found
|
Expand All @@ -64,3 +64,41 @@ We verified that scaphandre (and especially the powercap_rapl sensor) works on A
You need compiling tooling. On Ubuntu/Debian, run:

sudo apt install build-essential

## Trying to build the project I get "pkg_config fail: Failed to run ... openssl"

Full error may look like that :

run pkg_config fail: "Failed to run `\"pkg-config\" \"--libs\" \"--cflags\" \"openssl\"`: No such file or directory (os error 2)"

--- stderr
thread 'main' panicked at '

Could not find directory of OpenSSL installation, and this `-sys` crate cannot
proceed without this knowledge. If OpenSSL is installed and this crate had
trouble finding it, you can set the `OPENSSL_DIR` environment variable for the
compilation process.

Make sure you also have the development packages of openssl installed.
For example, `libssl-dev` on Ubuntu or `openssl-devel` on Fedora.

If you're in a situation where you think the directory *should* be found
automatically, please open a bug at https://github.com/sfackler/rust-openssl
and include information about your system as well as this message.

$HOST = x86_64-unknown-linux-gnu
$TARGET = x86_64-unknown-linux-gnu
openssl-sys = 0.9.66


It looks like you're compiling on Linux and also targeting Linux. Currently this
requires the `pkg-config` utility to find OpenSSL but unfortunately `pkg-config`
could not be found. If you have OpenSSL installed you can likely fix this by
installing `pkg-config`.

', /home/bpetit/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-sys-0.9.66/build/find_normal.rs:174:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

On Debian/Ubuntum the solution would be to install both pkg-config and libssl-dev :

apt install pkg-config libssl-dev
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ fn get_sensor(matches: &ArgMatches) -> Box<dyn Sensor> {
.parse()
.unwrap(),
matches.is_present("vm"),
get_argument(matches, "prefix"),
),
_ => PowercapRAPLSensor::new(
get_argument(matches, "sensor-buffer-per-socket-max-kB")
Expand All @@ -45,6 +46,7 @@ fn get_sensor(matches: &ArgMatches) -> Box<dyn Sensor> {
.parse()
.unwrap(),
matches.is_present("vm"),
get_argument(matches, "prefix"),
),
};
Box::new(sensor)
Expand Down
8 changes: 8 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ fn main() {
.long("vm")
.required(false)
.takes_value(false)
).arg(
Arg::with_name("prefix")
.value_name("prefix")
.help("Ask scaphandre to look for data in a specific location instead of the default one (will look in $PREFIX/sys/class/powercap and $PREFIX/proc).")
.long("prefix")
.required(false)
.takes_value(false)
.default_value("")
);

for exporter in exporters {
Expand Down
13 changes: 9 additions & 4 deletions src/sensors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::error::Error;
use std::mem::size_of_val;
use std::time::Duration;
use std::{fmt, fs};
use std::path::Path;
use utils::{current_system_time_since_epoch, ProcessTracker};

// !!!!!!!!!!!!!!!!! Sensor !!!!!!!!!!!!!!!!!!!!!!!
Expand Down Expand Up @@ -256,6 +257,10 @@ impl Topology {
.unwrap()
.parse::<u16>()
.unwrap();
println!("socket_id: {}", socket_id);
for s in &self.sockets {
println!("s.id: {}", s.id);
}
let socket = self
.sockets
.iter_mut()
Expand Down Expand Up @@ -294,7 +299,7 @@ impl Topology {
/// them in self.proc_tracker
fn refresh_procs(&mut self) {
//! current_procs is the up to date list of processus running on the host
let current_procs = process::all_processes().unwrap();
let current_procs = process::all_processes_with_root().unwrap();

for p in current_procs {
let pid = p.pid;
Expand Down Expand Up @@ -1137,14 +1142,14 @@ mod tests {

#[test]
fn read_topology_stats() {
let mut sensor = powercap_rapl::PowercapRAPLSensor::new(8, 8, false);
let mut sensor = powercap_rapl::PowercapRAPLSensor::new(8, 8, false, String::from(""));
let topo = (*sensor.get_topology()).unwrap();
println!("{:?}", topo.read_stats());
}

#[test]
fn read_core_stats() {
let mut sensor = powercap_rapl::PowercapRAPLSensor::new(8, 8, false);
let mut sensor = powercap_rapl::PowercapRAPLSensor::new(8, 8, false, String::from(""));
let mut topo = (*sensor.get_topology()).unwrap();
for s in topo.get_sockets() {
for c in s.get_cores() {
Expand All @@ -1155,7 +1160,7 @@ mod tests {

#[test]
fn read_socket_stats() {
let mut sensor = powercap_rapl::PowercapRAPLSensor::new(8, 8, false);
let mut sensor = powercap_rapl::PowercapRAPLSensor::new(8, 8, false, String::from(""));
let mut topo = (*sensor.get_topology()).unwrap();
for s in topo.get_sockets() {
println!("{:?}", s.read_stats());
Expand Down
5 changes: 3 additions & 2 deletions src/sensors/powercap_rapl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ impl PowercapRAPLSensor {
buffer_per_socket_max_kbytes: u16,
buffer_per_domain_max_kbytes: u16,
virtual_machine: bool,
prefix: String,
) -> PowercapRAPLSensor {
let mut powercap_path = String::from("/sys/class/powercap");
let mut powercap_path = format!("{}/sys/class/powercap", prefix);
if virtual_machine {
powercap_path = String::from("/var/scaphandre");
if let Ok(val) = env::var("SCAPHANDRE_POWERCAP_PATH") {
Expand Down Expand Up @@ -127,7 +128,7 @@ mod tests {
}
#[test]
fn get_topology_returns_topology_type() {
let mut sensor = PowercapRAPLSensor::new(1, 1, false);
let mut sensor = PowercapRAPLSensor::new(1, 1, false, String::from(""));
let topology = sensor.get_topology();
assert_eq!(
"alloc::boxed::Box<core::option::Option<scaphandre::sensors::Topology>>",
Expand Down
2 changes: 1 addition & 1 deletion tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::fs::{create_dir, read_dir};

#[test]
fn exporter_qemu() {
let sensor = PowercapRAPLSensor::new(1, 1, false);
let sensor = PowercapRAPLSensor::new(1, 1, false, String::from(""));
let mut exporter = QemuExporter::new(Box::new(sensor));
// Create integration_tests directory if it does not exist
let curdir = current_dir().unwrap();
Expand Down