Skip to content

Commit

Permalink
Add default config values, add Wg connections metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
the2pizza committed Oct 14, 2024
1 parent 6b87f24 commit b389cd1
Show file tree
Hide file tree
Showing 14 changed files with 393 additions and 137 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
target
pony.log
92 changes: 89 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ log = "0.4"
fern = "0.6"
chrono = "0.4"
reqwest = "0.12"
toml = "0.7"
futures = "0.3"

25 changes: 16 additions & 9 deletions config.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
[carbon]
address = "10.0.0.1:2003"
#address = "10.0.0.1:2003"

[app]
env = "dev"
hostname = "localhost"
#env = "dev"
#hostname = "localhost"
iface = "en0"
xray_vmess_port = 8081
xray_vless_port = 2053
xray_ss_port = 1080
metrics_delay = 1
#metrics_delay = 1

[xray]
enabled = true
vmess_port = 8081
vless_port = 2053
ss_port = 1080

[wg]
enabled = true
#port = 51820

[logging]
level = "info"
file = "pony.log"
#level = "info"
#file = "pony.log"

16 changes: 8 additions & 8 deletions src/bandwidth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use log::info;
use std::{fmt, thread, time};
use sysinfo::Networks;

use crate::config2::AppConfig;
use crate::config2::Settings;
use crate::metrics::{AsMetric, Metric};
use crate::utils::{current_timestamp, send_to_carbon};

Expand Down Expand Up @@ -38,10 +38,10 @@ impl fmt::Display for Bandwidth {
impl AsMetric for Bandwidth {
type Output = u64;

fn as_metric(&self, interface: &str, settings: AppConfig) -> Vec<Metric<u64>> {
fn as_metric(&self, interface: &str, settings: Settings) -> Vec<Metric<u64>> {
let timestamp = current_timestamp();
let h = &settings.hostname;
let env = &settings.env;
let h = &settings.app.hostname;
let env = &settings.app.env;

vec![
Metric {
Expand All @@ -68,15 +68,15 @@ impl AsMetric for Bandwidth {
}
}

pub async fn bandwidth_metrics(server: String, settings: AppConfig) {
pub async fn bandwidth_metrics(server: String, settings: Settings) {
info!("Starting bandwidth metric loop");
let mut networks = Networks::new_with_refreshed_list();

loop {
let _ = networks.refresh();
let res = networks
.iter()
.find(|&(interface, _)| interface == &settings.iface);
.find(|&(interface, _)| interface == &settings.app.iface);

match res {
Some((interface, data)) => {
Expand All @@ -92,8 +92,8 @@ pub async fn bandwidth_metrics(server: String, settings: AppConfig) {
let _ = send_to_carbon(&metric, &server).await;
}
}
None => println!("Interface '{}' not found.", &settings.iface),
None => println!("Interface '{}' not found.", &settings.app.iface),
}
thread::sleep(time::Duration::from_secs(settings.metrics_delay));
thread::sleep(time::Duration::from_secs(settings.app.metrics_delay));
}
}
Loading

0 comments on commit b389cd1

Please sign in to comment.