Skip to content

Commit

Permalink
chore: add feature for metrics-process, default enable (#1870)
Browse files Browse the repository at this point in the history
chore: add feature for metrics process, default enable
  • Loading branch information
fengys1996 committed Jul 4, 2023
1 parent b466ef6 commit 451cc02
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/cmd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions src/servers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down Expand Up @@ -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"
Expand Down
6 changes: 4 additions & 2 deletions src/servers/src/http/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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");
Expand Down
6 changes: 3 additions & 3 deletions src/servers/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 451cc02

Please sign in to comment.