summaryrefslogtreecommitdiffstats
path: root/rust/src/bin
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2019-01-10 16:09:50 -0800
committerBryan Newbold <bnewbold@robocracy.org>2019-01-10 16:09:50 -0800
commit60d39b2f9923bf1b9d659f2f4dad223ec565466a (patch)
treeb992730fe230bec74744db4babd3f1eff83f180b /rust/src/bin
parent5a31f1181e9a86aa91e95be87ac386731ce219cd (diff)
downloadfatcat-60d39b2f9923bf1b9d659f2f4dad223ec565466a.tar.gz
fatcat-60d39b2f9923bf1b9d659f2f4dad223ec565466a.zip
crude metrics integration (only a handful for now)
Diffstat (limited to 'rust/src/bin')
-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,