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.

56 lines
1.7KB

  1. #[macro_use]
  2. extern crate slog;
  3. use std::sync::Arc;
  4. use std::sync::atomic::{AtomicBool, Ordering};
  5. use std::time::*;
  6. use std::thread;
  7. use slog::Drain;
  8. use pretty_toa::ThousandsSep;
  9. use chrono::prelude::*;
  10. use influx_writer::{InfluxWriter, measure};
  11. const DELAY: Duration = Duration::from_millis(1);
  12. const N_PER: usize = 567;
  13. fn main() {
  14. let start = Instant::now();
  15. let term = Arc::new(AtomicBool::new(false));
  16. signal_hook::flag::register(signal_hook::consts::signal::SIGINT, Arc::clone(&term)).unwrap();
  17. signal_hook::flag::register(signal_hook::consts::signal::SIGTERM, Arc::clone(&term)).unwrap();
  18. signal_hook::flag::register(signal_hook::consts::signal::SIGQUIT, Arc::clone(&term)).unwrap();
  19. let decorator = slog_term::TermDecorator::new().stdout().force_color().build();
  20. let drain = slog_term::FullFormat::new(decorator).use_utc_timestamp().build().fuse();
  21. let drain = slog_async::Async::new(drain).chan_size(1024 * 64).thread_name("recv".into()).build().fuse();
  22. let root = slog::Logger::root(drain, o!("version" => "0.1"));
  23. let logger = root.new(o!("thread" => "main"));
  24. let influx = InfluxWriter::with_logger_and_opt_creds("localhost", "test", None, &root);
  25. let mut n = 0;
  26. loop {
  27. if term.load(Ordering::Relaxed) {
  28. info!(logger, "exiting...");
  29. break
  30. }
  31. let mut now = Utc::now().timestamp_nanos();
  32. for _ in 0..N_PER {
  33. measure!(influx, example, i(n, 1), tm(now));
  34. now += 1;
  35. n += 1;
  36. }
  37. thread::sleep(DELAY);
  38. }
  39. drop(influx);
  40. let took = Instant::now() - start;
  41. info!(logger, "wrote {} measurements in {:?}", n.thousands_sep(), took);
  42. }