chore: add feature for metrics-process, default enable (#1870)

chore: add feature for metrics process, default enable
This commit is contained in:
fys
2023-07-04 13:28:33 +08:00
committed by GitHub
parent b466ef6cb6
commit 451cc02d8d
4 changed files with 12 additions and 8 deletions

View File

@@ -10,7 +10,9 @@ name = "greptime"
path = "src/bin/greptime.rs"
[features]
default = ["metrics-process"]
tokio-console = ["common-telemetry/tokio-console"]
metrics-process = ["servers/metrics-process"]
[dependencies]
anymap = "1.0.0-beta.2"

View File

@@ -5,9 +5,9 @@ edition.workspace = true
license.workspace = true
[features]
pprof = ["dep:common-pprof"]
mem-prof = ["dep:common-mem-prof"]
dashboard = []
mem-prof = ["dep:common-mem-prof"]
pprof = ["dep:common-pprof"]
[dependencies]
aide = { version = "0.9", features = ["axum"] }
@@ -48,7 +48,7 @@ influxdb_line_protocol = { git = "https://github.com/evenyag/influxdb_iox", bran
itertools.workspace = true
metrics.workspace = true
# metrics-process 1.0.10 depends on metrics-0.21 but opendal depends on metrics-0.20.1
metrics-process = "<1.0.10"
metrics-process = { version = "<1.0.10", optional = true }
mime_guess = "2.0"
num_cpus = "1.13"
once_cell = "1.16"

View File

@@ -27,7 +27,7 @@ use serde::{Deserialize, Serialize};
use session::context::UserInfo;
use crate::http::{ApiState, JsonResponse};
use crate::metrics::{JEMALLOC_COLLECTOR, PROCESS_COLLECTOR};
use crate::metrics::JEMALLOC_COLLECTOR;
use crate::metrics_handler::MetricsHandler;
#[derive(Debug, Default, Serialize, Deserialize, JsonSchema)]
@@ -137,7 +137,9 @@ pub async fn metrics(
Query(_params): Query<HashMap<String, String>>,
) -> String {
// Collect process metrics.
PROCESS_COLLECTOR.collect();
#[cfg(feature = "metrics-process")]
crate::metrics::PROCESS_COLLECTOR.collect();
if let Some(c) = JEMALLOC_COLLECTOR.as_ref() {
if let Err(e) = c.update() {
error!(e; "Failed to update jemalloc metrics");

View File

@@ -18,7 +18,6 @@ use std::time::Instant;
use common_telemetry::error;
use hyper::Body;
use metrics::gauge;
use metrics_process::Collector;
use once_cell::sync::Lazy;
use snafu::ResultExt;
use tikv_jemalloc_ctl::stats::{allocated_mib, resident_mib};
@@ -71,8 +70,9 @@ pub(crate) const METRIC_JEMALLOC_RESIDENT: &str = "sys.jemalloc.resident";
pub(crate) const METRIC_JEMALLOC_ALLOCATED: &str = "sys.jemalloc.allocated";
/// Prometheus style process metrics collector.
pub(crate) static PROCESS_COLLECTOR: Lazy<Collector> = Lazy::new(|| {
let collector = Collector::default();
#[cfg(feature = "metrics-process")]
pub(crate) static PROCESS_COLLECTOR: Lazy<metrics_process::Collector> = Lazy::new(|| {
let collector = metrics_process::Collector::default();
// Describe collector.
collector.describe();
collector