-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* experimental log * introduce wireguard metrics updates * add wireguard traffic rates to console logger * missing import * changed order of displayed values * expose bytes information via rest endpoint * clippy
- Loading branch information
Showing
14 changed files
with
199 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2024 - Nym Technologies SA <contact@nymtech.net> | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use std::sync::atomic::{AtomicUsize, Ordering}; | ||
|
||
#[derive(Default)] | ||
pub struct WireguardStats { | ||
bytes_rx: AtomicUsize, | ||
bytes_tx: AtomicUsize, | ||
|
||
total_peers: AtomicUsize, | ||
active_peers: AtomicUsize, | ||
} | ||
|
||
impl WireguardStats { | ||
pub fn bytes_rx(&self) -> usize { | ||
self.bytes_rx.load(Ordering::Relaxed) | ||
} | ||
|
||
pub fn bytes_tx(&self) -> usize { | ||
self.bytes_tx.load(Ordering::Relaxed) | ||
} | ||
|
||
pub fn total_peers(&self) -> usize { | ||
self.total_peers.load(Ordering::Relaxed) | ||
} | ||
|
||
pub fn active_peers(&self) -> usize { | ||
self.active_peers.load(Ordering::Relaxed) | ||
} | ||
|
||
pub fn update( | ||
&self, | ||
bytes_rx: usize, | ||
bytes_tx: usize, | ||
total_peers: usize, | ||
active_peers: usize, | ||
) { | ||
self.bytes_rx.store(bytes_rx, Ordering::Relaxed); | ||
self.bytes_tx.store(bytes_tx, Ordering::Relaxed); | ||
self.total_peers.store(total_peers, Ordering::Relaxed); | ||
self.active_peers.store(active_peers, Ordering::Relaxed); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2024 - Nym Technologies SA <contact@nymtech.net> | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
use crate::node::http::state::metrics::MetricsAppState; | ||
use axum::extract::{Query, State}; | ||
use nym_http_api_common::{FormattedResponse, OutputParams}; | ||
use nym_node_metrics::NymNodeMetrics; | ||
use nym_node_requests::api::v1::metrics::models::WireguardStats; | ||
|
||
/// If applicable, returns wireguard statistics information of this node. | ||
/// This information is **PURELY** self-reported and in no way validated. | ||
#[utoipa::path( | ||
get, | ||
path = "/wireguard-stats", | ||
context_path = "/api/v1/metrics", | ||
tag = "Metrics", | ||
responses( | ||
(status = 200, content( | ||
("application/json" = WireguardStats), | ||
("application/yaml" = WireguardStats) | ||
)) | ||
), | ||
params(OutputParams), | ||
)] | ||
pub(crate) async fn wireguard_stats( | ||
Query(output): Query<OutputParams>, | ||
State(metrics_state): State<MetricsAppState>, | ||
) -> WireguardStatsResponse { | ||
let output = output.output.unwrap_or_default(); | ||
output.to_response(build_response(&metrics_state.metrics)) | ||
} | ||
|
||
fn build_response(metrics: &NymNodeMetrics) -> WireguardStats { | ||
WireguardStats { | ||
bytes_tx: metrics.wireguard.bytes_tx(), | ||
bytes_rx: metrics.wireguard.bytes_rx(), | ||
} | ||
} | ||
|
||
pub type WireguardStatsResponse = FormattedResponse<WireguardStats>; |
Oops, something went wrong.