summaryrefslogtreecommitdiffstats
path: root/rust/src/bin/fatcatd.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rust/src/bin/fatcatd.rs')
-rw-r--r--rust/src/bin/fatcatd.rs29
1 files changed, 28 insertions, 1 deletions
diff --git a/rust/src/bin/fatcatd.rs b/rust/src/bin/fatcatd.rs
index 388c6e61..df5c390e 100644
--- a/rust/src/bin/fatcatd.rs
+++ b/rust/src/bin/fatcatd.rs
@@ -15,6 +15,9 @@ use iron_slog::{DefaultLogFormatter, LoggerMiddleware};
use sentry::integrations::panic;
use slog::{Drain, Logger};
use std::env;
+use cadence::{StatsdClient, QueuingMetricSink, BufferedUdpMetricSink};
+use cadence::prelude::*;
+use std::net::UdpSocket;
// HTTP header middleware
header! { (XClacksOverhead, "X-Clacks-Overhead") => [String] }
@@ -29,6 +32,7 @@ impl AfterMiddleware for XClacksOverheadMiddleware {
}
}
+
/// Create custom server, wire it to the autogenerated router,
/// and pass it to the web server.
fn main() -> Result<()> {
@@ -60,7 +64,30 @@ fn main() -> Result<()> {
None
};
- let server = create_server()?;
+ let mut server = create_server()?;
+
+ // metrics reporting
+ match env::var("FATCAT_STATSD_HOST") {
+ Err(_) => {
+ info!(logger, "no metrics recipient configured");
+ },
+ Ok(host) => {
+ let port: u16 = match env::var("FATCAT_STATSD_PORT") {
+ Err(_) => cadence::DEFAULT_PORT,
+ Ok(var) => var.parse::<u16>()?, // "expect FATCAT_STATSD_PORT to be null or an integer
+ };
+ let socket = UdpSocket::bind("0.0.0.0:0").unwrap();
+ socket.set_nonblocking(true).unwrap();
+ let udp_sink = BufferedUdpMetricSink::from((host.as_ref(), port), socket).unwrap();
+ let queuing_sink = QueuingMetricSink::from(udp_sink);
+ info!(logger, "sending statsd metrics via UDP to: {}:{}", host, port);
+ server.metrics = StatsdClient::from_sink("fatcat.api", queuing_sink);
+ //server.metrics = StatsdClient::from_udp_host("fatcat.api", (host.as_ref(), port))?;
+ server.metrics.incr("restart").unwrap();
+ }
+ };
+ info!(logger, "{:#?}", server.metrics);
+
info!(
logger,
"using primary auth key: {}", server.auth_confectionary.identifier,