Skip to content

Commit

Permalink
metrics: Use prometheus for process metrics
Browse files Browse the repository at this point in the history
We currently have our own implementation of system level metrics. This
is unnecessary. The `prometheus` crate provides a _process_ feature that
bundles prometheus's default process-level metrics. This adds a
`process_threads` metric.

This change also updates the static `proxy_build_info` metric to be
exported via the default prometheus registry. This allows us to export
this metric from the top-level `linkerd2-proxy` crate so that the build
metadata is not inferred from the linkerd-app-core crate (fixing an old
TODO).

---

Before

> # HELP process_start_time_seconds Time that the process started (in seconds since the UNIX epoch)
> # TYPE process_start_time_seconds gauge
> process_start_time_seconds 1701551542
> # HELP process_uptime_seconds_total Total time since the process started (in seconds)
> # TYPE process_uptime_seconds_total counter
> process_uptime_seconds_total 1782.137
> # HELP process_cpu_seconds_total Total user and system CPU time spent in seconds.
> # TYPE process_cpu_seconds_total counter
> process_cpu_seconds_total 0.72
> # HELP process_virtual_memory_bytes Virtual memory size in bytes.
> # TYPE process_virtual_memory_bytes gauge
> process_virtual_memory_bytes 111042560
> # HELP process_resident_memory_bytes Resident memory size in bytes.
> # TYPE process_resident_memory_bytes gauge
> process_resident_memory_bytes 33910784
> # HELP process_open_fds Number of open file descriptors.
> # TYPE process_open_fds gauge
> process_open_fds 28
> # HELP process_max_fds Maximum number of open file descriptors.
> # TYPE process_max_fds gauge
> process_max_fds 1048576
> # HELP proxy_build_info Proxy build info
> # TYPE proxy_build_info gauge
> proxy_build_info{version="2.213.0",git_sha="9f7e7ac",profile="release",date="2023-11-16T23:24:26Z",vendor="linkerd"} 1

After:

> # HELP process_cpu_seconds_total Total user and system CPU time spent in seconds.
> # TYPE process_cpu_seconds_total counter
> process_cpu_seconds_total 0
> # HELP process_max_fds Maximum number of open file descriptors.
> # TYPE process_max_fds gauge
> process_max_fds 1048576
> # HELP process_open_fds Number of open file descriptors.
> # TYPE process_open_fds gauge
> process_open_fds 24
> # HELP process_resident_memory_bytes Resident memory size in bytes.
> # TYPE process_resident_memory_bytes gauge
> process_resident_memory_bytes 27656192
> # HELP process_start_time_seconds Start time of the process since unix epoch in seconds.
> # TYPE process_start_time_seconds gauge
> process_start_time_seconds 1701553218
> # HELP process_threads Number of OS threads in the process.
> # TYPE process_threads gauge
> process_threads 2
> # HELP process_uptime_seconds_total Total time since the process started (in seconds)
> # TYPE process_uptime_seconds_total gauge
> process_uptime_seconds_total 9.700919434
> # HELP process_virtual_memory_bytes Virtual memory size in bytes.
> # TYPE process_virtual_memory_bytes gauge
> process_virtual_memory_bytes 109264896
> # HELP proxy_build_info Proxy build info
> # TYPE proxy_build_info gauge
> proxy_build_info{date="2023-12-02T21:32:40Z",git_sha="9a4d02c6f",profile="release",vendor="code@ver-sea",version="0.0.0-dev.9a4d02c6f"} 1
  • Loading branch information
