Use hostname in database if env is set (#2101)
This commit is contained in:
@ -9,9 +9,9 @@ license = "Apache-2.0"
|
||||
[dependencies]
|
||||
influx_db_client = "0.3.6"
|
||||
log = "0.4.2"
|
||||
rand = "0.6.1"
|
||||
reqwest = "0.9.0"
|
||||
lazy_static = "1.2.0"
|
||||
sys-info = "0.5.6"
|
||||
solana-sdk = { path = "../sdk", version = "0.11.0" }
|
||||
|
||||
[lib]
|
||||
|
@ -1,11 +1,11 @@
|
||||
pub extern crate influx_db_client;
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
extern crate rand;
|
||||
extern crate reqwest;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
extern crate solana_sdk;
|
||||
extern crate sys_info;
|
||||
|
||||
mod metrics;
|
||||
pub use metrics::flush;
|
||||
|
@ -3,16 +3,27 @@
|
||||
extern crate reqwest;
|
||||
|
||||
use influx_db_client as influxdb;
|
||||
use rand;
|
||||
use solana_sdk::hash::hash;
|
||||
use solana_sdk::timing;
|
||||
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;
|
||||
|
||||
lazy_static! {
|
||||
static ref HOST_ID: i64 = rand::random::<i64>();
|
||||
static ref HOST_INFO: String = {
|
||||
let v = env::var("SOLANA_METRICS_DISPLAY_HOSTNAME")
|
||||
.map(|x| x.parse().unwrap_or(0))
|
||||
.unwrap_or(0);
|
||||
let name: String = hostname().unwrap_or_else(|_| "".to_string());
|
||||
if v == 0 {
|
||||
hash(name.as_bytes()).to_string()
|
||||
} else {
|
||||
name
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -135,7 +146,7 @@ impl MetricsAgent {
|
||||
}
|
||||
|
||||
pub fn submit(&self, mut point: influxdb::Point) {
|
||||
point.add_field("host_id", influxdb::Value::Integer(*HOST_ID));
|
||||
point.add_field("host_id", influxdb::Value::String(HOST_INFO.to_string()));
|
||||
if point.timestamp.is_none() {
|
||||
point.timestamp = Some(timing::timestamp() as i64);
|
||||
}
|
||||
@ -244,7 +255,7 @@ pub fn set_panic_hook(program: &'static str) {
|
||||
None => "?".to_string(),
|
||||
}),
|
||||
)
|
||||
.add_field("host_id", influxdb::Value::Integer(*HOST_ID))
|
||||
.add_field("host_id", influxdb::Value::String(HOST_INFO.to_string()))
|
||||
.to_owned(),
|
||||
);
|
||||
// Flush metrics immediately in case the process exits immediately
|
||||
|
Reference in New Issue
Block a user