-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from maxmindlin/feature/metrics
Feature/metrics
- Loading branch information
Showing
8 changed files
with
186 additions
and
9 deletions.
There are no files selected for viewing
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,23 @@ | ||
[global_tags] | ||
|
||
[agent] | ||
interval = "1s" | ||
round_interval = true | ||
metric_batch_size = 1000 | ||
metric_buffer_limit = 200000 | ||
collection_jitter = "0s" | ||
flush_interval = "10s" | ||
flush_jitter = "0s" | ||
precision = "1s" | ||
debug = true | ||
|
||
[[outputs.influxdb_v2]] | ||
urls = ["http://influxdb:8086"] | ||
bucket = "${DOCKER_INFLUXDB_INIT_BUCKET}" | ||
organization = "${DOCKER_INFLUXDB_INIT_ORG}" | ||
token = "${DOCKER_INFLUXDB_INIT_ADMIN_TOKEN}" | ||
timeout = "40s" | ||
|
||
[[inputs.socket_listener]] | ||
## Address and port to host HTTP listener on | ||
service_address = "tcp://${TELEGRAFCLIENT_HOST}:${TELEGRAFCLIENT_PORT}" |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use telegraf::Metric; | ||
|
||
#[derive(Debug)] | ||
pub enum MetricsError { | ||
WriteError(String), | ||
} | ||
|
||
pub trait MetricClient { | ||
fn send_proxy_metric(&mut self, metric: &ProxyMetric) -> Result<(), MetricsError>; | ||
} | ||
|
||
#[derive(Metric)] | ||
#[measurement = "proxy_metrics"] | ||
pub struct ProxyMetric { | ||
#[telegraf(tag)] | ||
pub domain: String, | ||
#[telegraf(tag)] | ||
pub proxy_id: i32, | ||
pub response_time: u32, | ||
pub status: u16, | ||
} | ||
|
||
pub struct TelegrafClient { | ||
client: telegraf::Client, | ||
} | ||
|
||
impl TelegrafClient { | ||
pub fn new(addr: &str) -> Self { | ||
Self { | ||
client: telegraf::Client::new(addr).unwrap(), | ||
} | ||
} | ||
} | ||
|
||
impl MetricClient for TelegrafClient { | ||
fn send_proxy_metric(&mut self, metric: &ProxyMetric) -> Result<(), MetricsError> { | ||
if let Err(e) = self.client.write(metric) { | ||
return Err(MetricsError::WriteError(e.to_string())); | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
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