diff --git a/.github/workflows/cargo.yml b/.github/workflows/cargo.yml index c667c862..3544a70f 100644 --- a/.github/workflows/cargo.yml +++ b/.github/workflows/cargo.yml @@ -101,7 +101,6 @@ jobs: matrix: os: [ ubuntu-latest, ubuntu-20.04, macos-latest ] profile: [ release, debug ] - features: [ default, no-default ] steps: - uses: actions/checkout@v3 - uses: ./.github/actions/setup-rust @@ -118,15 +117,6 @@ jobs: run: echo 'FLAGS=' >> $GITHUB_ENV shell: bash - - name: Update feature flags - if: ${{ matrix.features == 'default' }} - run: echo 'FEATURE_FLAGS=--features default' >> $GITHUB_ENV - shell: bash - - name: Update feature flags - if: ${{ matrix.features == 'no-default' }} - run: echo 'FEATURE_FLAGS=--no-default-features' >> $GITHUB_ENV - shell: bash - - name: Install dependencies if: ${{ matrix.os != 'macos-latest' }} shell: bash diff --git a/CHANGELOG.md b/CHANGELOG.md index 366d09c0..ea3c9ffd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## [Unreleased] +### Changed + +- BPF is now non-optional on Linux. (#336) + ## [3.18.1] - 2024-08-09 ### Changed diff --git a/Cargo.lock b/Cargo.lock index 1da61e6a..ec18529e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1483,7 +1483,7 @@ checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" [[package]] name = "rezolus" -version = "3.18.2-alpha.11" +version = "4.0.0-alpha.1" dependencies = [ "async-trait", "backtrace", @@ -1779,7 +1779,7 @@ dependencies = [ [[package]] name = "systeminfo" -version = "3.18.2-alpha.11" +version = "4.0.0-alpha.1" dependencies = [ "log", "serde", diff --git a/Cargo.toml b/Cargo.toml index 237ca398..de8a1bb2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" description = "High resolution systems performance telemetry agent" [workspace.package] -version = "3.18.2-alpha.11" +version = "4.0.0-alpha.1" license = "MIT OR Apache-2.0" [dependencies] @@ -41,18 +41,13 @@ async-trait = "0.1.81" parking_lot = "0.12.3" [target.'cfg(target_os = "linux")'.dependencies] -libbpf-rs = { version = "0.24.2", optional = true } -libbpf-sys = { version = "1.4.3", optional = true } +libbpf-rs = { version = "0.24.2" } +libbpf-sys = { version = "1.4.3" } perf-event2 = "0.7.2" nvml-wrapper = "0.9.0" [target.'cfg(target_os = "linux")'.build-dependencies] -libbpf-cargo = { version = "0.24.2", optional = true } - -[features] -all = ["bpf"] -default = ["bpf"] -bpf = ["libbpf-cargo","libbpf-rs","libbpf-sys"] +libbpf-cargo = { version = "0.24.2" } [profile.bench] debug = true diff --git a/build.rs b/build.rs index 377a76c8..9a2b869f 100644 --- a/build.rs +++ b/build.rs @@ -1,9 +1,9 @@ fn main() { - #[cfg(all(feature = "bpf", target_os = "linux"))] + #[cfg(target_os = "linux")] bpf::generate(); } -#[cfg(all(feature = "bpf", target_os = "linux"))] +#[cfg(target_os = "linux")] mod bpf { use libbpf_cargo::SkeletonBuilder; diff --git a/config.toml b/config.toml index ee7530a5..3eb32318 100644 --- a/config.toml +++ b/config.toml @@ -61,10 +61,6 @@ histogram_grouping_power = 4 # collection for that sampler. Setting the default to false requires that # individual sampler configs are used to opt-in to collection. enabled = true -# Controls whether BPF sampler will be used. When a metric can be collected -# without BPF, that sampler will be used instead. Otherwise, the sampler will -# effectively be disabled. -bpf = true # The collection interval for the sampler. Shorter intervals result in less # error when calculating rates and allow for more accurately capturing bursts in # the related percentile metrics. @@ -83,17 +79,14 @@ enabled = true [samplers.block_io_requests] enabled = true -# Instruments CPU frequency, instructions, and cycles using BPF perf events or -# frequency only via /proc/cpuinfo +# Instruments CPU frequency, instructions, and cycles using perf events [samplers.cpu_perf] enabled = true -bpf = true -# Instruments CPU usage by state with BPF or by reading /proc/stat on linux +# Instruments CPU usage by state with BPF # On macos host_processor_info() is used [samplers.cpu_usage] enabled = true -bpf = true # Instruments the number of currently open file descriptors using # /proc/sys/fs/file-nr @@ -161,8 +154,7 @@ enabled = true [samplers.tcp_retransmit] enabled = true -# Samples TCP traffic using either a BPF sampler or /proc/net/snmp to provide -# metrics for TX/RX bytes and packets +# Samples TCP traffic using a BPF sampler to get metrics for TX/RX bytes and +# packets [samplers.tcp_traffic] enabled = true -bpf = true diff --git a/src/common/mod.rs b/src/common/mod.rs index 7645b82e..ec8557d4 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -1,4 +1,4 @@ -#[cfg(all(feature = "bpf", target_os = "linux"))] +#[cfg(target_os = "linux")] pub mod bpf; pub mod classic; diff --git a/src/config/mod.rs b/src/config/mod.rs index 05378350..8ba55325 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -76,13 +76,6 @@ impl Config { .unwrap_or(self.defaults.enabled.unwrap_or(enabled())) } - pub fn bpf(&self, name: &str) -> bool { - self.samplers - .get(name) - .and_then(|v| v.bpf) - .unwrap_or(self.defaults.bpf.unwrap_or(enabled())) - } - pub fn interval(&self, name: &str) -> Duration { let interval = self .samplers @@ -261,8 +254,6 @@ pub struct SamplerConfig { #[serde(default)] enabled: Option, #[serde(default)] - bpf: Option, - #[serde(default)] interval: Option, } diff --git a/src/samplers/block_io/linux/latency/mod.rs b/src/samplers/block_io/linux/latency/mod.rs index 9b86659c..3137e1c3 100644 --- a/src/samplers/block_io/linux/latency/mod.rs +++ b/src/samplers/block_io/linux/latency/mod.rs @@ -21,7 +21,7 @@ use crate::*; #[distributed_slice(ASYNC_SAMPLERS)] fn spawn(config: Arc, runtime: &Runtime) { // check if sampler should be enabled - if !(config.enabled(NAME) && config.bpf(NAME)) { + if !config.enabled(NAME) { return; } diff --git a/src/samplers/block_io/linux/mod.rs b/src/samplers/block_io/linux/mod.rs index 2b0af0de..5497fe29 100644 --- a/src/samplers/block_io/linux/mod.rs +++ b/src/samplers/block_io/linux/mod.rs @@ -1,5 +1,2 @@ -#[cfg(feature = "bpf")] mod latency; - -#[cfg(feature = "bpf")] mod requests; diff --git a/src/samplers/block_io/linux/requests/mod.rs b/src/samplers/block_io/linux/requests/mod.rs index cadf6cc1..4b1632b5 100644 --- a/src/samplers/block_io/linux/requests/mod.rs +++ b/src/samplers/block_io/linux/requests/mod.rs @@ -22,7 +22,7 @@ use crate::*; #[distributed_slice(ASYNC_SAMPLERS)] fn spawn(config: Arc, runtime: &Runtime) { // check if sampler should be enabled - if !(config.enabled(NAME) && config.bpf(NAME)) { + if !config.enabled(NAME) { return; } diff --git a/src/samplers/cpu/linux/perf/mod.rs b/src/samplers/cpu/linux/perf/mod.rs index 0824e38c..d7a2b113 100644 --- a/src/samplers/cpu/linux/perf/mod.rs +++ b/src/samplers/cpu/linux/perf/mod.rs @@ -9,21 +9,13 @@ use perf_event::{Builder, ReadFormat}; use samplers::hwinfo::hardware_info; mod perf_group; -mod proc_cpuinfo; use perf_group::*; -use proc_cpuinfo::*; #[distributed_slice(SAMPLERS)] fn init(config: Arc) -> Box { - // try to initialize the perf counter based sampler that provides more info - // with lower overhead if let Ok(perf) = Perf::new(config.clone()) { Box::new(perf) - // try to fallback to the /proc/cpuinfo based sampler if perf events are not - // supported - } else if let Ok(cpuinfo) = ProcCpuinfo::new(config) { - Box::new(cpuinfo) } else { Box::new(Nop {}) } @@ -41,7 +33,7 @@ pub struct Perf { impl Perf { pub fn new(config: Arc) -> Result { // check if sampler should be enabled - if !(config.enabled(NAME) && config.bpf(NAME)) { + if !config.enabled(NAME) { return Err(()); } diff --git a/src/samplers/cpu/linux/perf/proc_cpuinfo.rs b/src/samplers/cpu/linux/perf/proc_cpuinfo.rs deleted file mode 100644 index 4b0916e0..00000000 --- a/src/samplers/cpu/linux/perf/proc_cpuinfo.rs +++ /dev/null @@ -1,79 +0,0 @@ -use super::*; -use clocksource::precise::UnixInstant; -use std::fs::File; -use std::io::{Read, Seek}; - -pub struct ProcCpuinfo { - file: File, - interval: Interval, -} - -impl ProcCpuinfo { - pub fn new(config: Arc) -> Result { - let file = File::open("/proc/cpuinfo").map_err(|e| { - error!("failed to open /proc/cpuinfo: {e}"); - })?; - - Ok(Self { - file, - interval: Interval::new(Instant::now(), config.interval(NAME)), - }) - } -} - -impl Sampler for ProcCpuinfo { - fn sample(&mut self) { - let now = Instant::now(); - - if let Ok(_) = self.interval.try_wait(now) { - METADATA_CPU_PERF_COLLECTED_AT.set(UnixInstant::EPOCH.elapsed().as_nanos()); - - let _ = self.sample_proc_cpuinfo(); - - let elapsed = now.elapsed().as_nanos() as u64; - METADATA_CPU_PERF_RUNTIME.add(elapsed); - let _ = METADATA_CPU_PERF_RUNTIME_HISTOGRAM.increment(elapsed); - } - } -} - -impl ProcCpuinfo { - fn sample_proc_cpuinfo(&mut self) -> Result<(), std::io::Error> { - self.file.rewind()?; - - let mut data = String::new(); - self.file.read_to_string(&mut data)?; - - let mut online_cores = 0; - - let lines = data.lines(); - - let mut frequency = 0; - - for line in lines { - let parts: Vec<&str> = line.split_whitespace().collect(); - - if let Some(&"processor") = parts.first() { - online_cores += 1; - } - - if let (Some(&"cpu"), Some(&"MHz")) = (parts.first(), parts.get(1)) { - if let Some(Ok(freq)) = parts - .get(3) - .map(|v| v.parse::().map(|v| v.floor() as u64)) - { - let _ = CPU_FREQUENCY_HISTOGRAM.increment(freq); - frequency += freq; - } - } - } - - CPU_CORES.set(online_cores); - - if frequency != 0 && online_cores != 0 { - CPU_FREQUENCY_AVERAGE.set(frequency as i64 / online_cores); - } - - Ok(()) - } -} diff --git a/src/samplers/cpu/linux/usage/bpf.rs b/src/samplers/cpu/linux/usage/bpf.rs index 178747b9..fa5cae77 100644 --- a/src/samplers/cpu/linux/usage/bpf.rs +++ b/src/samplers/cpu/linux/usage/bpf.rs @@ -130,7 +130,7 @@ impl OnlineCores { impl CpuUsage { pub fn new(config: Arc) -> Result { // check if sampler should be enabled - if !(config.enabled(NAME) && config.bpf(NAME)) { + if !config.enabled(NAME) { return Err(()); } diff --git a/src/samplers/cpu/linux/usage/mod.rs b/src/samplers/cpu/linux/usage/mod.rs index 3c05c830..fa11a1eb 100644 --- a/src/samplers/cpu/linux/usage/mod.rs +++ b/src/samplers/cpu/linux/usage/mod.rs @@ -3,37 +3,14 @@ use crate::*; const NAME: &str = "cpu_usage"; -#[cfg(feature = "bpf")] mod bpf; -mod proc_stat; - -#[cfg(feature = "bpf")] use bpf::*; -use proc_stat::*; - -#[cfg(feature = "bpf")] #[distributed_slice(SAMPLERS)] fn init(config: Arc) -> Box { - // try to initialize the bpf based sampler if let Ok(s) = CpuUsage::new(config.clone()) { Box::new(s) - // try to fallback to the /proc/stat based sampler if there was an error - } else if let Ok(s) = ProcStat::new(config) { - Box::new(s) - } else { - Box::new(Nop {}) - } -} - -#[cfg(not(feature = "bpf"))] -#[distributed_slice(SAMPLERS)] -fn init(config: Arc) -> Box { - // try to use the /proc/stat based sampler since BPF was not enabled for - // this build - if let Ok(s) = ProcStat::new(config) { - Box::new(s) } else { Box::new(Nop {}) } diff --git a/src/samplers/cpu/linux/usage/proc_stat.rs b/src/samplers/cpu/linux/usage/proc_stat.rs deleted file mode 100644 index 50be22a5..00000000 --- a/src/samplers/cpu/linux/usage/proc_stat.rs +++ /dev/null @@ -1,182 +0,0 @@ -use crate::common::{Counter, Interval}; -use crate::samplers::cpu::*; -use crate::samplers::hwinfo::hardware_info; -use clocksource::precise::UnixInstant; -use metriken::DynBoxedMetric; -use metriken::MetricBuilder; -use std::fs::File; -use std::io::{Read, Seek}; - -use super::NAME; - -const CPU_IDLE_FIELD_INDEX: usize = 3; -const CPU_IO_WAIT_FIELD_INDEX: usize = 4; - -pub struct ProcStat { - interval: Interval, - nanos_per_tick: u64, - file: File, - total_counters: Vec, - total_busy: Counter, - percpu_counters: Vec>>, - percpu_busy: Vec>, -} - -impl ProcStat { - pub fn new(config: Arc) -> Result { - // check if sampler should be enabled - if !config.enabled(NAME) { - return Err(()); - } - - let cpus = match hardware_info() { - Ok(hwinfo) => hwinfo.get_cpus(), - Err(_) => return Err(()), - }; - - let total_counters = vec![ - Counter::new(&CPU_USAGE_USER, Some(&CPU_USAGE_USER_HISTOGRAM)), - Counter::new(&CPU_USAGE_NICE, Some(&CPU_USAGE_NICE_HISTOGRAM)), - Counter::new(&CPU_USAGE_SYSTEM, Some(&CPU_USAGE_SYSTEM_HISTOGRAM)), - Counter::new(&CPU_USAGE_IDLE, Some(&CPU_USAGE_IDLE_HISTOGRAM)), - Counter::new(&CPU_USAGE_IO_WAIT, Some(&CPU_USAGE_IO_WAIT_HISTOGRAM)), - Counter::new(&CPU_USAGE_IRQ, Some(&CPU_USAGE_IRQ_HISTOGRAM)), - Counter::new(&CPU_USAGE_SOFTIRQ, Some(&CPU_USAGE_SOFTIRQ_HISTOGRAM)), - Counter::new(&CPU_USAGE_STEAL, Some(&CPU_USAGE_STEAL_HISTOGRAM)), - Counter::new(&CPU_USAGE_GUEST, Some(&CPU_USAGE_GUEST_HISTOGRAM)), - Counter::new(&CPU_USAGE_GUEST_NICE, Some(&CPU_USAGE_GUEST_NICE_HISTOGRAM)), - ]; - - let mut percpu_counters = Vec::with_capacity(cpus.len()); - let mut percpu_busy = Vec::new(); - - for cpu in cpus { - let states = [ - "user", - "nice", - "system", - "idle", - "io_wait", - "irq", - "softirq", - "steal", - "guest", - "guest_nice", - ]; - - let counters: Vec> = states - .iter() - .map(|state| { - MetricBuilder::new("cpu/usage") - .metadata("id", format!("{}", cpu.id())) - .metadata("core", format!("{}", cpu.core())) - .metadata("die", format!("{}", cpu.die())) - .metadata("package", format!("{}", cpu.package())) - .metadata("state", *state) - .formatter(cpu_metric_formatter) - .build(metriken::Counter::new()) - }) - .collect(); - - percpu_counters.push(counters); - - percpu_busy.push( - MetricBuilder::new("cpu/usage") - .metadata("id", format!("{}", cpu.id())) - .metadata("core", format!("{}", cpu.core())) - .metadata("die", format!("{}", cpu.die())) - .metadata("package", format!("{}", cpu.package())) - .metadata("state", "busy") - .formatter(cpu_metric_formatter) - .build(metriken::Counter::new()), - ); - } - - let sc_clk_tck = - sysconf::raw::sysconf(sysconf::raw::SysconfVariable::ScClkTck).map_err(|_| { - error!("Failed to get system clock tick rate"); - })?; - - let nanos_per_tick = 1_000_000_000 / (sc_clk_tck as u64); - - Ok(Self { - file: File::open("/proc/stat").expect("file not found"), - total_counters, - total_busy: Counter::new(&CPU_USAGE_BUSY, Some(&CPU_USAGE_BUSY_HISTOGRAM)), - percpu_counters, - percpu_busy, - nanos_per_tick, - interval: Interval::new(Instant::now(), config.interval(NAME)), - }) - } -} - -impl Sampler for ProcStat { - fn sample(&mut self) { - let now = Instant::now(); - - if let Ok(elapsed) = self.interval.try_wait(now) { - METADATA_CPU_USAGE_COLLECTED_AT.set(UnixInstant::EPOCH.elapsed().as_nanos()); - - let _ = self.sample_proc_stat(elapsed.as_secs_f64()); - - let elapsed = now.elapsed().as_nanos() as u64; - METADATA_CPU_USAGE_RUNTIME.add(elapsed); - let _ = METADATA_CPU_USAGE_RUNTIME_HISTOGRAM.increment(elapsed); - } - } -} - -impl ProcStat { - fn sample_proc_stat(&mut self, elapsed: f64) -> Result<(), std::io::Error> { - self.file.rewind()?; - - let mut data = String::new(); - self.file.read_to_string(&mut data)?; - - let lines = data.lines(); - - for line in lines { - let parts: Vec<&str> = line.split_whitespace().collect(); - - if parts.is_empty() { - continue; - } - - let header = parts.first().unwrap(); - - if *header == "cpu" { - let mut busy: u64 = 0; - - for (field, counter) in self.total_counters.iter_mut().enumerate() { - if let Some(Ok(v)) = parts.get(field + 1).map(|v| v.parse::()) { - if field != CPU_IDLE_FIELD_INDEX && field != CPU_IO_WAIT_FIELD_INDEX { - busy = busy.wrapping_add(v); - } - counter.set(elapsed, v.wrapping_mul(self.nanos_per_tick)); - } - - self.total_busy - .set(elapsed, busy.wrapping_mul(self.nanos_per_tick)); - } - } else if header.starts_with("cpu") { - if let Ok(id) = header.replace("cpu", "").parse::() { - let mut busy: u64 = 0; - - for (field, counter) in self.percpu_counters[id].iter_mut().enumerate() { - if let Some(Ok(v)) = parts.get(field + 1).map(|v| v.parse::()) { - if field != CPU_IDLE_FIELD_INDEX && field != CPU_IO_WAIT_FIELD_INDEX { - busy = busy.wrapping_add(v); - } - counter.set(v.wrapping_mul(self.nanos_per_tick)); - } - } - - self.percpu_busy[id].set(busy.wrapping_mul(self.nanos_per_tick)); - } - } - } - - Ok(()) - } -} diff --git a/src/samplers/gpu/nvidia/mod.rs b/src/samplers/gpu/nvidia/mod.rs index a8eb6b71..ede5b580 100644 --- a/src/samplers/gpu/nvidia/mod.rs +++ b/src/samplers/gpu/nvidia/mod.rs @@ -14,7 +14,7 @@ const MHZ: i64 = 1_000_000; #[distributed_slice(ASYNC_SAMPLERS)] fn spawn(config: Arc, runtime: &Runtime) { // check if sampler should be enabled - if !(config.enabled(NAME) && config.bpf(NAME)) { + if !config.enabled(NAME) { return; } diff --git a/src/samplers/network/linux/traffic/bpf.rs b/src/samplers/network/linux/traffic/bpf.rs index 39f08620..822c7a1c 100644 --- a/src/samplers/network/linux/traffic/bpf.rs +++ b/src/samplers/network/linux/traffic/bpf.rs @@ -38,7 +38,7 @@ pub struct NetworkTraffic { impl NetworkTraffic { pub fn new(config: Arc) -> Result { // check if sampler should be enabled - if !(config.enabled(NAME) && config.bpf(NAME)) { + if !config.enabled(NAME) { return Err(()); } diff --git a/src/samplers/network/linux/traffic/mod.rs b/src/samplers/network/linux/traffic/mod.rs index 02034081..e8f77316 100644 --- a/src/samplers/network/linux/traffic/mod.rs +++ b/src/samplers/network/linux/traffic/mod.rs @@ -3,67 +3,13 @@ use crate::samplers::network::linux::*; const NAME: &str = "network_traffic"; -#[cfg(feature = "bpf")] mod bpf; -#[cfg(feature = "bpf")] #[distributed_slice(SAMPLERS)] fn init(config: Arc) -> Box { - // try to initialize the bpf based sampler if let Ok(s) = bpf::NetworkTraffic::new(config.clone()) { Box::new(s) - } else { - if let Ok(s) = NetworkTraffic::new(config) { - Box::new(s) - } else { - Box::new(Nop {}) - } - } -} - -#[cfg(not(feature = "bpf"))] -#[distributed_slice(SAMPLERS)] -fn init(config: Arc) -> Box { - if let Ok(s) = NetworkTraffic::new(config) { - Box::new(s) } else { Box::new(Nop {}) } } - -struct NetworkTraffic { - inner: SysfsNetSampler, - interval: Interval, -} - -impl NetworkTraffic { - pub fn new(config: Arc) -> Result { - let metrics = vec![ - (&NETWORK_RX_BYTES, "rx_bytes"), - (&NETWORK_RX_PACKETS, "rx_packets"), - (&NETWORK_TX_BYTES, "tx_bytes"), - (&NETWORK_TX_PACKETS, "tx_packets"), - ]; - - Ok(Self { - inner: SysfsNetSampler::new(config.clone(), NAME, metrics)?, - interval: Interval::new(Instant::now(), config.interval(NAME)), - }) - } -} - -impl Sampler for NetworkTraffic { - fn sample(&mut self) { - let now = Instant::now(); - - if let Ok(_) = self.interval.try_wait(now) { - METADATA_NETWORK_TRAFFIC_COLLECTED_AT.set(UnixInstant::EPOCH.elapsed().as_nanos()); - - let _ = self.inner.sample_now(); - - let elapsed = now.elapsed().as_nanos() as u64; - METADATA_NETWORK_TRAFFIC_RUNTIME.add(elapsed); - let _ = METADATA_NETWORK_TRAFFIC_RUNTIME_HISTOGRAM.increment(elapsed); - } - } -} diff --git a/src/samplers/scheduler/linux/mod.rs b/src/samplers/scheduler/linux/mod.rs index 45451f20..cb0f5960 100644 --- a/src/samplers/scheduler/linux/mod.rs +++ b/src/samplers/scheduler/linux/mod.rs @@ -1,2 +1 @@ -#[cfg(feature = "bpf")] mod runqueue; diff --git a/src/samplers/scheduler/linux/runqueue/mod.rs b/src/samplers/scheduler/linux/runqueue/mod.rs index 2e2e57eb..a0b0cdcd 100644 --- a/src/samplers/scheduler/linux/runqueue/mod.rs +++ b/src/samplers/scheduler/linux/runqueue/mod.rs @@ -25,7 +25,7 @@ use crate::*; #[distributed_slice(ASYNC_SAMPLERS)] fn spawn(config: Arc, runtime: &Runtime) { // check if sampler should be enabled - if !(config.enabled(NAME) && config.bpf(NAME)) { + if !config.enabled(NAME) { return; } diff --git a/src/samplers/syscall/linux/counts/mod.rs b/src/samplers/syscall/linux/counts/mod.rs index 0670a91e..31373edc 100644 --- a/src/samplers/syscall/linux/counts/mod.rs +++ b/src/samplers/syscall/linux/counts/mod.rs @@ -29,7 +29,7 @@ use crate::*; #[distributed_slice(ASYNC_SAMPLERS)] fn spawn(config: Arc, runtime: &Runtime) { // check if sampler should be enabled - if !(config.enabled(NAME) && config.bpf(NAME)) { + if !config.enabled(NAME) { return; } diff --git a/src/samplers/syscall/linux/latency/mod.rs b/src/samplers/syscall/linux/latency/mod.rs index dd43265e..54a58916 100644 --- a/src/samplers/syscall/linux/latency/mod.rs +++ b/src/samplers/syscall/linux/latency/mod.rs @@ -29,7 +29,7 @@ use crate::*; #[distributed_slice(ASYNC_SAMPLERS)] fn spawn(config: Arc, runtime: &Runtime) { // check if sampler should be enabled - if !(config.enabled(NAME) && config.bpf(NAME)) { + if !config.enabled(NAME) { return; } diff --git a/src/samplers/syscall/linux/mod.rs b/src/samplers/syscall/linux/mod.rs index 0e6a010a..510bd292 100644 --- a/src/samplers/syscall/linux/mod.rs +++ b/src/samplers/syscall/linux/mod.rs @@ -1,7 +1,4 @@ -#[cfg(feature = "bpf")] mod counts; - -#[cfg(feature = "bpf")] mod latency; pub const MAX_SYSCALL_ID: usize = 1024; diff --git a/src/samplers/tcp/linux/mod.rs b/src/samplers/tcp/linux/mod.rs index e25133c1..d25637bc 100644 --- a/src/samplers/tcp/linux/mod.rs +++ b/src/samplers/tcp/linux/mod.rs @@ -1,11 +1,5 @@ mod connection_state; -mod traffic; - -#[cfg(feature = "bpf")] mod packet_latency; - -#[cfg(feature = "bpf")] mod receive; - -#[cfg(feature = "bpf")] mod retransmit; +mod traffic; diff --git a/src/samplers/tcp/linux/packet_latency/mod.rs b/src/samplers/tcp/linux/packet_latency/mod.rs index 491a1bb0..462e4a52 100644 --- a/src/samplers/tcp/linux/packet_latency/mod.rs +++ b/src/samplers/tcp/linux/packet_latency/mod.rs @@ -21,7 +21,7 @@ use crate::samplers::tcp::*; #[distributed_slice(ASYNC_SAMPLERS)] fn spawn(config: Arc, runtime: &Runtime) { // check if sampler should be enabled - if !(config.enabled(NAME) && config.bpf(NAME)) { + if !config.enabled(NAME) { return; } diff --git a/src/samplers/tcp/linux/receive/mod.rs b/src/samplers/tcp/linux/receive/mod.rs index 0168d81b..28f5cce9 100644 --- a/src/samplers/tcp/linux/receive/mod.rs +++ b/src/samplers/tcp/linux/receive/mod.rs @@ -20,7 +20,7 @@ use crate::samplers::tcp::*; #[distributed_slice(ASYNC_SAMPLERS)] fn spawn(config: Arc, runtime: &Runtime) { // check if sampler should be enabled - if !(config.enabled(NAME) && config.bpf(NAME)) { + if !config.enabled(NAME) { return; } diff --git a/src/samplers/tcp/linux/retransmit/mod.rs b/src/samplers/tcp/linux/retransmit/mod.rs index ad2ebc85..dc05c7fb 100644 --- a/src/samplers/tcp/linux/retransmit/mod.rs +++ b/src/samplers/tcp/linux/retransmit/mod.rs @@ -20,7 +20,7 @@ use crate::samplers::tcp::*; #[distributed_slice(ASYNC_SAMPLERS)] fn spawn(config: Arc, runtime: &Runtime) { // check if sampler should be enabled - if !(config.enabled(NAME) && config.bpf(NAME)) { + if !config.enabled(NAME) { return; } diff --git a/src/samplers/tcp/linux/traffic/mod.rs b/src/samplers/tcp/linux/traffic/mod.rs index 0edec57c..8d6d799e 100644 --- a/src/samplers/tcp/linux/traffic/mod.rs +++ b/src/samplers/tcp/linux/traffic/mod.rs @@ -4,21 +4,13 @@ use crate::samplers::tcp::*; const NAME: &str = "tcp_traffic"; -#[cfg(feature = "bpf")] mod bpf { include!(concat!(env!("OUT_DIR"), "/tcp_traffic.bpf.rs")); } -#[cfg(feature = "bpf")] use crate::common::bpf::*; -#[cfg(feature = "bpf")] use bpf::*; -mod proc; - -use proc::*; - -#[cfg(feature = "bpf")] impl GetMap for ModSkel<'_> { fn map(&self, name: &str) -> &libbpf_rs::Map { match name { @@ -30,7 +22,6 @@ impl GetMap for ModSkel<'_> { } } -#[cfg(feature = "bpf")] impl OpenSkelExt for ModSkel<'_> { fn log_prog_instructions(&self) { debug!( @@ -44,11 +35,10 @@ impl OpenSkelExt for ModSkel<'_> { } } -#[cfg(feature = "bpf")] #[distributed_slice(ASYNC_SAMPLERS)] fn spawn(config: Arc, runtime: &Runtime) { // check if sampler should be enabled - if !(config.enabled(NAME) && config.bpf(NAME)) { + if !config.enabled(NAME) { return; } @@ -82,13 +72,5 @@ fn spawn(config: Arc, runtime: &Runtime) { sampler.sample().await; } }); - } else { - runtime.spawn(async move { - if let Ok(mut sampler) = ProcNetSnmp::new(config.async_interval(NAME)) { - loop { - sampler.sample().await; - } - } - }); } } diff --git a/src/samplers/tcp/linux/traffic/proc.rs b/src/samplers/tcp/linux/traffic/proc.rs deleted file mode 100644 index d0ddb4f2..00000000 --- a/src/samplers/tcp/linux/traffic/proc.rs +++ /dev/null @@ -1,60 +0,0 @@ -use crate::common::classic::NestedMap; -use crate::common::*; -use crate::samplers::tcp::stats::*; -use crate::samplers::tcp::*; - -pub struct ProcNetSnmp { - interval: AsyncInterval, - counters: Vec<(Counter, &'static str, &'static str)>, - file: tokio::fs::File, -} - -impl ProcNetSnmp { - pub fn new(interval: AsyncInterval) -> Result { - let counters = vec![ - ( - Counter::new(&TCP_RX_PACKETS, Some(&TCP_RX_PACKETS_HISTOGRAM)), - "Tcp:", - "InSegs", - ), - ( - Counter::new(&TCP_TX_PACKETS, Some(&TCP_TX_PACKETS_HISTOGRAM)), - "Tcp:", - "OutSegs", - ), - ]; - - let file = std::fs::File::open("/proc/net/snmp") - .map(|f| tokio::fs::File::from_std(f)) - .map_err(|e| { - error!("failed to open: /proc/net/snmp error: {e}"); - })?; - - Ok(Self { - interval, - counters, - file, - }) - } -} - -#[async_trait] -impl AsyncSampler for ProcNetSnmp { - async fn sample(&mut self) { - let (now, elapsed) = self.interval.tick().await; - - METADATA_TCP_TRAFFIC_COLLECTED_AT.set(UnixInstant::EPOCH.elapsed().as_nanos()); - - if let Ok(nested_map) = NestedMap::try_from_procfs(&mut self.file).await { - for (counter, pkey, lkey) in self.counters.iter_mut() { - if let Some(curr) = nested_map.get(pkey, lkey) { - counter.set2(elapsed, curr); - } - } - } - - let elapsed = now.elapsed().as_nanos() as u64; - METADATA_TCP_TRAFFIC_RUNTIME.add(elapsed); - let _ = METADATA_TCP_TRAFFIC_RUNTIME_HISTOGRAM.increment(elapsed); - } -}