Skip to content

Commit

Permalink
blocked -> denied
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernauer committed May 30, 2024
1 parent 056f793 commit 1aface0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ All notable changes to this project will be documented in this file.
### Added

- Try to improve performance by calling `madvise` to inform Kernel we are reading sequentially ([#24])
- Expose metric on dropped connection counts ([#26])
- Expose metric on denied connection counts ([#26])

### Changed

Expand Down
18 changes: 9 additions & 9 deletions breakwater/src/prometheus_exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub struct PrometheusExporter {
metric_statistic_events: IntGauge,

metric_connections_for_ip: IntGaugeVec,
metric_blocked_connections_for_ip: IntGaugeVec,
metric_denied_connections_for_ip: IntGaugeVec,
metric_bytes_for_ip: IntGaugeVec,
}

Expand Down Expand Up @@ -72,9 +72,9 @@ impl PrometheusExporter {
"Number of client connections per IP address",
&["ip"],
)?,
metric_blocked_connections_for_ip: register_int_gauge_vec(
"breakwater_blocked_connections",
"Number of blocked connections per IP address because it tried to open too many connections",
metric_denied_connections_for_ip: register_int_gauge_vec(
"breakwater_denied_connections",
"Number of denied connections per IP address because it tried to open too many connections",
&["ip"],
)?,
metric_bytes_for_ip: register_int_gauge_vec(
Expand Down Expand Up @@ -104,14 +104,14 @@ impl PrometheusExporter {
.with_label_values(&[&ip.to_string()])
.set(*connections as i64)
});
self.metric_blocked_connections_for_ip.reset();
self.metric_denied_connections_for_ip.reset();
event
.blocked_connections_for_ip
.denied_connections_for_ip
.iter()
.for_each(|(ip, blocked)| {
self.metric_blocked_connections_for_ip
.for_each(|(ip, denied)| {
self.metric_denied_connections_for_ip
.with_label_values(&[&ip.to_string()])
.set(*blocked as i64)
.set(*denied as i64)
});
self.metric_bytes_for_ip.reset();
event.bytes_for_ip.iter().for_each(|(ip, bytes)| {
Expand Down
10 changes: 5 additions & 5 deletions breakwater/src/statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub struct StatisticsInformationEvent {
pub bytes_per_s: u64,

pub connections_for_ip: HashMap<IpAddr, u32>,
pub blocked_connections_for_ip: HashMap<IpAddr, u32>,
pub denied_connections_for_ip: HashMap<IpAddr, u32>,
pub bytes_for_ip: HashMap<IpAddr, u64>,

pub statistic_events: u64,
Expand All @@ -77,7 +77,7 @@ pub struct Statistics {

frame: u64,
connections_for_ip: HashMap<IpAddr, u32>,
blocked_connections_for_ip: HashMap<IpAddr, u32>,
denied_connections_for_ip: HashMap<IpAddr, u32>,
bytes_for_ip: HashMap<IpAddr, u64>,

bytes_per_s_window: SingleSumSMA<u64, u64, STATS_SLIDING_WINDOW_SIZE>,
Expand Down Expand Up @@ -118,7 +118,7 @@ impl Statistics {
statistic_events: 0,
frame: 0,
connections_for_ip: HashMap::new(),
blocked_connections_for_ip: HashMap::new(),
denied_connections_for_ip: HashMap::new(),
bytes_for_ip: HashMap::new(),
bytes_per_s_window: SingleSumSMA::new(),
fps_window: SingleSumSMA::new(),
Expand Down Expand Up @@ -158,7 +158,7 @@ impl Statistics {
}
}
StatisticsEvent::ConnectionDenied { ip } => {
*self.blocked_connections_for_ip.entry(ip).or_insert(0) += 1;
*self.denied_connections_for_ip.entry(ip).or_insert(0) += 1;
}
StatisticsEvent::BytesRead { ip, bytes } => {
*self.bytes_for_ip.entry(ip).or_insert(0) += bytes;
Expand Down Expand Up @@ -225,7 +225,7 @@ impl Statistics {
fps: self.fps_window.get_average(),
bytes_per_s: self.bytes_per_s_window.get_average(),
connections_for_ip: self.connections_for_ip.clone(),
blocked_connections_for_ip: self.blocked_connections_for_ip.clone(),
denied_connections_for_ip: self.denied_connections_for_ip.clone(),
bytes_for_ip: self.bytes_for_ip.clone(),
statistic_events,
}
Expand Down

0 comments on commit 1aface0

Please sign in to comment.