You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

precipice.rs 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #![allow(unused_imports)]
  2. #[macro_use]
  3. extern crate slog;
  4. #[macro_use]
  5. extern crate logging;
  6. use std::io::{self, prelude::*};
  7. use std::thread;
  8. use std::sync::{Arc, atomic::{AtomicBool, Ordering}};
  9. use std::time::*;
  10. use chrono::Utc;
  11. use slog::Drain;
  12. use pretty_toa::ThousandsSep;
  13. use logging::influx::InfluxWriter;
  14. const INTERVAL: Duration = Duration::from_micros(1); //from_millis(1);
  15. const HB_EVERY: usize = 1_000_000;
  16. fn main() {
  17. let to_file = logging::truncating_file_logger("var/log/precipice.log", sloggers::types::Severity::Debug);
  18. let decorator = slog_term::TermDecorator::new().stdout().force_color().build();
  19. let drain = slog_term::CompactFormat::new(decorator).use_utc_timestamp().build().fuse();
  20. let drain = slog_async::Async::new(drain).chan_size(8192).thread_name("recv".into()).build().fuse();
  21. let drain = slog::Duplicate::new(drain, to_file).fuse();
  22. let root = slog::Logger::root(drain, o!());
  23. let logger = root.new(o!("thread" => "main"));
  24. info!(logger, "initializing...");
  25. let influx = InfluxWriter::with_logger("localhost", "precipice", 1024, root.new(o!("thread" => "InfluxWriter")));
  26. let stop = Arc::new(AtomicBool::new(false));
  27. let thread = {
  28. let stop = Arc::clone(&stop);
  29. let logger = root.new(o!("thread" => "blaster"));
  30. let influx = influx.clone();
  31. thread::spawn(move || {
  32. let mut i = 0;
  33. let mut sum = 0;
  34. while !stop.load(Ordering::Relaxed) {
  35. measure!(influx, xs, i(i), tm(logging::inanos(Utc::now())));
  36. sum += i;
  37. i += 1;
  38. if i % HB_EVERY == 0 {
  39. info!(logger, "sent {} measurements", i.thousands_sep());
  40. }
  41. thread::sleep(INTERVAL);
  42. }
  43. info!(logger, "exiting"; "n_sent" => i, "sum" => sum);
  44. })
  45. };
  46. let mut keys = String::new();
  47. loop {
  48. if let Ok(_) = io::stdin().read_line(&mut keys) {
  49. break
  50. }
  51. thread::sleep(Duration::from_millis(1));
  52. }
  53. stop.store(true, Ordering::Relaxed);
  54. let _ = thread.join();
  55. }