From 9fe210c454f39feb9abbbdc26d7a24b0642fffe8 Mon Sep 17 00:00:00 2001 From: Sathish <44555499+sambley@users.noreply.github.com> Date: Tue, 13 Nov 2018 21:54:15 -0800 Subject: [PATCH] Add host information to db entries (#1778) Add new field to each db entry identifying the host that it originated from. --- Cargo.toml | 1 + src/lib.rs | 2 ++ src/metrics.rs | 13 ++++++++----- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 98be14250..17900bda0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -109,6 +109,7 @@ sys-info = "0.5.6" tokio = "0.1" tokio-codec = "0.1" untrusted = "0.6.2" +lazy_static = "1.2.0" solana-bpfloader = { path = "programs/native/bpf_loader", version = "0.11.0" } solana-erc20 = { path = "programs/native/erc20", version = "0.11.0" } solana-lualoader = { path = "programs/native/lua_loader", version = "0.11.0" } diff --git a/src/lib.rs b/src/lib.rs index 7f2daa5b7..2b7f4459e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -123,6 +123,8 @@ extern crate sys_info; extern crate tokio; extern crate tokio_codec; extern crate untrusted; +#[macro_use] +extern crate lazy_static; #[cfg(test)] #[macro_use] diff --git a/src/metrics.rs b/src/metrics.rs index 24c6e50a5..de5be7337 100644 --- a/src/metrics.rs +++ b/src/metrics.rs @@ -3,14 +3,18 @@ extern crate reqwest; use influx_db_client as influxdb; +use rand; use std::env; use std::sync::mpsc::{channel, Receiver, RecvTimeoutError, Sender}; use std::sync::{Arc, Barrier, Mutex, Once, ONCE_INIT}; use std::thread; use std::time::{Duration, Instant}; -use sys_info::hostname; use timing; +lazy_static! { + static ref HOST_ID: i64 = rand::random::(); +} + #[derive(Debug)] enum MetricsCommand { Submit(influxdb::Point), @@ -131,6 +135,7 @@ impl MetricsAgent { } pub fn submit(&self, mut point: influxdb::Point) { + point.add_field("host_id", influxdb::Value::Integer(*HOST_ID)); if point.timestamp.is_none() { point.timestamp = Some(timing::timestamp() as i64); } @@ -237,10 +242,8 @@ pub fn set_panic_hook(program: &'static str) { Some(location) => location.to_string(), None => "?".to_string(), }), - ).add_field( - "host", - influxdb::Value::String(hostname().unwrap_or_else(|_| "?".to_string())), - ).to_owned(), + ).add_field("host_id", influxdb::Value::Integer(*HOST_ID)) + .to_owned(), ); // Flush metrics immediately in case the process exits immediately // upon return