feat: Record process metrics (#1646)

* feat(servers): Export process metrics

* chore: update metrics related deps to get the process-metrics printed

The latest process-metrics crate depends on metrics 0.21, we use metrics
0.20. This cause the process-metrics crate doesn't record the metrics
  when use metrics macros
This commit is contained in:
Yingwen
2023-05-26 11:51:01 +08:00
committed by GitHub
parent 732784d3f8
commit c042723fc9
7 changed files with 181 additions and 40 deletions
+2 -2
View File
@@ -12,8 +12,8 @@ deadlock_detection = ["parking_lot"]
backtrace = "0.3"
common-error = { path = "../error" }
console-subscriber = { version = "0.1", optional = true }
metrics-exporter-prometheus = { version = "0.11", default-features = false }
metrics-util = "0.14.0"
metrics-exporter-prometheus = { version = "0.12", default-features = false }
metrics-util = "0.15"
metrics.workspace = true
once_cell = "1.10"
opentelemetry = { version = "0.17", default-features = false, features = [
+1 -1
View File
@@ -10,7 +10,7 @@ async-trait = "0.1"
bytes = "1.4"
futures = { version = "0.3" }
md5 = "0.7"
metrics = "0.20"
metrics.workspace = true
opendal = { version = "0.33", features = ["layers-tracing", "layers-metrics"] }
pin-project = "1.0"
tokio.workspace = true
+1
View File
@@ -40,6 +40,7 @@ humantime-serde = "1.1"
hyper = { version = "0.14", features = ["full"] }
influxdb_line_protocol = { git = "https://github.com/evenyag/influxdb_iox", branch = "feat/line-protocol" }
metrics.workspace = true
metrics-process = "1"
mime_guess = "2.0"
num_cpus = "1.13"
once_cell = "1.16"
+4
View File
@@ -26,6 +26,7 @@ use serde::{Deserialize, Serialize};
use session::context::UserInfo;
use crate::http::{ApiState, JsonResponse};
use crate::metrics::PROCESS_COLLECTOR;
use crate::metrics_handler::MetricsHandler;
#[derive(Debug, Default, Serialize, Deserialize, JsonSchema)]
@@ -128,6 +129,9 @@ pub async fn metrics(
State(state): State<MetricsHandler>,
Query(_params): Query<HashMap<String, String>>,
) -> String {
// Collect process metrics.
PROCESS_COLLECTOR.collect();
state.render()
}
+11
View File
@@ -12,6 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use metrics_process::Collector;
use once_cell::sync::Lazy;
pub(crate) const METRIC_DB_LABEL: &str = "db";
pub(crate) const METRIC_CODE_LABEL: &str = "code";
@@ -47,3 +50,11 @@ pub(crate) const METRIC_HTTP_REQUESTS_ELAPSED: &str = "servers.http_requests_ela
pub(crate) const METRIC_METHOD_LABEL: &str = "method";
pub(crate) const METRIC_PATH_LABEL: &str = "path";
pub(crate) const METRIC_STATUS_LABEL: &str = "status";
/// Prometheus style process metrics collector.
pub(crate) static PROCESS_COLLECTOR: Lazy<Collector> = Lazy::new(|| {
let collector = Collector::default();
// Describe collector.
collector.describe();
collector
});