Skip to content

Commit

Permalink
add config options to disable bpf samplers (#258)
Browse files Browse the repository at this point in the history
Adds config options to enable/disable bpf samplers. This can be set
on a per-sampler basis, or globally, and enables better control
when a sampler can get some data without bpf.
  • Loading branch information
brayniac authored May 9, 2024
1 parent 524dbbd commit 939f37e
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 26 deletions.
27 changes: 19 additions & 8 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ 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 counter and gauge based metrics. Shorter intervals
# allow for more accurately capturing bursts in the related percentile metrics.
interval = "10ms"
Expand All @@ -73,9 +77,11 @@ enabled = true
[samplers.cpu_perf]
enabled = true

# Instruments CPU usage by state by reading /proc/stat
[samplers.cpu_proc_stat]
# Instruments CPU usage by state with BPF or by reading /proc/stat on linux
# On macos host_processor_info() is used
[samplers.cpu_usage]
enabled = true
bpf = true

# Produces various nVIDIA specific GPU metrics using NVML
[samplers.gpu_nvidia]
Expand All @@ -89,6 +95,14 @@ enabled = true
[samplers.memory_vmstat]
enabled = true

# Produces network interface statistics from /sys/class/net for TX/RX errors
[samplers.network_interfaces]
enabled = true

# Produces network traffic statistics using BPF
[samplers.network_traffic]
enabled = true

# Sample resource utilization for Rezolus itself
[samplers.rezolus_rusage]
enabled = true
Expand Down Expand Up @@ -126,11 +140,8 @@ enabled = true
[samplers.tcp_retransmit]
enabled = true

# TCP sampler that reads from /proc/snmp
[samplers.tcp_snmp]
enabled = true

# BPF sampler that probes TCP send and receive paths to instrument tx/rx size
# distribution, bytes, and packets.
# Samples TCP traffic using either a BPF sampler or /proc/net/snmp to provide
# metrics for TX/RX bytes and packets
[samplers.tcp_traffic]
enabled = true
bpf = true
24 changes: 14 additions & 10 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,20 @@ impl Config {
&self.prometheus
}

#[cfg(feature = "bpf")]
pub fn bpf(&self) -> bool {
true
}

#[cfg(not(feature = "bpf"))]
pub fn bpf(&self) -> bool {
false
}

pub fn enabled(&self, name: &str) -> bool {
self.samplers
.get(name)
.map(|c| c.enabled())
.unwrap_or(self.defaults.enabled())
}

pub fn bpf(&self, name: &str) -> bool {
self.samplers
.get(name)
.map(|c| c.bpf())
.unwrap_or(self.defaults.bpf())
}

pub fn interval(&self, name: &str) -> Duration {
self.samplers
.get(name)
Expand Down Expand Up @@ -224,6 +221,8 @@ pub fn distribution_interval() -> String {
pub struct SamplerConfig {
#[serde(default = "enabled")]
enabled: bool,
#[serde(default = "enabled")]
bpf: bool,
#[serde(default = "interval")]
interval: String,
#[serde(default = "distribution_interval")]
Expand All @@ -234,6 +233,7 @@ impl Default for SamplerConfig {
fn default() -> Self {
Self {
enabled: true,
bpf: true,
interval: interval(),
distribution_interval: distribution_interval(),
}
Expand Down Expand Up @@ -268,6 +268,10 @@ impl SamplerConfig {
self.enabled
}

pub fn bpf(&self) -> bool {
self.bpf
}

pub fn interval(&self) -> Duration {
Duration::from_nanos(
self.interval
Expand Down
2 changes: 1 addition & 1 deletion src/samplers/block_io/linux/latency/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub struct Biolat {
impl Biolat {
pub fn new(config: &Config) -> Result<Self, ()> {
// check if sampler should be enabled
if !config.enabled(NAME) {
if !(config.enabled(NAME) && config.bpf(NAME)) {
return Err(());
}

Expand Down
5 changes: 5 additions & 0 deletions src/samplers/cpu/linux/usage/bpf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ pub struct CpuUsage {
const IDLE_CPUTIME_INDEX: usize = 5;
impl CpuUsage {
pub fn new(config: &Config) -> Result<Self, ()> {
// check if sampler should be enabled
if !(config.enabled(NAME) && config.bpf(NAME)) {
return Err(());
}

let builder = ModSkelBuilder::default();
let mut skel = builder
.open()
Expand Down
2 changes: 1 addition & 1 deletion src/samplers/network/linux/traffic/bpf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub struct NetworkTraffic {
impl NetworkTraffic {
pub fn new(config: &Config) -> Result<Self, ()> {
// check if sampler should be enabled
if !config.enabled(NAME) {
if !(config.enabled(NAME) && config.bpf(NAME)) {
return Err(());
}

Expand Down
2 changes: 1 addition & 1 deletion src/samplers/scheduler/linux/runqueue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub struct Runqlat {
impl Runqlat {
pub fn new(config: &Config) -> Result<Self, ()> {
// check if sampler should be enabled
if !config.enabled(NAME) {
if !(config.enabled(NAME) && config.bpf(NAME)) {
return Err(());
}

Expand Down
2 changes: 1 addition & 1 deletion src/samplers/syscall/linux/latency/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub struct Syscall {
impl Syscall {
pub fn new(config: &Config) -> Result<Self, ()> {
// check if sampler should be enabled
if !config.enabled(NAME) {
if !(config.enabled(NAME) && config.bpf(NAME)) {
return Err(());
}

Expand Down
2 changes: 1 addition & 1 deletion src/samplers/tcp/linux/packet_latency/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub struct PacketLatency {
impl PacketLatency {
pub fn new(config: &Config) -> Result<Self, ()> {
// check if sampler should be enabled
if !config.enabled(NAME) {
if !(config.enabled(NAME) && config.bpf(NAME)) {
return Err(());
}

Expand Down
2 changes: 1 addition & 1 deletion src/samplers/tcp/linux/receive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub struct Receive {
impl Receive {
pub fn new(config: &Config) -> Result<Self, ()> {
// check if sampler should be enabled
if !config.enabled(NAME) {
if !(config.enabled(NAME) && config.bpf(NAME)) {
return Err(());
}

Expand Down
2 changes: 1 addition & 1 deletion src/samplers/tcp/linux/retransmit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub struct Retransmit {
impl Retransmit {
pub fn new(config: &Config) -> Result<Self, ()> {
// check if sampler should be enabled
if !config.enabled(NAME) {
if !(config.enabled(NAME) && config.bpf(NAME)) {
return Err(());
}

Expand Down
2 changes: 1 addition & 1 deletion src/samplers/tcp/linux/traffic/bpf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub struct TcpTraffic {
impl TcpTraffic {
pub fn new(config: &Config) -> Result<Self, ()> {
// check if sampler should be enabled
if !config.enabled(NAME) {
if !(config.enabled(NAME) && config.bpf(NAME)) {
return Err(());
}

Expand Down

0 comments on commit 939f37e

Please sign in to comment.