diff --git a/src/server/metrics.rs b/src/server/metrics.rs index ad26c2cc3003..09c0659ba0a9 100644 --- a/src/server/metrics.rs +++ b/src/server/metrics.rs @@ -232,6 +232,12 @@ lazy_static! { exponential_buckets(1f64, 5f64, 10).unwrap() ) .unwrap(); + pub static ref SERVER_INFO_GAUGE_VEC: IntGaugeVec = register_int_gauge_vec!( + "tikv_server_info", + "Indicate the tikv server info, and the value is the server startup timestamp(s).", + &["version", "hash"] + ) + .unwrap(); } make_static_metric! { diff --git a/src/server/server.rs b/src/server/server.rs index 8723a2096c7d..28a93a4f1952 100644 --- a/src/server/server.rs +++ b/src/server/server.rs @@ -4,7 +4,7 @@ use std::i32; use std::net::{IpAddr, SocketAddr}; use std::str::FromStr; use std::sync::{Arc, RwLock}; -use std::time::{Duration, Instant}; +use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH}; use futures::{Future, Stream}; use grpcio::{ @@ -26,12 +26,13 @@ use tikv_util::worker::Worker; use tikv_util::Either; use super::load_statistics::*; +use super::metrics::SERVER_INFO_GAUGE_VEC; use super::raft_client::RaftClient; use super::resolve::StoreAddrResolver; use super::service::*; use super::snap::{Runner as SnapHandler, Task as SnapTask}; use super::transport::ServerTransport; -use super::{Config, Result}; +use super::{Config, Error, Result}; use crate::read_pool::ReadPool; const LOAD_STATISTICS_SLOTS: usize = 4; @@ -245,6 +246,18 @@ impl Server { ) }; + let startup_ts = SystemTime::now() + .duration_since(UNIX_EPOCH) + .map_err(|_| Error::Other(box_err!("Clock may have gone backwards")))? + .as_secs(); + + SERVER_INFO_GAUGE_VEC + .with_label_values(&[ + &("v".to_owned() + env!("CARGO_PKG_VERSION")), + option_env!("TIKV_BUILD_GIT_HASH").unwrap_or("None"), + ]) + .set(startup_ts as i64); + info!("TiKV is ready to serve"); Ok(()) }