olix0r committed Dec 2, 2023
1 parent 1b2039d commit 52c9dd5
Show file tree
Hide file tree
Showing 26 changed files with 141 additions and 427 deletions.
46 changes: 31 additions & 15 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,7 @@ dependencies = [
"linkerd-app-inbound",
"linkerd-app-outbound",
"linkerd-error",
"linkerd-metrics",
"linkerd-opencensus",
"rangemap",
"regex",
Expand Down Expand Up @@ -1135,7 +1136,6 @@ dependencies = [
"linkerd-stack",
"linkerd-stack-metrics",
"linkerd-stack-tracing",
"linkerd-system",
"linkerd-tls",
"linkerd-trace-context",
"linkerd-tracing",
Expand All @@ -1145,7 +1145,6 @@ dependencies = [
"pin-project",
"quickcheck",
"regex",
"semver",
"serde_json",
"thiserror",
"tokio",
Expand Down Expand Up @@ -1623,6 +1622,7 @@ dependencies = [
"hyper",
"linkerd-stack",
"parking_lot",
"prometheus",
"quickcheck",
"tokio",
"tracing",
Expand Down Expand Up @@ -2010,15 +2010,6 @@ dependencies = [
"tracing",
]

[[package]]
name = "linkerd-system"
version = "0.1.0"
dependencies = [
"libc",
"procfs",
"tracing",
]

[[package]]
name = "linkerd-tls"
version = "0.1.0"
Expand Down Expand Up @@ -2132,10 +2123,12 @@ version = "0.1.0"
dependencies = [
"futures",
"jemallocator",
"lazy_static",
"linkerd-app",
"linkerd-meshtls",
"linkerd-signal",
"num_cpus",
"semver",
"tokio",
"tracing",
]
Expand Down Expand Up @@ -2559,9 +2552,9 @@ dependencies = [

[[package]]
name = "procfs"
version = "0.15.1"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "943ca7f9f29bab5844ecd8fdb3992c5969b6622bb9609b9502fef9b4310e3f1f"
checksum = "b1de8dacb0873f77e6aefc6d71e044761fcc68060290f5b1089fcdf84626bb69"
dependencies = [
"bitflags 1.3.2",
"byteorder",
Expand All @@ -2570,6 +2563,23 @@ dependencies = [
"rustix 0.36.16",
]

[[package]]
name = "prometheus"
version = "0.13.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "449811d15fbdf5ceb5c1144416066429cf82316e2ec8ce0c1f6f8a02e7bbcf8c"
dependencies = [
"cfg-if",
"fnv",
"lazy_static",
"libc",
"memchr",
"parking_lot",
"procfs",
"protobuf",
"thiserror",
]

[[package]]
name = "prost"
version = "0.11.8"
Expand Down Expand Up @@ -2678,6 +2688,12 @@ dependencies = [
"prost 0.12.1",
]

[[package]]
name = "protobuf"
version = "2.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "106dd99e98437432fed6519dedecfade6a06a73bb7b2a1e019fdd2bee5778d94"

[[package]]
name = "quick-error"
version = "1.2.3"
Expand Down Expand Up @@ -2947,9 +2963,9 @@ dependencies = [

[[package]]
name = "semver"
version = "1.0.17"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed"
checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090"

[[package]]
name = "serde"
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ members = [
"linkerd/stack",
"linkerd/stack/metrics",
"linkerd/stack/tracing",
"linkerd/system",
"linkerd/tonic-watch",
"linkerd/tls",
"linkerd/tls/test-util",
Expand Down
1 change: 1 addition & 0 deletions linkerd/app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ linkerd-app-gateway = { path = "./gateway" }
linkerd-app-inbound = { path = "./inbound" }
linkerd-app-outbound = { path = "./outbound" }
linkerd-error = { path = "../error" }
linkerd-metrics = { path = "../metrics", features = ["process"] }
linkerd-opencensus = { path = "../opencensus" }
rangemap = "1"
regex = "1"
Expand Down
6 changes: 0 additions & 6 deletions linkerd/app/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,5 @@ version = "0.4"
default-features = false
features = ["make", "spawn-ready", "timeout", "util", "limit"]

[target.'cfg(target_os = "linux")'.dependencies]
linkerd-system = { path = "../../system" }

[build-dependencies]
semver = "1"

[dev-dependencies]
quickcheck = { version = "1", default-features = false }
1 change: 0 additions & 1 deletion linkerd/app/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ pub mod metrics;
pub mod proxy;
pub mod serve;
pub mod svc;
pub mod telemetry;
pub mod transport;

pub use drain;
Expand Down
15 changes: 3 additions & 12 deletions linkerd/app/core/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
classify::Class,
control, http_metrics, http_metrics as metrics, opencensus, profiles, stack_metrics,
svc::Param,
telemetry, tls,
tls,
transport::{self, labels::TlsConnect},
};
use linkerd_addr::Addr;
Expand Down Expand Up @@ -143,14 +143,7 @@ where
// === impl Metrics ===

impl Metrics {
pub fn new(
retain_idle: Duration,
start_time: telemetry::StartTime,
) -> (Self, impl FmtMetrics + Clone + Send + 'static) {
let process = telemetry::process::Report::new(start_time);

let build_info = telemetry::build_info::Report::default();

pub fn new(retain_idle: Duration) -> (Self, impl FmtMetrics + Clone + Send + 'static) {
let (control, control_report) = {
let m = metrics::Requests::<ControlLabels, Class>::default();
let r = m.clone().into_report(retain_idle).with_prefix("control");
Expand Down Expand Up @@ -212,9 +205,7 @@ impl Metrics {
.and_report(control_report)
.and_report(transport_report)
.and_report(opencensus_report)
.and_report(stack)
.and_report(process)
.and_report(build_info);
.and_report(stack);

(metrics, report)
}
Expand Down
3 changes: 0 additions & 3 deletions linkerd/app/core/src/telemetry.rs

This file was deleted.

38 changes: 0 additions & 38 deletions linkerd/app/core/src/telemetry/build_info.rs

This file was deleted.

Loading

0 comments on commit 52c9dd5

Please sign in to comment.