Skip to content

Commit

Permalink
drop unique, checl all connections, 0.0.19
Browse files Browse the repository at this point in the history
  • Loading branch information
the2pizza committed Oct 29, 2024
1 parent f2c2f22 commit 70e0f7e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 28 deletions.
2 changes: 1 addition & 1 deletion 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
@@ -1,6 +1,6 @@
[package]
name = "pony"
version = "0.0.18"
version = "0.0.19"
edition = "2021"

[dependencies]
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
## Pony - monitoring agent for Xray/Wiregard
(pony means ponytoring)

Collects metrics on lowlevel and sends to Carbon

Collects metrics on lowlevel and sends to Carbon



Works with [carbon-clickhouse](https://github.com/frkn-dev/graphite-clickhouse-tldr) stack

Expand Down
31 changes: 8 additions & 23 deletions src/connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,6 @@ impl AsMetric for WgConnections {
}
}

fn filter_unique_by_remote_addr(connections: &HashSet<ConnectionInfo>) -> HashSet<ConnectionInfo> {
let mut seen_remote_addrs = HashSet::new();

connections
.iter()
.filter(|conn| seen_remote_addrs.insert(&conn.remote_addr))
.cloned()
.collect()
}

fn port_connections_data(target_port: u16) -> HashSet<ConnectionInfo> {
let mut connections = HashSet::new();

Expand Down Expand Up @@ -167,18 +157,13 @@ pub async fn connections_metric(server: String, settings: Settings) {

if settings.xray.enabled {
let vmess_connections = port_connections_data(settings.xray.vmess_port);
let unique_vmess_connections = filter_unique_by_remote_addr(&vmess_connections);

let vless_data_connections = port_connections_data(settings.xray.vless_port);
let unique_vless_connections = filter_unique_by_remote_addr(&vless_data_connections);

let ss_data_connections = port_connections_data(settings.xray.ss_port);
let unique_ss_connections = filter_unique_by_remote_addr(&ss_data_connections);
let vless_connections = port_connections_data(settings.xray.vless_port);
let ss_connections = port_connections_data(settings.xray.ss_port);

let xray_connections = XrayConnections {
vmess: unique_vmess_connections.len() as u64,
vless: unique_vless_connections.len() as u64,
ss: unique_ss_connections.len() as u64,
vmess: vmess_connections.len() as u64,
vless: vless_connections.len() as u64,
ss: ss_connections.len() as u64,
};

for metric in xray_connections.as_metric("connections", settings.clone()) {
Expand All @@ -189,19 +174,19 @@ pub async fn connections_metric(server: String, settings: Settings) {

tasks.push(tokio::spawn(send_to_carbon_country_metric(
settings.clone(),
unique_vmess_connections.clone(),
vmess_connections.clone(),
"vmess",
server.clone(),
)));
tasks.push(tokio::spawn(send_to_carbon_country_metric(
settings.clone(),
unique_vless_connections.clone(),
vless_connections.clone(),
"vless",
server.clone(),
)));
tasks.push(tokio::spawn(send_to_carbon_country_metric(
settings.clone(),
unique_ss_connections.clone(),
ss_connections.clone(),
"ss",
server.clone(),
)));
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use crate::web::not_found;

#[derive(Parser)]
#[command(
version = "0.0.18",
version = "0.0.19",
about = "Pony - montiroing tool for Xray/Wireguard"
)]
struct Cli {
Expand Down Expand Up @@ -77,7 +77,7 @@ async fn main() -> std::io::Result<()> {
std::process::exit(1);
} else {
info!(">>> Settings: {:?}", settings);
info!(">>> Version: 0.0.18");
info!(">>> Version: 0.0.19");
}

let carbon_server = settings.carbon.address.clone();
Expand Down

0 comments on commit 70e0f7e

Please sign in to comment.