Use hostname in database if env is set (#2101)
This commit is contained in:
parent
aeee25e703
commit
154e20484d
|
@ -2010,9 +2010,9 @@ dependencies = [
|
||||||
"influx_db_client 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"influx_db_client 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"reqwest 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"reqwest 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"solana-sdk 0.11.0",
|
"solana-sdk 0.11.0",
|
||||||
|
"sys-info 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -9,9 +9,9 @@ license = "Apache-2.0"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
influx_db_client = "0.3.6"
|
influx_db_client = "0.3.6"
|
||||||
log = "0.4.2"
|
log = "0.4.2"
|
||||||
rand = "0.6.1"
|
|
||||||
reqwest = "0.9.0"
|
reqwest = "0.9.0"
|
||||||
lazy_static = "1.2.0"
|
lazy_static = "1.2.0"
|
||||||
|
sys-info = "0.5.6"
|
||||||
solana-sdk = { path = "../sdk", version = "0.11.0" }
|
solana-sdk = { path = "../sdk", version = "0.11.0" }
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
pub extern crate influx_db_client;
|
pub extern crate influx_db_client;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate lazy_static;
|
extern crate lazy_static;
|
||||||
extern crate rand;
|
|
||||||
extern crate reqwest;
|
extern crate reqwest;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
extern crate solana_sdk;
|
extern crate solana_sdk;
|
||||||
|
extern crate sys_info;
|
||||||
|
|
||||||
mod metrics;
|
mod metrics;
|
||||||
pub use metrics::flush;
|
pub use metrics::flush;
|
||||||
|
|
|
@ -3,16 +3,27 @@
|
||||||
extern crate reqwest;
|
extern crate reqwest;
|
||||||
|
|
||||||
use influx_db_client as influxdb;
|
use influx_db_client as influxdb;
|
||||||
use rand;
|
use solana_sdk::hash::hash;
|
||||||
use solana_sdk::timing;
|
use solana_sdk::timing;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::sync::mpsc::{channel, Receiver, RecvTimeoutError, Sender};
|
use std::sync::mpsc::{channel, Receiver, RecvTimeoutError, Sender};
|
||||||
use std::sync::{Arc, Barrier, Mutex, Once, ONCE_INIT};
|
use std::sync::{Arc, Barrier, Mutex, Once, ONCE_INIT};
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
use sys_info::hostname;
|
||||||
|
|
||||||
lazy_static! {
|
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)]
|
#[derive(Debug)]
|
||||||
|
@ -135,7 +146,7 @@ impl MetricsAgent {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn submit(&self, mut point: influxdb::Point) {
|
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() {
|
if point.timestamp.is_none() {
|
||||||
point.timestamp = Some(timing::timestamp() as i64);
|
point.timestamp = Some(timing::timestamp() as i64);
|
||||||
}
|
}
|
||||||
|
@ -244,7 +255,7 @@ pub fn set_panic_hook(program: &'static str) {
|
||||||
None => "?".to_string(),
|
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(),
|
.to_owned(),
|
||||||
);
|
);
|
||||||
// Flush metrics immediately in case the process exits immediately
|
// Flush metrics immediately in case the process exits immediately
|
||||||
|
|
|
@ -124,6 +124,7 @@ local|tar)
|
||||||
PATH="$HOME"/.cargo/bin:"$PATH"
|
PATH="$HOME"/.cargo/bin:"$PATH"
|
||||||
export USE_INSTALL=1
|
export USE_INSTALL=1
|
||||||
export RUST_LOG
|
export RUST_LOG
|
||||||
|
export SOLANA_METRICS_DISPLAY_HOSTNAME=1
|
||||||
|
|
||||||
# Setup `/var/snap/solana/current` symlink so rsyncing the genesis
|
# Setup `/var/snap/solana/current` symlink so rsyncing the genesis
|
||||||
# ledger works (reference: `net/scripts/install-rsync.sh`)
|
# ledger works (reference: `net/scripts/install-rsync.sh`)
|
||||||
|
|
Loading…
Reference in New Issue