Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metrics: introduce a new way to dump metrics immediately #1042

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -49,6 +49,7 @@ nix = "0.6.0"
utime = "0.1"
chrono = "0.2"
lazy_static = "0.2.1"
simple-signal = "1.0.6"

# The getopts in crate.io is outdated, use the latest getopts instead.
[dependencies.getopts]
Expand Down
20 changes: 20 additions & 0 deletions src/bin/tikv-server.rs
Expand Up @@ -23,6 +23,9 @@ extern crate mio;
extern crate toml;
extern crate libc;
extern crate fs2;
extern crate simple_signal;
extern crate prometheus;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove empty line 28.


use std::env;
use std::fs::{self, File};
Expand All @@ -46,6 +49,8 @@ use tikv::server::{MockStoreAddrResolver, PdStoreAddrResolver};
use tikv::raftstore::store::{self, SnapManager};
use tikv::pd::RpcClient;
use tikv::util::time_monitor::TimeMonitor;
use prometheus::{Encoder, TextEncoder};
use simple_signal::{Signals, Signal};

const ROCKSDB_DSN: &'static str = "rocksdb";
const RAFTKV_DSN: &'static str = "raftkv";
Expand Down Expand Up @@ -650,7 +655,22 @@ fn run_raft_server(listener: TcpListener, matches: &Matches, config: &toml::Valu
node.stop().unwrap();
}

fn reg_metrics_sig_handler() {
// sometimes we need to dump the metrics one by one, and compare those metrics.
// to flush metrics to stdout immediately, run:
// pkill --signal INT tikv-server
// or kill --s INT pid
Signals::set_handler(&[Signal::Int], move |_signals| {
let mut buffer = vec![];
let metric_familys = prometheus::gather();
let encoder = TextEncoder::new();
encoder.encode(&metric_familys, &mut buffer).unwrap();
info!("{}", String::from_utf8(buffer.clone()).unwrap());
});
}

fn main() {
reg_metrics_sig_handler();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider calling this function after util::run_prometheus, for better readability.

let args: Vec<String> = env::args().collect();
let program = args[0].clone();
let mut opts = Options::new();
Expand Down
2 changes: 1 addition & 1 deletion src/util/mod.rs
Expand Up @@ -394,7 +394,7 @@ pub fn run_prometheus(interval: Duration) -> Option<thread::JoinHandle<()>> {

Some(thread::spawn(move || {
let encoder = TextEncoder::new();
let mut buffer = Vec::<u8>::new();
let mut buffer = vec![];
loop {
let metric_familys = prometheus::gather();
encoder.encode(&metric_familys, &mut buffer).unwrap();
Expand Down