diff --git a/Cargo.lock b/Cargo.lock index 72792b06..a00db69a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -103,7 +103,7 @@ checksum = "10f203db73a71dfa2fb6dd22763990fa26f3d2625a6da2da900d23b87d26be27" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -114,7 +114,7 @@ checksum = "76464446b8bc32758d7e88ee1a804d9914cd9b1cb264c029899680b0be29826f" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -817,7 +817,7 @@ checksum = "c8469d0d40519bc608ec6863f1cc88f3f1deee15913f2f3b3e573d81ed38cccc" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -904,7 +904,7 @@ checksum = "42cd15d1c7456c04dbdf7e88bcd69760d74f3a798d6444e16974b505b0e62f17" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -1003,9 +1003,9 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "heatmap" -version = "0.7.1" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eb03972c2abd3d09b18a58eec103ab2debb59d5f2ca631fa43a87fa726765fa" +checksum = "d8cbf90780d798f8068becac8b922ab9901af29e2406e6327c4fda70353c58fa" dependencies = [ "clocksource", "histogram", @@ -1039,9 +1039,9 @@ dependencies = [ [[package]] name = "histogram" -version = "0.7.1" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2cddb1ee43e0813fb269066abae4e09550efca332cc2c639369b64c3b2ebd55" +checksum = "d0978bb4ae7b21dded5037bc688271ec01443b6eb2c7713aad75fce2cf670923" dependencies = [ "thiserror", ] @@ -1271,7 +1271,7 @@ checksum = "8ea60989e1675e85b206a8e44835d06727f5794e095a7229c81f70078c63fea9" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -1323,7 +1323,7 @@ version = "0.3.1" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -1358,28 +1358,29 @@ dependencies = [ [[package]] name = "metriken" -version = "0.1.1" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c051f99c84bdd165f31c1aaa7717f9d43d21410c08335cb33e97dca98fb7ad79" +checksum = "283da0f4c6ea37b3d8f932e02d368f1c1f77b3072653a91a5cdef6931b6db889" dependencies = [ - "clocksource", "heatmap", + "histogram", "linkme", "metriken-derive", "once_cell", "parking_lot", + "phf", ] [[package]] name = "metriken-derive" -version = "0.1.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e58941ebb3d827378ea64a769df9cf65e47f75d78227969d70431c19578e5dc" +checksum = "0213a7a12e01c66357d1f3491e2d7d74b2373540ea0a4bfd928a4c0e5e02f432" dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -1710,9 +1711,9 @@ dependencies = [ [[package]] name = "phf" -version = "0.11.1" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "928c6535de93548188ef63bb7c4036bd415cd8f36ad25af44b9789b2ee72a48c" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" dependencies = [ "phf_macros", "phf_shared", @@ -1730,22 +1731,22 @@ dependencies = [ [[package]] name = "phf_macros" -version = "0.11.1" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92aacdc5f16768709a569e913f7451034034178b05bdc8acda226659a3dccc66" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" dependencies = [ "phf_generator", "phf_shared", "proc-macro2", "quote", - "syn", + "syn 2.0.27", ] [[package]] name = "phf_shared" -version = "0.11.1" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1fb5f6f826b772a8d4c0394209441e7d37cbbb967ae9c7e0e8134365c9ee676" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" dependencies = [ "siphasher", ] @@ -1767,7 +1768,7 @@ checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -1853,7 +1854,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e97e3215779627f01ee256d2fad52f3d95e8e1c11e9fc6fd08f7cd455d5d5c78" dependencies = [ "proc-macro2", - "syn", + "syn 1.0.107", ] [[package]] @@ -1869,9 +1870,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.56" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" dependencies = [ "unicode-ident", ] @@ -1903,7 +1904,7 @@ dependencies = [ "prost", "prost-types", "regex", - "syn", + "syn 1.0.107", "tempfile", "which", ] @@ -1918,7 +1919,7 @@ dependencies = [ "itertools", "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -2026,6 +2027,7 @@ name = "proxy" version = "0.3.1" dependencies = [ "admin", + "clocksource", "common", "config", "crossbeam-channel", @@ -2042,9 +2044,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.23" +version = "1.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "50f3b39ccfb720540debaa0164757101c08ecb8d326b15358ce76a62c7e85965" dependencies = [ "proc-macro2", ] @@ -2181,9 +2183,9 @@ dependencies = [ [[package]] name = "ringlog" -version = "0.1.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a481f46b429f20e0dc310ddee227e5e35b86acaff897bfc5db9e37aa35c828be" +checksum = "c90d3d1e4db43daedfdae26373e7b4cb4f56b26f217fc8f661e4f439827b4a46" dependencies = [ "ahash", "clocksource", @@ -2381,7 +2383,7 @@ checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -2409,6 +2411,7 @@ name = "server" version = "0.3.1" dependencies = [ "admin", + "clocksource", "common", "config", "crossbeam-channel", @@ -2562,6 +2565,17 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn" +version = "2.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b60f673f44a8255b9c8c657daf66a596d435f2da81a555b06dc644d080ba45e0" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "sync_wrapper" version = "0.1.1" @@ -2628,7 +2642,7 @@ checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -2723,7 +2737,7 @@ checksum = "9724f9a975fb987ef7a3cd9be0350edcbe130698af5b8f7a631e23d42d052484" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -2851,7 +2865,7 @@ dependencies = [ "proc-macro2", "prost-build", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -2926,7 +2940,7 @@ checksum = "11c75893af559bc8e10716548bdef5cb2b983f8e637db9d0e15126b61b484ee2" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", ] [[package]] @@ -3048,7 +3062,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 1.0.107", "wasm-bindgen-shared", ] @@ -3070,7 +3084,7 @@ checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.107", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3306,5 +3320,5 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42307291e3c8b2e4082e5647572da863f0470511d0ecb1618a4cd0a361549723" dependencies = [ "quote", - "syn", + "syn 1.0.107", ] diff --git a/Cargo.toml b/Cargo.toml index c8dd209e..0bd6af8a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,7 +55,7 @@ httparse = "1.8.0" libc = "0.2.139" log = "0.4.17" memmap2 = "0.5.8" -metriken = "0.1.1" +metriken = "0.2.1" metrohash = "1.0.6" mio = "0.8.5" nom = "7.1.3" @@ -65,7 +65,7 @@ quote = "1.0.23" rand = "0.8.5" rand_chacha = "0.3.1" rand_xoshiro = "0.6.0" -ringlog = "0.1.0" +ringlog = "0.2.0" serde = "1.0.152" serde_json = "1.0.91" signal-hook = "0.3.15" diff --git a/src/common/src/metrics.rs b/src/common/src/metrics.rs index 7c416e54..ad780b3b 100644 --- a/src/common/src/metrics.rs +++ b/src/common/src/metrics.rs @@ -27,7 +27,8 @@ macro_rules! test_no_duplicates { pub use test_no_duplicates; -gauge!(PID, "the process id"); +#[metric(name = "pid", description = "the process id")] +pub static PID: Gauge = Gauge::new(); pub fn init() { PID.set(std::process::id().into()); diff --git a/src/core/admin/src/lib.rs b/src/core/admin/src/lib.rs index b33e6424..479d88f5 100644 --- a/src/core/admin/src/lib.rs +++ b/src/core/admin/src/lib.rs @@ -20,50 +20,104 @@ use std::time::Duration; use switchboard::{Queues, Waker}; use tiny_http::{Method, Request, Response}; -counter!(ADMIN_REQUEST_PARSE); -counter!(ADMIN_RESPONSE_COMPOSE); -counter!(ADMIN_EVENT_ERROR); -counter!(ADMIN_EVENT_WRITE); -counter!(ADMIN_EVENT_READ); -counter!(ADMIN_EVENT_LOOP); -counter!(ADMIN_EVENT_TOTAL); - -counter!(RU_UTIME); -counter!(RU_STIME); -gauge!(RU_MAXRSS); -gauge!(RU_IXRSS); -gauge!(RU_IDRSS); -gauge!(RU_ISRSS); -counter!(RU_MINFLT); -counter!(RU_MAJFLT); -counter!(RU_NSWAP); -counter!(RU_INBLOCK); -counter!(RU_OUBLOCK); -counter!(RU_MSGSND); -counter!(RU_MSGRCV); -counter!(RU_NSIGNALS); -counter!(RU_NVCSW); -counter!(RU_NIVCSW); - -counter!( - ADMIN_SESSION_ACCEPT, - "total number of attempts to accept a session" -); -counter!( - ADMIN_SESSION_ACCEPT_EX, - "number of times accept resulted in an exception, ignoring attempts that would block" -); -counter!( - ADMIN_SESSION_ACCEPT_OK, - "number of times a session was accepted successfully" -); - -counter!( - ADMIN_SESSION_CLOSE, - "total number of times a session was closed" -); - -gauge!(ADMIN_SESSION_CURR, "current number of admin sessions"); +#[metric(name = "admin_request_parse")] +pub static ADMIN_REQUEST_PARSE: Counter = Counter::new(); + +#[metric(name = "admin_response_compose")] +pub static ADMIN_RESPONSE_COMPOSE: Counter = Counter::new(); + +#[metric(name = "admin_event_error")] +pub static ADMIN_EVENT_ERROR: Counter = Counter::new(); + +#[metric(name = "admin_event_read")] +pub static ADMIN_EVENT_READ: Counter = Counter::new(); + +#[metric(name = "admin_event_write")] +pub static ADMIN_EVENT_WRITE: Counter = Counter::new(); + +#[metric(name = "admin_event_loop")] +pub static ADMIN_EVENT_LOOP: Counter = Counter::new(); + +#[metric(name = "admin_event_total")] +pub static ADMIN_EVENT_TOTAL: Counter = Counter::new(); + +#[metric(name = "ru_utime")] +pub static RU_UTIME: Counter = Counter::new(); + +#[metric(name = "ru_stime")] +pub static RU_STIME: Counter = Counter::new(); + +#[metric(name = "ru_maxrss")] +pub static RU_MAXRSS: Gauge = Gauge::new(); + +#[metric(name = "ru_ixrss")] +pub static RU_IXRSS: Gauge = Gauge::new(); + +#[metric(name = "ru_idrss")] +pub static RU_IDRSS: Gauge = Gauge::new(); + +#[metric(name = "ru_isrss")] +pub static RU_ISRSS: Gauge = Gauge::new(); + +#[metric(name = "ru_minflt")] +pub static RU_MINFLT: Counter = Counter::new(); + +#[metric(name = "ru_majflt")] +pub static RU_MAJFLT: Counter = Counter::new(); + +#[metric(name = "ru_nswap")] +pub static RU_NSWAP: Counter = Counter::new(); + +#[metric(name = "ru_inblock")] +pub static RU_INBLOCK: Counter = Counter::new(); + +#[metric(name = "ru_oublock")] +pub static RU_OUBLOCK: Counter = Counter::new(); + +#[metric(name = "ru_msgsnd")] +pub static RU_MSGSND: Counter = Counter::new(); + +#[metric(name = "ru_msgrcv")] +pub static RU_MSGRCV: Counter = Counter::new(); + +#[metric(name = "ru_nsignals")] +pub static RU_NSIGNALS: Counter = Counter::new(); + +#[metric(name = "ru_nvcsw")] +pub static RU_NVCSW: Counter = Counter::new(); + +#[metric(name = "ru_nivcsw")] +pub static RU_NIVCSW: Counter = Counter::new(); + +#[metric( + name = "admin_session_accept", + description = "total number of attempts to accept a session" +)] +pub static ADMIN_SESSION_ACCEPT: Counter = Counter::new(); + +#[metric( + name = "admin_session_accept_ex", + description = "number of times accept resulted in an exception, ignoring attempts that would block" +)] +pub static ADMIN_SESSION_ACCEPT_EX: Counter = Counter::new(); + +#[metric( + name = "admin_session_accept_ok", + description = "number of times a session was accepted successfully" +)] +pub static ADMIN_SESSION_ACCEPT_OK: Counter = Counter::new(); + +#[metric( + name = "admin_session_close", + description = "total number of times a session was closed" +)] +pub static ADMIN_SESSION_CLOSE: Counter = Counter::new(); + +#[metric( + name = "admin_session_curr", + description = "current number of admin sessions" +)] +pub static ADMIN_SESSION_CURR: Gauge = Gauge::new(); // consts @@ -473,8 +527,9 @@ impl Admin { data.push(format!("{}: {}", metric.name(), gauge.value())); } else if let Some(heatmap) = any.downcast_ref::() { for (label, value) in PERCENTILES { - let percentile = heatmap.percentile(*value).map(|b| b.high()).unwrap_or(0); - data.push(format!("{}_{}: {}", metric.name(), label, percentile)); + if let Some(Ok(bucket)) = heatmap.percentile(*value) { + data.push(format!("{}_{}: {}", metric.name(), label, bucket.high())); + } } } } @@ -511,8 +566,14 @@ impl Admin { data.push(format!("\"{}\": {}", metric.name(), gauge.value())); } else if let Some(heatmap) = any.downcast_ref::() { for (label, value) in PERCENTILES { - let percentile = heatmap.percentile(*value).map(|b| b.high()).unwrap_or(0); - data.push(format!("\"{}_{}\": {}", metric.name(), label, percentile)); + if let Some(Ok(bucket)) = heatmap.percentile(*value) { + data.push(format!( + "\"{}_{}\": {}", + metric.name(), + label, + bucket.high() + )); + } } } } @@ -582,14 +643,15 @@ impl Admin { )); } else if let Some(heatmap) = any.downcast_ref::() { for (label, value) in PERCENTILES { - let percentile = heatmap.percentile(*value).map(|b| b.high()).unwrap_or(0); - data.push(format!( - "# TYPE {} gauge\n{}{{percentile=\"{}\"}} {}", - metric.name(), - metric.name(), - label, - percentile - )); + if let Some(Ok(bucket)) = heatmap.percentile(*value) { + data.push(format!( + "# TYPE {} gauge\n{}{{percentile=\"{}\"}} {}", + metric.name(), + metric.name(), + label, + bucket.high() + )); + } } } } diff --git a/src/core/proxy/Cargo.toml b/src/core/proxy/Cargo.toml index 4c19d974..a87ba3ea 100644 --- a/src/core/proxy/Cargo.toml +++ b/src/core/proxy/Cargo.toml @@ -11,6 +11,7 @@ license = { workspace = true } [dependencies] admin = { path = "../admin" } common = { path = "../../common" } +clocksource = { workspace = true } config = { path = "../../config" } crossbeam-channel = { workspace = true } entrystore = { path = "../../entrystore" } diff --git a/src/core/proxy/src/backend.rs b/src/core/proxy/src/backend.rs index 2972b4e7..b8bb133f 100644 --- a/src/core/proxy/src/backend.rs +++ b/src/core/proxy/src/backend.rs @@ -8,23 +8,48 @@ use session::ClientSession; use std::collections::HashMap; use std::collections::VecDeque; -heatmap!( - BACKEND_EVENT_DEPTH, - 100_000, - "distribution of the number of events received per iteration of the event loop" -); -counter!(BACKEND_EVENT_ERROR, "the number of error events received"); -counter!( - BACKEND_EVENT_LOOP, - "the number of times the event loop has run" -); -counter!( - BACKEND_EVENT_MAX_REACHED, - "the number of times the maximum number of events was returned" -); -counter!(BACKEND_EVENT_READ, "the number of read events received"); -counter!(BACKEND_EVENT_TOTAL, "the total number of events received"); -counter!(BACKEND_EVENT_WRITE, "the number of write events received"); +#[metric( + name = "backend_event_depth", + description = "distribution of the number of events received per iteration of the event loop" +)] +pub static BACKEND_EVENT_DEPTH: Heatmap = + Heatmap::new(0, 8, 20, Duration::from_secs(60), Duration::from_secs(1)); + +#[metric( + name = "backend_event_error", + description = "the number of error events received" +)] +pub static BACKEND_EVENT_ERROR: Counter = Counter::new(); + +#[metric( + name = "backend_event_loop", + description = "the number of times the event loop has run" +)] +pub static BACKEND_EVENT_LOOP: Counter = Counter::new(); + +#[metric( + name = "backend_event_max_reached", + description = "the number of times the maximum number of events was returned" +)] +pub static BACKEND_EVENT_MAX_REACHED: Counter = Counter::new(); + +#[metric( + name = "backend_event_read", + description = "the number of read events received" +)] +pub static BACKEND_EVENT_READ: Counter = Counter::new(); + +#[metric( + name = "backend_event_total", + description = "the total number of events received" +)] +pub static BACKEND_EVENT_TOTAL: Counter = Counter::new(); + +#[metric( + name = "backend_event_write", + description = "the number of write events received" +)] +pub static BACKEND_EVENT_WRITE: Counter = Counter::new(); pub struct BackendWorkerBuilder { free_queue: VecDeque, @@ -193,7 +218,7 @@ where if count == self.nevent { BACKEND_EVENT_MAX_REACHED.increment(); } else { - BACKEND_EVENT_DEPTH.increment(timestamp, count as _, 1); + let _ = BACKEND_EVENT_DEPTH.increment(timestamp, count as _); } // process all events diff --git a/src/core/proxy/src/frontend.rs b/src/core/proxy/src/frontend.rs index fa9be36e..558c6434 100644 --- a/src/core/proxy/src/frontend.rs +++ b/src/core/proxy/src/frontend.rs @@ -5,23 +5,48 @@ use super::map_result; use crate::*; -heatmap!( - FRONTEND_EVENT_DEPTH, - 100_000, - "distribution of the number of events received per iteration of the event loop" -); -counter!(FRONTEND_EVENT_ERROR, "the number of error events received"); -counter!( - FRONTEND_EVENT_LOOP, - "the number of times the event loop has run" -); -counter!( - FRONTEND_EVENT_MAX_REACHED, - "the number of times the maximum number of events was returned" -); -counter!(FRONTEND_EVENT_READ, "the number of read events received"); -counter!(FRONTEND_EVENT_TOTAL, "the total number of events received"); -counter!(FRONTEND_EVENT_WRITE, "the number of write events received"); +#[metric( + name = "frontend_event_depth", + description = "distribution of the number of events received per iteration of the event loop" +)] +pub static FRONTEND_EVENT_DEPTH: Heatmap = + Heatmap::new(0, 8, 20, Duration::from_secs(60), Duration::from_secs(1)); + +#[metric( + name = "frontend_event_error", + description = "the number of error events received" +)] +pub static FRONTEND_EVENT_ERROR: Counter = Counter::new(); + +#[metric( + name = "frontend_event_loop", + description = "the number of times the event loop has run" +)] +pub static FRONTEND_EVENT_LOOP: Counter = Counter::new(); + +#[metric( + name = "frontend_event_max_reached", + description = "the number of times the maximum number of events was returned" +)] +pub static FRONTEND_EVENT_MAX_REACHED: Counter = Counter::new(); + +#[metric( + name = "frontend_event_read", + description = "the number of read events received" +)] +pub static FRONTEND_EVENT_READ: Counter = Counter::new(); + +#[metric( + name = "frontend_event_total", + description = "the total number of events received" +)] +pub static FRONTEND_EVENT_TOTAL: Counter = Counter::new(); + +#[metric( + name = "frontend_event_write", + description = "the number of write events received" +)] +pub static FRONTEND_EVENT_WRITE: Counter = Counter::new(); pub struct FrontendWorkerBuilder< FrontendParser, @@ -202,7 +227,7 @@ where if count == self.nevent { FRONTEND_EVENT_MAX_REACHED.increment(); } else { - FRONTEND_EVENT_DEPTH.increment(timestamp, count as _, 1); + let _ = FRONTEND_EVENT_DEPTH.increment(timestamp, count as _); } // process all events diff --git a/src/core/proxy/src/lib.rs b/src/core/proxy/src/lib.rs index 89dc781d..953ec9f2 100644 --- a/src/core/proxy/src/lib.rs +++ b/src/core/proxy/src/lib.rs @@ -31,7 +31,7 @@ use std::io::{Error, ErrorKind, Result}; use std::sync::Arc; use switchboard::{Queues, Waker}; -type Instant = metriken::time::Instant>; +type Instant = clocksource::Instant>; mod backend; mod frontend; diff --git a/src/core/proxy/src/listener.rs b/src/core/proxy/src/listener.rs index 36fcd890..3dc9d5cf 100644 --- a/src/core/proxy/src/listener.rs +++ b/src/core/proxy/src/listener.rs @@ -6,19 +6,47 @@ use crate::*; use metriken::*; use std::time::Duration; -counter!(LISTENER_EVENT_ERROR, "the number of error events received"); -counter!( - LISTENER_EVENT_LOOP, - "the number of times the event loop has run" -); -counter!(LISTENER_EVENT_READ, "the number of read events received"); -counter!(LISTENER_EVENT_TOTAL, "the total number of events received"); -counter!(LISTENER_EVENT_WRITE, "the number of write events received"); - -counter!( - LISTENER_SESSION_DISCARD, - "the number of sessions discarded by the listener" -); +#[metric( + name = "listener_event_error", + description = "the number of error events received" +)] +pub static LISTENER_EVENT_ERROR: Counter = Counter::new(); + +#[metric( + name = "listener_event_loop", + description = "the number of times the event loop has run" +)] +pub static LISTENER_EVENT_LOOP: Counter = Counter::new(); + +#[metric( + name = "listener_event_max_reached", + description = "the number of times the maximum number of events was returned" +)] +pub static LISTENER_EVENT_MAX_REACHED: Counter = Counter::new(); + +#[metric( + name = "listener_event_read", + description = "the number of read events received" +)] +pub static LISTENER_EVENT_READ: Counter = Counter::new(); + +#[metric( + name = "listener_event_total", + description = "the total number of events received" +)] +pub static LISTENER_EVENT_TOTAL: Counter = Counter::new(); + +#[metric( + name = "listener_event_write", + description = "the number of write events received" +)] +pub static LISTENER_EVENT_WRITE: Counter = Counter::new(); + +#[metric( + name = "listener_session_discard", + description = "the number of sessions discarded by the listener" +)] +pub static LISTENER_SESSION_DISCARD: Counter = Counter::new(); pub struct ListenerBuilder { listener: ::net::Listener, diff --git a/src/core/server/Cargo.toml b/src/core/server/Cargo.toml index 37f2c541..22a5dd37 100644 --- a/src/core/server/Cargo.toml +++ b/src/core/server/Cargo.toml @@ -12,6 +12,7 @@ license = { workspace = true } [dependencies] admin = { path = "../admin" } common = { path = "../../common" } +clocksource = { workspace = true } config = { path = "../../config" } crossbeam-channel = { workspace = true } entrystore = { path = "../../entrystore" } diff --git a/src/core/server/src/lib.rs b/src/core/server/src/lib.rs index 845e8e33..59e269aa 100644 --- a/src/core/server/src/lib.rs +++ b/src/core/server/src/lib.rs @@ -119,7 +119,7 @@ use workers::WorkersBuilder; pub use process::{Process, ProcessBuilder}; -type Instant = metriken::time::Instant>; +type Instant = clocksource::Instant>; // TODO(bmartin): this *should* be plenty safe, the queue should rarely ever be // full, and a single wakeup should drain at least one message and make room for @@ -147,7 +147,8 @@ pub static PERCENTILES: &[(&str, f64)] = &[ ]; // stats -counter!(PROCESS_REQ); +#[metric(name = "process_req")] +pub static PROCESS_REQ: Counter = Counter::new(); fn map_err(e: std::io::Error) -> Result<()> { match e.kind() { diff --git a/src/core/server/src/listener.rs b/src/core/server/src/listener.rs index 4aaff009..0b594927 100644 --- a/src/core/server/src/listener.rs +++ b/src/core/server/src/listener.rs @@ -5,19 +5,47 @@ use crate::*; use std::time::Duration; -counter!(LISTENER_EVENT_ERROR, "the number of error events received"); -counter!( - LISTENER_EVENT_LOOP, - "the number of times the event loop has run" -); -counter!(LISTENER_EVENT_READ, "the number of read events received"); -counter!(LISTENER_EVENT_TOTAL, "the total number of events received"); -counter!(LISTENER_EVENT_WRITE, "the number of write events received"); - -counter!( - LISTENER_SESSION_DISCARD, - "the number of sessions discarded by the listener" -); +#[metric( + name = "listener_event_error", + description = "the number of error events received" +)] +pub static LISTENER_EVENT_ERROR: Counter = Counter::new(); + +#[metric( + name = "listener_event_loop", + description = "the number of times the event loop has run" +)] +pub static LISTENER_EVENT_LOOP: Counter = Counter::new(); + +#[metric( + name = "listener_event_max_reached", + description = "the number of times the maximum number of events was returned" +)] +pub static LISTENER_EVENT_MAX_REACHED: Counter = Counter::new(); + +#[metric( + name = "listener_event_read", + description = "the number of read events received" +)] +pub static LISTENER_EVENT_READ: Counter = Counter::new(); + +#[metric( + name = "listener_event_total", + description = "the total number of events received" +)] +pub static LISTENER_EVENT_TOTAL: Counter = Counter::new(); + +#[metric( + name = "listener_event_write", + description = "the number of write events received" +)] +pub static LISTENER_EVENT_WRITE: Counter = Counter::new(); + +#[metric( + name = "listener_session_discard", + description = "the number of sessions discarded by the listener" +)] +pub static LISTENER_SESSION_DISCARD: Counter = Counter::new(); pub struct Listener { /// The actual network listener server diff --git a/src/core/server/src/workers/mod.rs b/src/core/server/src/workers/mod.rs index 141c1734..ffad1e96 100644 --- a/src/core/server/src/workers/mod.rs +++ b/src/core/server/src/workers/mod.rs @@ -13,23 +13,48 @@ use multi::*; use single::*; use storage::*; -heatmap!( - WORKER_EVENT_DEPTH, - 100_000, - "distribution of the number of events received per iteration of the event loop" -); -counter!(WORKER_EVENT_ERROR, "the number of error events received"); -counter!( - WORKER_EVENT_LOOP, - "the number of times the event loop has run" -); -counter!( - WORKER_EVENT_MAX_REACHED, - "the number of times the maximum number of events was returned" -); -counter!(WORKER_EVENT_READ, "the number of read events received"); -counter!(WORKER_EVENT_TOTAL, "the total number of events received"); -counter!(WORKER_EVENT_WRITE, "the number of write events received"); +#[metric( + name = "worker_event_depth", + description = "distribution of the number of events received per iteration of the event loop" +)] +pub static WORKER_EVENT_DEPTH: Heatmap = + Heatmap::new(0, 8, 20, Duration::from_secs(60), Duration::from_secs(1)); + +#[metric( + name = "worker_event_error", + description = "the number of error events received" +)] +pub static WORKER_EVENT_ERROR: Counter = Counter::new(); + +#[metric( + name = "worker_event_loop", + description = "the number of times the event loop has run" +)] +pub static WORKER_EVENT_LOOP: Counter = Counter::new(); + +#[metric( + name = "worker_event_max_reached", + description = "the number of times the maximum number of events was returned" +)] +pub static WORKER_EVENT_MAX_REACHED: Counter = Counter::new(); + +#[metric( + name = "worker_event_read", + description = "the number of read events received" +)] +pub static WORKER_EVENT_READ: Counter = Counter::new(); + +#[metric( + name = "worker_event_total", + description = "the total number of events received" +)] +pub static WORKER_EVENT_TOTAL: Counter = Counter::new(); + +#[metric( + name = "worker_event_write", + description = "the number of write events received" +)] +pub static WORKER_EVENT_WRITE: Counter = Counter::new(); fn map_result(result: Result) -> Result<()> { match result { diff --git a/src/core/server/src/workers/multi.rs b/src/core/server/src/workers/multi.rs index 113cf08b..d14cc6ed 100644 --- a/src/core/server/src/workers/multi.rs +++ b/src/core/server/src/workers/multi.rs @@ -143,7 +143,7 @@ where if count == self.nevent { WORKER_EVENT_MAX_REACHED.increment(); } else { - WORKER_EVENT_DEPTH.increment(timestamp, count as _, 1); + let _ = WORKER_EVENT_DEPTH.increment(timestamp, count as _); } // process all events diff --git a/src/core/server/src/workers/single.rs b/src/core/server/src/workers/single.rs index 974955a1..6ef1f4f4 100644 --- a/src/core/server/src/workers/single.rs +++ b/src/core/server/src/workers/single.rs @@ -204,7 +204,7 @@ where if count == self.nevent { WORKER_EVENT_MAX_REACHED.increment(); } else { - WORKER_EVENT_DEPTH.increment(timestamp, count as _, 1); + let _ = WORKER_EVENT_DEPTH.increment(timestamp, count as _); } // process all events diff --git a/src/core/server/src/workers/storage.rs b/src/core/server/src/workers/storage.rs index 10cd25ce..a4ebc8b9 100644 --- a/src/core/server/src/workers/storage.rs +++ b/src/core/server/src/workers/storage.rs @@ -4,15 +4,18 @@ use crate::*; -counter!( - STORAGE_EVENT_LOOP, - "the number of times the event loop has run" -); -heatmap!( - STORAGE_QUEUE_DEPTH, - 1_000_000, - "the distribution of the depth of the storage queue on each loop" -); +#[metric( + name = "storage_event_loop", + description = "the number of times the event loop has run" +)] +pub static STORAGE_EVENT_LOOP: Counter = Counter::new(); + +#[metric( + name = "storage_queue_depth", + description = "the distribution of the depth of the storage queue on each loop" +)] +pub static STORAGE_QUEUE_DEPTH: Heatmap = + Heatmap::new(0, 8, 20, Duration::from_secs(60), Duration::from_secs(1)); pub struct StorageWorkerBuilder { nevent: usize, @@ -114,7 +117,7 @@ where self.data_queue.try_recv_all(&mut messages); - STORAGE_QUEUE_DEPTH.increment(timestamp, messages.len() as _, 1); + let _ = STORAGE_QUEUE_DEPTH.increment(timestamp, messages.len() as _); for message in messages.drain(..) { let sender = message.sender(); diff --git a/src/entrystore/Cargo.toml b/src/entrystore/Cargo.toml index a0223b42..a9851270 100644 --- a/src/entrystore/Cargo.toml +++ b/src/entrystore/Cargo.toml @@ -19,4 +19,4 @@ protocol-common = { path = "../protocol/common" } protocol-memcache = { path = "../protocol/memcache" } protocol-ping = { path = "../protocol/ping" } protocol-resp = { path = "../protocol/resp" } -seg = { path = "../storage/seg" } \ No newline at end of file +seg = { path = "../storage/seg" } diff --git a/src/entrystore/src/seg/memcache.rs b/src/entrystore/src/seg/memcache.rs index 379fe28f..9531ea03 100644 --- a/src/entrystore/src/seg/memcache.rs +++ b/src/entrystore/src/seg/memcache.rs @@ -8,6 +8,7 @@ use super::*; use protocol_common::*; +use protocol_memcache::Value; use protocol_memcache::*; use std::time::Duration; diff --git a/src/net/src/lib.rs b/src/net/src/lib.rs index fa3005cd..18a6edc5 100644 --- a/src/net/src/lib.rs +++ b/src/net/src/lib.rs @@ -33,35 +33,71 @@ type Result = std::io::Result; // stats -counter!( - TCP_ACCEPT, - "number of TCP streams passively opened with accept" -); -counter!( - TCP_CONNECT, - "number of TCP streams actively opened with connect" -); -counter!(TCP_CLOSE, "number of TCP streams closed"); -gauge!(TCP_CONN_CURR, "current number of open TCP streams"); -counter!(TCP_RECV_BYTE, "number of bytes received on TCP streams"); -counter!(TCP_SEND_BYTE, "number of bytes sent on TCP streams"); - -counter!(STREAM_ACCEPT, "number of calls to accept"); -counter!( - STREAM_ACCEPT_EX, - "number of times calling accept resulted in an exception" -); -counter!(STREAM_CLOSE, "number of streams closed"); -counter!( - STREAM_HANDSHAKE, - "number of times stream handshaking was attempted" -); -counter!( - STREAM_HANDSHAKE_EX, - "number of exceptions while handshaking" -); -counter!(STREAM_SHUTDOWN, "number of streams gracefully shutdown"); -counter!( - STREAM_SHUTDOWN_EX, - "number of exceptions while attempting to gracefully shutdown a stream" -); +#[metric( + name = "tcp_accept", + description = "number of TCP streams passively opened with accept" +)] +pub static TCP_ACCEPT: Counter = Counter::new(); + +#[metric( + name = "tcp_connect", + description = "number of TCP streams actively opened with connect" +)] +pub static TCP_CONNECT: Counter = Counter::new(); + +#[metric(name = "tcp_close", description = "number of TCP streams closed")] +pub static TCP_CLOSE: Counter = Counter::new(); + +#[metric( + name = "tcp_conn_curr", + description = "current number of open TCP streams" +)] +pub static TCP_CONN_CURR: Gauge = Gauge::new(); + +#[metric( + name = "tcp_recv_byte", + description = "number of bytes received on TCP streams" +)] +pub static TCP_RECV_BYTE: Counter = Counter::new(); + +#[metric( + name = "tcp_send_byte", + description = "number of bytes sent on TCP streams" +)] +pub static TCP_SEND_BYTE: Counter = Counter::new(); + +#[metric(name = "stream_accept", description = "number of calls to accept")] +pub static STREAM_ACCEPT: Counter = Counter::new(); + +#[metric( + name = "stream_accept_ex", + description = "number of times calling accept resulted in an exception" +)] +pub static STREAM_ACCEPT_EX: Counter = Counter::new(); + +#[metric(name = "stream_close", description = "number of streams closed")] +pub static STREAM_CLOSE: Counter = Counter::new(); + +#[metric( + name = "stream_handshake", + description = "number of times stream handshaking was attempted" +)] +pub static STREAM_HANDSHAKE: Counter = Counter::new(); + +#[metric( + name = "stream_handshake_ex", + description = "number of exceptions while handshaking" +)] +pub static STREAM_HANDSHAKE_EX: Counter = Counter::new(); + +#[metric( + name = "stream_shutdown", + description = "number of streams gracefully shutdown" +)] +pub static STREAM_SHUTDOWN: Counter = Counter::new(); + +#[metric( + name = "stream_shutdown_ex", + description = "number of exceptions while attempting to gracefully shutdown a stream" +)] +pub static STREAM_SHUTDOWN_EX: Counter = Counter::new(); diff --git a/src/protocol/admin/src/admin.rs b/src/protocol/admin/src/admin.rs index 036401c2..8e7cce90 100644 --- a/src/protocol/admin/src/admin.rs +++ b/src/protocol/admin/src/admin.rs @@ -137,14 +137,14 @@ impl Compose for AdminResponse { data.push(format!("STAT {} {}\r\n", metric.name(), gauge.value())); } else if let Some(heatmap) = any.downcast_ref::() { for (label, value) in PERCENTILES { - let percentile = - heatmap.percentile(*value).map(|b| b.high()).unwrap_or(0); - data.push(format!( - "STAT {}_{} {}\r\n", - metric.name(), - label, - percentile - )); + if let Some(Ok(bucket)) = heatmap.percentile(*value) { + data.push(format!( + "STAT {}_{} {}\r\n", + metric.name(), + label, + bucket.high() + )); + } } } } diff --git a/src/protocol/memcache/src/lib.rs b/src/protocol/memcache/src/lib.rs index b9b48b8f..ca81dbaf 100644 --- a/src/protocol/memcache/src/lib.rs +++ b/src/protocol/memcache/src/lib.rs @@ -20,8 +20,7 @@ pub use protocol_common::*; pub use common::expiry::TimeType; use logger::Klog; -use metriken::time::*; -use metriken::*; +use metriken::{metric, Counter, Heatmap}; const CRLF: &[u8] = b"\r\n"; @@ -33,72 +32,218 @@ pub enum MemcacheError { type Instant = common::time::Instant>; -counter!(GET); -heatmap!( - GET_CARDINALITY, - 1_000_000, - "distribution of key cardinality for get requests" +/* + * GET + */ + +#[metric(name = "get")] +pub static GET: Counter = Counter::new(); + +#[metric(name = "get_ex")] +pub static GET_EX: Counter = Counter::new(); + +#[metric(name = "get_key")] +pub static GET_KEY: Counter = Counter::new(); + +#[metric(name = "get_key_hit")] +pub static GET_KEY_HIT: Counter = Counter::new(); + +#[metric(name = "get_key_miss")] +pub static GET_KEY_MISS: Counter = Counter::new(); + +#[metric( + name = "get_cardinality", + description = "distribution of key cardinality for get requests" +)] +pub static GET_CARDINALITY: Heatmap = Heatmap::new( + 0, + 8, + 20, + core::time::Duration::from_secs(60), + core::time::Duration::from_secs(1), ); -counter!(GET_EX); -counter!(GET_KEY); -counter!(GET_KEY_HIT); -counter!(GET_KEY_MISS); - -counter!(GETS); -counter!(GETS_EX); -counter!(GETS_KEY); -counter!(GETS_KEY_HIT); -counter!(GETS_KEY_MISS); - -counter!(SET); -counter!(SET_EX); -counter!(SET_STORED); -counter!(SET_NOT_STORED); - -counter!(ADD); -counter!(ADD_EX); -counter!(ADD_STORED); -counter!(ADD_NOT_STORED); - -counter!(REPLACE); -counter!(REPLACE_EX); -counter!(REPLACE_STORED); -counter!(REPLACE_NOT_STORED); - -counter!(APPEND); -counter!(APPEND_EX); -counter!(APPEND_STORED); -counter!(APPEND_NOT_STORED); - -counter!(PREPEND); -counter!(PREPEND_EX); -counter!(PREPEND_STORED); -counter!(PREPEND_NOT_STORED); - -counter!(DELETE); -counter!(DELETE_EX); -counter!(DELETE_DELETED); -counter!(DELETE_NOT_FOUND); - -counter!(INCR); -counter!(INCR_EX); -counter!(INCR_STORED); -counter!(INCR_NOT_FOUND); - -counter!(DECR); -counter!(DECR_EX); -counter!(DECR_STORED); -counter!(DECR_NOT_FOUND); - -counter!(CAS); -counter!(CAS_EX); -counter!(CAS_EXISTS); -counter!(CAS_NOT_FOUND); -counter!(CAS_STORED); - -counter!(FLUSH_ALL); -counter!(FLUSH_ALL_EX); - -counter!(QUIT); + +/* + * GETS + */ + +#[metric(name = "gets")] +pub static GETS: Counter = Counter::new(); + +#[metric(name = "gets_ex")] +pub static GETS_EX: Counter = Counter::new(); + +#[metric(name = "gets_key")] +pub static GETS_KEY: Counter = Counter::new(); + +#[metric(name = "gets_key_hit")] +pub static GETS_KEY_HIT: Counter = Counter::new(); + +#[metric(name = "gets_key_miss")] +pub static GETS_KEY_MISS: Counter = Counter::new(); + +/* + * SET + */ + +#[metric(name = "set")] +pub static SET: Counter = Counter::new(); + +#[metric(name = "set_ex")] +pub static SET_EX: Counter = Counter::new(); + +#[metric(name = "set_stored")] +pub static SET_STORED: Counter = Counter::new(); + +#[metric(name = "set_not_stored")] +pub static SET_NOT_STORED: Counter = Counter::new(); + +/* + * ADD + */ + +#[metric(name = "add")] +pub static ADD: Counter = Counter::new(); + +#[metric(name = "add_ex")] +pub static ADD_EX: Counter = Counter::new(); + +#[metric(name = "add_stored")] +pub static ADD_STORED: Counter = Counter::new(); + +#[metric(name = "add_not_stored")] +pub static ADD_NOT_STORED: Counter = Counter::new(); + +/* + * REPLACE + */ + +#[metric(name = "replace")] +pub static REPLACE: Counter = Counter::new(); + +#[metric(name = "replace_ex")] +pub static REPLACE_EX: Counter = Counter::new(); + +#[metric(name = "replace_stored")] +pub static REPLACE_STORED: Counter = Counter::new(); + +#[metric(name = "replace_not_stored")] +pub static REPLACE_NOT_STORED: Counter = Counter::new(); + +/* + * APPEND + */ + +#[metric(name = "append")] +pub static APPEND: Counter = Counter::new(); + +#[metric(name = "append_ex")] +pub static APPEND_EX: Counter = Counter::new(); + +#[metric(name = "append_stored")] +pub static APPEND_STORED: Counter = Counter::new(); + +#[metric(name = "append_not_stored")] +pub static APPEND_NOT_STORED: Counter = Counter::new(); + +/* + * PREPEND + */ + +#[metric(name = "prepend")] +pub static PREPEND: Counter = Counter::new(); + +#[metric(name = "prepend_ex")] +pub static PREPEND_EX: Counter = Counter::new(); + +#[metric(name = "prepend_stored")] +pub static PREPEND_STORED: Counter = Counter::new(); + +#[metric(name = "prepend_not_stored")] +pub static PREPEND_NOT_STORED: Counter = Counter::new(); + +/* + * DELETE + */ + +#[metric(name = "delete")] +pub static DELETE: Counter = Counter::new(); + +#[metric(name = "delete_ex")] +pub static DELETE_EX: Counter = Counter::new(); + +#[metric(name = "delete_deleted")] +pub static DELETE_DELETED: Counter = Counter::new(); + +#[metric(name = "delete_not_found")] +pub static DELETE_NOT_FOUND: Counter = Counter::new(); + +/* + * INCR + */ + +#[metric(name = "incr")] +pub static INCR: Counter = Counter::new(); + +#[metric(name = "incr_ex")] +pub static INCR_EX: Counter = Counter::new(); + +#[metric(name = "incr_stored")] +pub static INCR_STORED: Counter = Counter::new(); + +#[metric(name = "incr_not_found")] +pub static INCR_NOT_FOUND: Counter = Counter::new(); + +/* + * DECR + */ + +#[metric(name = "decr")] +pub static DECR: Counter = Counter::new(); + +#[metric(name = "decr_ex")] +pub static DECR_EX: Counter = Counter::new(); + +#[metric(name = "decr_stored")] +pub static DECR_STORED: Counter = Counter::new(); + +#[metric(name = "decr_not_found")] +pub static DECR_NOT_FOUND: Counter = Counter::new(); + +/* + * CAS + */ + +#[metric(name = "cas")] +pub static CAS: Counter = Counter::new(); + +#[metric(name = "cas_ex")] +pub static CAS_EX: Counter = Counter::new(); + +#[metric(name = "cas_exists")] +pub static CAS_EXISTS: Counter = Counter::new(); + +#[metric(name = "cas_not_found")] +pub static CAS_NOT_FOUND: Counter = Counter::new(); + +#[metric(name = "cas_stored")] +pub static CAS_STORED: Counter = Counter::new(); + +/* + * FLUSH_ALL + */ + +#[metric(name = "flush_all")] +pub static FLUSH_ALL: Counter = Counter::new(); + +#[metric(name = "flush_all_ex")] +pub static FLUSH_ALL_EX: Counter = Counter::new(); + +/* + * QUIT + */ + +#[metric(name = "quit")] +pub static QUIT: Counter = Counter::new(); common::metrics::test_no_duplicates!(); diff --git a/src/protocol/memcache/src/request/get.rs b/src/protocol/memcache/src/request/get.rs index 8c5f268a..41cb6cd1 100644 --- a/src/protocol/memcache/src/request/get.rs +++ b/src/protocol/memcache/src/request/get.rs @@ -73,7 +73,7 @@ impl RequestParser { GET.increment(); let keys = request.keys.len() as u64; GET_KEY.add(keys); - GET_CARDINALITY.increment(Instant::now(), keys, 1); + let _ = GET_CARDINALITY.increment(Instant::now(), keys); Ok((input, request)) } Err(e) => { diff --git a/src/protocol/memcache/src/request/mod.rs b/src/protocol/memcache/src/request/mod.rs index ea44c30f..5310a11f 100644 --- a/src/protocol/memcache/src/request/mod.rs +++ b/src/protocol/memcache/src/request/mod.rs @@ -3,6 +3,7 @@ // http://www.apache.org/licenses/LICENSE-2.0 use crate::*; +use common::time::{Seconds, UnixInstant}; use core::fmt::{Display, Formatter}; use core::num::NonZeroI32; use protocol_common::{BufMut, Parse, ParseOk}; diff --git a/src/protocol/ping/src/lib.rs b/src/protocol/ping/src/lib.rs index 62827408..5f925a6d 100644 --- a/src/protocol/ping/src/lib.rs +++ b/src/protocol/ping/src/lib.rs @@ -26,10 +26,12 @@ mod stats { use metriken::*; #[cfg(feature = "server")] - counter!(PING, "the number of ping requests"); + #[metric(name = "ping", description = "the number of ping requests")] + pub static PING: Counter = Counter::new(); #[cfg(feature = "client")] - counter!(PONG, "the number of pong responses"); + #[metric(name = "pong", description = "the number of pong responses")] + pub static PONG: Counter = Counter::new(); } common::metrics::test_no_duplicates!(); diff --git a/src/protocol/resp/src/request/del.rs b/src/protocol/resp/src/request/del.rs index ecaa2acd..fc103c60 100644 --- a/src/protocol/resp/src/request/del.rs +++ b/src/protocol/resp/src/request/del.rs @@ -7,8 +7,11 @@ use std::sync::Arc; use super::*; -counter!(DEL); -counter!(DEL_EX); +#[metric(name = "del")] +pub static DEL: Counter = Counter::new(); + +#[metric(name = "del_ex")] +pub static DEL_EX: Counter = Counter::new(); #[derive(Debug, PartialEq, Eq)] pub struct Del { diff --git a/src/protocol/resp/src/request/hdel.rs b/src/protocol/resp/src/request/hdel.rs index 43d9bada..53639a02 100644 --- a/src/protocol/resp/src/request/hdel.rs +++ b/src/protocol/resp/src/request/hdel.rs @@ -5,8 +5,11 @@ use super::*; use std::io::{Error, ErrorKind}; -counter!(HDEL); -counter!(HDEL_EX); +#[metric(name = "hdel")] +pub static HDEL: Counter = Counter::new(); + +#[metric(name = "hdel_ex")] +pub static HDEL_EX: Counter = Counter::new(); #[derive(Debug, PartialEq, Eq)] pub struct HashDelete { diff --git a/src/protocol/resp/src/request/hexists.rs b/src/protocol/resp/src/request/hexists.rs index 8c844912..a3b5ef89 100644 --- a/src/protocol/resp/src/request/hexists.rs +++ b/src/protocol/resp/src/request/hexists.rs @@ -5,10 +5,17 @@ use super::*; use std::io::{Error, ErrorKind}; -counter!(HEXISTS); -counter!(HEXISTS_EX); -counter!(HEXISTS_HIT); -counter!(HEXISTS_MISS); +#[metric(name = "hexists")] +pub static HEXISTS: Counter = Counter::new(); + +#[metric(name = "hexists_ex")] +pub static HEXISTS_EX: Counter = Counter::new(); + +#[metric(name = "hexists_hit")] +pub static HEXISTS_HIT: Counter = Counter::new(); + +#[metric(name = "hexists_miss")] +pub static HEXISTS_MISS: Counter = Counter::new(); #[derive(Debug, PartialEq, Eq)] pub struct HashExists { diff --git a/src/protocol/resp/src/request/hget.rs b/src/protocol/resp/src/request/hget.rs index ee6cfa7b..74ac044f 100644 --- a/src/protocol/resp/src/request/hget.rs +++ b/src/protocol/resp/src/request/hget.rs @@ -5,10 +5,17 @@ use super::*; use std::io::{Error, ErrorKind}; -counter!(HGET); -counter!(HGET_EX); -counter!(HGET_HIT); -counter!(HGET_MISS); +#[metric(name = "hget")] +pub static HGET: Counter = Counter::new(); + +#[metric(name = "hget_ex")] +pub static HGET_EX: Counter = Counter::new(); + +#[metric(name = "hget_hit")] +pub static HGET_HIT: Counter = Counter::new(); + +#[metric(name = "hget_miss")] +pub static HGET_MISS: Counter = Counter::new(); #[derive(Debug, PartialEq, Eq)] pub struct HashGet { diff --git a/src/protocol/resp/src/request/hgetall.rs b/src/protocol/resp/src/request/hgetall.rs index 479140c9..7aa60c09 100644 --- a/src/protocol/resp/src/request/hgetall.rs +++ b/src/protocol/resp/src/request/hgetall.rs @@ -6,10 +6,17 @@ use super::*; use std::io::{Error, ErrorKind}; use std::sync::Arc; -counter!(HGETALL); -counter!(HGETALL_EX); -counter!(HGETALL_HIT); -counter!(HGETALL_MISS); +#[metric(name = "hgetall")] +pub static HGETALL: Counter = Counter::new(); + +#[metric(name = "hgetall_ex")] +pub static HGETALL_EX: Counter = Counter::new(); + +#[metric(name = "hgetall_hit")] +pub static HGETALL_HIT: Counter = Counter::new(); + +#[metric(name = "hgetall_miss")] +pub static HGETALL_MISS: Counter = Counter::new(); #[derive(Debug, PartialEq, Eq)] pub struct HashGetAll { diff --git a/src/protocol/resp/src/request/hincrby.rs b/src/protocol/resp/src/request/hincrby.rs index 3956b20a..d3c37a18 100644 --- a/src/protocol/resp/src/request/hincrby.rs +++ b/src/protocol/resp/src/request/hincrby.rs @@ -6,8 +6,11 @@ use super::*; use std::io::{Error, ErrorKind}; use std::sync::Arc; -counter!(HINCRBY); -counter!(HINCRBY_EX); +#[metric(name = "hincrby")] +pub static HINCRBY: Counter = Counter::new(); + +#[metric(name = "hincrby_ex")] +pub static HINCRBY_EX: Counter = Counter::new(); #[derive(Debug, PartialEq, Eq)] pub struct HashIncrBy { diff --git a/src/protocol/resp/src/request/hkeys.rs b/src/protocol/resp/src/request/hkeys.rs index 791274c9..75871e75 100644 --- a/src/protocol/resp/src/request/hkeys.rs +++ b/src/protocol/resp/src/request/hkeys.rs @@ -6,10 +6,17 @@ use super::*; use std::io::{Error, ErrorKind}; use std::sync::Arc; -counter!(HKEYS); -counter!(HKEYS_EX); -counter!(HKEYS_HIT); -counter!(HKEYS_MISS); +#[metric(name = "hkeys")] +pub static HKEYS: Counter = Counter::new(); + +#[metric(name = "hkeys_ex")] +pub static HKEYS_EX: Counter = Counter::new(); + +#[metric(name = "hkeys_hit")] +pub static HKEYS_HIT: Counter = Counter::new(); + +#[metric(name = "hkeys_miss")] +pub static HKEYS_MISS: Counter = Counter::new(); #[derive(Debug, PartialEq, Eq)] pub struct HashKeys { diff --git a/src/protocol/resp/src/request/hlen.rs b/src/protocol/resp/src/request/hlen.rs index 167cb329..a26e7851 100644 --- a/src/protocol/resp/src/request/hlen.rs +++ b/src/protocol/resp/src/request/hlen.rs @@ -5,10 +5,17 @@ use super::*; use std::io::{Error, ErrorKind}; -counter!(HLEN); -counter!(HLEN_EX); -counter!(HLEN_HIT); -counter!(HLEN_MISS); +#[metric(name = "hlen")] +pub static HLEN: Counter = Counter::new(); + +#[metric(name = "hlen_ex")] +pub static HLEN_EX: Counter = Counter::new(); + +#[metric(name = "hlen_hit")] +pub static HLEN_HIT: Counter = Counter::new(); + +#[metric(name = "hlen_miss")] +pub static HLEN_MISS: Counter = Counter::new(); #[derive(Debug, PartialEq, Eq)] pub struct HashLength { diff --git a/src/protocol/resp/src/request/hmget.rs b/src/protocol/resp/src/request/hmget.rs index 9d12149b..67b95fb8 100644 --- a/src/protocol/resp/src/request/hmget.rs +++ b/src/protocol/resp/src/request/hmget.rs @@ -6,11 +6,20 @@ use super::*; use std::io::{Error, ErrorKind}; use std::sync::Arc; -counter!(HMGET); -counter!(HMGET_EX); -counter!(HMGET_FIELD); -counter!(HMGET_FIELD_HIT); -counter!(HMGET_FIELD_MISS); +#[metric(name = "hmget")] +pub static HMGET: Counter = Counter::new(); + +#[metric(name = "hmget_ex")] +pub static HMGET_EX: Counter = Counter::new(); + +#[metric(name = "hmget_field")] +pub static HMGET_FIELD: Counter = Counter::new(); + +#[metric(name = "hmget_field_hit")] +pub static HMGET_FIELD_HIT: Counter = Counter::new(); + +#[metric(name = "hmget_field_miss")] +pub static HMGET_FIELD_MISS: Counter = Counter::new(); #[derive(Debug, PartialEq, Eq)] pub struct HashMultiGet { diff --git a/src/protocol/resp/src/request/hset.rs b/src/protocol/resp/src/request/hset.rs index 1f0ecc8e..23167834 100644 --- a/src/protocol/resp/src/request/hset.rs +++ b/src/protocol/resp/src/request/hset.rs @@ -6,10 +6,17 @@ use super::*; use std::io::{Error, ErrorKind}; use std::sync::Arc; -counter!(HSET); -counter!(HSET_EX); -counter!(HSET_STORED); -counter!(HSET_NOT_STORED); +#[metric(name = "hset")] +pub static HSET: Counter = Counter::new(); + +#[metric(name = "hset_ex")] +pub static HSET_EX: Counter = Counter::new(); + +#[metric(name = "hset_stored")] +pub static HSET_STORED: Counter = Counter::new(); + +#[metric(name = "hset_not_stored")] +pub static HSET_NOT_STORED: Counter = Counter::new(); #[derive(Debug, PartialEq, Eq)] pub struct HashSet { diff --git a/src/protocol/resp/src/request/hvals.rs b/src/protocol/resp/src/request/hvals.rs index 4267dbee..8a6a9e75 100644 --- a/src/protocol/resp/src/request/hvals.rs +++ b/src/protocol/resp/src/request/hvals.rs @@ -5,10 +5,17 @@ use super::*; use std::io::{Error, ErrorKind}; -counter!(HVALS); -counter!(HVALS_EX); -counter!(HVALS_HIT); -counter!(HVALS_MISS); +#[metric(name = "hvals")] +pub static HVALS: Counter = Counter::new(); + +#[metric(name = "hvals_ex")] +pub static HVALS_EX: Counter = Counter::new(); + +#[metric(name = "hvals_hit")] +pub static HVALS_HIT: Counter = Counter::new(); + +#[metric(name = "hvals_miss")] +pub static HVALS_MISS: Counter = Counter::new(); #[derive(Debug, PartialEq, Eq)] pub struct HashValues { diff --git a/src/protocol/resp/src/request/lindex.rs b/src/protocol/resp/src/request/lindex.rs index a683928e..7b2485a2 100644 --- a/src/protocol/resp/src/request/lindex.rs +++ b/src/protocol/resp/src/request/lindex.rs @@ -4,10 +4,17 @@ use super::*; -counter!(LINDEX); -counter!(LINDEX_EX); -counter!(LINDEX_HIT); -counter!(LINDEX_MISS); +#[metric(name = "lindex")] +pub static LINDEX: Counter = Counter::new(); + +#[metric(name = "lindex_ex")] +pub static LINDEX_EX: Counter = Counter::new(); + +#[metric(name = "lindex_hit")] +pub static LINDEX_HIT: Counter = Counter::new(); + +#[metric(name = "lindex_miss")] +pub static LINDEX_MISS: Counter = Counter::new(); #[derive(Debug, PartialEq, Eq)] pub struct ListIndex { diff --git a/src/protocol/resp/src/request/llen.rs b/src/protocol/resp/src/request/llen.rs index f66fc102..f8105812 100644 --- a/src/protocol/resp/src/request/llen.rs +++ b/src/protocol/resp/src/request/llen.rs @@ -4,8 +4,11 @@ use super::*; -counter!(LLEN); -counter!(LLEN_EX); +#[metric(name = "llen")] +pub static LLEN: Counter = Counter::new(); + +#[metric(name = "llen_ex")] +pub static LLEN_EX: Counter = Counter::new(); #[derive(Debug, PartialEq, Eq)] pub struct ListLen { diff --git a/src/protocol/resp/src/request/lpop.rs b/src/protocol/resp/src/request/lpop.rs index f9db899c..0dcaa9df 100644 --- a/src/protocol/resp/src/request/lpop.rs +++ b/src/protocol/resp/src/request/lpop.rs @@ -4,8 +4,11 @@ use super::*; -counter!(LPOP); -counter!(LPOP_EX); +#[metric(name = "lpop")] +pub static LPOP: Counter = Counter::new(); + +#[metric(name = "lpop_ex")] +pub static LPOP_EX: Counter = Counter::new(); #[derive(Debug, PartialEq, Eq)] pub struct ListPop { diff --git a/src/protocol/resp/src/request/lpush.rs b/src/protocol/resp/src/request/lpush.rs index 461b776d..ed0e7ed8 100644 --- a/src/protocol/resp/src/request/lpush.rs +++ b/src/protocol/resp/src/request/lpush.rs @@ -7,8 +7,11 @@ use std::sync::Arc; use super::*; -counter!(LPUSH); -counter!(LPUSH_EX); +#[metric(name = "lpush")] +pub static LPUSH: Counter = Counter::new(); + +#[metric(name = "lpush_ex")] +pub static LPUSH_EX: Counter = Counter::new(); #[derive(Debug, PartialEq, Eq)] pub struct ListPush { diff --git a/src/protocol/resp/src/request/lrange.rs b/src/protocol/resp/src/request/lrange.rs index 1a8ca4be..3975e062 100644 --- a/src/protocol/resp/src/request/lrange.rs +++ b/src/protocol/resp/src/request/lrange.rs @@ -4,8 +4,11 @@ use super::*; -counter!(LRANGE); -counter!(LRANGE_EX); +#[metric(name = "lrange")] +pub static LRANGE: Counter = Counter::new(); + +#[metric(name = "lrange_ex")] +pub static LRANGE_EX: Counter = Counter::new(); #[derive(Debug, PartialEq, Eq)] pub struct ListRange { diff --git a/src/protocol/resp/src/request/ltrim.rs b/src/protocol/resp/src/request/ltrim.rs index f24a45c9..2853532f 100644 --- a/src/protocol/resp/src/request/ltrim.rs +++ b/src/protocol/resp/src/request/ltrim.rs @@ -4,8 +4,11 @@ use super::*; -counter!(LTRIM); -counter!(LTRIM_EX); +#[metric(name = "ltrim")] +pub static LTRIM: Counter = Counter::new(); + +#[metric(name = "ltrim_ex")] +pub static LTRIM_EX: Counter = Counter::new(); #[derive(Debug, PartialEq, Eq)] pub struct ListTrim { diff --git a/src/protocol/resp/src/request/rpop.rs b/src/protocol/resp/src/request/rpop.rs index 87791213..4d5c25f0 100644 --- a/src/protocol/resp/src/request/rpop.rs +++ b/src/protocol/resp/src/request/rpop.rs @@ -4,8 +4,11 @@ use super::*; -counter!(RPOP); -counter!(RPOP_EX); +#[metric(name = "rpop")] +pub static RPOP: Counter = Counter::new(); + +#[metric(name = "rpop_ex")] +pub static RPOP_EX: Counter = Counter::new(); #[derive(Debug, PartialEq, Eq)] pub struct ListPopBack { diff --git a/src/protocol/resp/src/request/rpush.rs b/src/protocol/resp/src/request/rpush.rs index ebd9ba0e..0c559c87 100644 --- a/src/protocol/resp/src/request/rpush.rs +++ b/src/protocol/resp/src/request/rpush.rs @@ -7,8 +7,11 @@ use std::sync::Arc; use super::*; -counter!(RPUSH); -counter!(RPUSH_EX); +#[metric(name = "rpush")] +pub static RPUSH: Counter = Counter::new(); + +#[metric(name = "rpush_ex")] +pub static RPUSH_EX: Counter = Counter::new(); #[derive(Debug, PartialEq, Eq)] pub struct ListPushBack { diff --git a/src/protocol/resp/src/request/sadd.rs b/src/protocol/resp/src/request/sadd.rs index 7d7867f1..c633e122 100644 --- a/src/protocol/resp/src/request/sadd.rs +++ b/src/protocol/resp/src/request/sadd.rs @@ -7,8 +7,11 @@ use std::sync::Arc; use super::*; -counter!(SADD); -counter!(SADD_EX); +#[metric(name = "sadd")] +pub static SADD: Counter = Counter::new(); + +#[metric(name = "sadd_ex")] +pub static SADD_EX: Counter = Counter::new(); #[derive(Debug, PartialEq, Eq)] pub struct SetAdd { diff --git a/src/protocol/resp/src/request/sdiff.rs b/src/protocol/resp/src/request/sdiff.rs index d087c3db..b3eefd67 100644 --- a/src/protocol/resp/src/request/sdiff.rs +++ b/src/protocol/resp/src/request/sdiff.rs @@ -7,8 +7,11 @@ use std::sync::Arc; use super::*; -counter!(SDIFF); -counter!(SDIFF_EX); +#[metric(name = "sdiff")] +pub static SDIFF: Counter = Counter::new(); + +#[metric(name = "sdiff_ex")] +pub static SDIFF_EX: Counter = Counter::new(); #[derive(Debug, PartialEq, Eq)] pub struct SetDiff { diff --git a/src/protocol/resp/src/request/sinter.rs b/src/protocol/resp/src/request/sinter.rs index 3e5016be..b7856e17 100644 --- a/src/protocol/resp/src/request/sinter.rs +++ b/src/protocol/resp/src/request/sinter.rs @@ -7,8 +7,11 @@ use std::sync::Arc; use super::*; -counter!(SINTER); -counter!(SINTER_EX); +#[metric(name = "sinter")] +pub static SINTER: Counter = Counter::new(); + +#[metric(name = "sinter_ex")] +pub static SINTER_EX: Counter = Counter::new(); #[derive(Debug, PartialEq, Eq)] pub struct SetIntersect { diff --git a/src/protocol/resp/src/request/sismember.rs b/src/protocol/resp/src/request/sismember.rs index 4411d197..e1dcd9ce 100644 --- a/src/protocol/resp/src/request/sismember.rs +++ b/src/protocol/resp/src/request/sismember.rs @@ -5,10 +5,17 @@ use super::*; use std::io::{Error, ErrorKind}; -counter!(SISMEMBER); -counter!(SISMEMBER_EX); -counter!(SISMEMBER_HIT); -counter!(SISMEMBER_MISS); +#[metric(name = "sismember")] +pub static SISMEMBER: Counter = Counter::new(); + +#[metric(name = "sismember_ex")] +pub static SISMEMBER_EX: Counter = Counter::new(); + +#[metric(name = "sismember_hit")] +pub static SISMEMBER_HIT: Counter = Counter::new(); + +#[metric(name = "sismember_miss")] +pub static SISMEMBER_MISS: Counter = Counter::new(); #[derive(Debug, PartialEq, Eq)] pub struct SetIsMember { diff --git a/src/protocol/resp/src/request/smembers.rs b/src/protocol/resp/src/request/smembers.rs index 5e270660..71529f64 100644 --- a/src/protocol/resp/src/request/smembers.rs +++ b/src/protocol/resp/src/request/smembers.rs @@ -6,8 +6,11 @@ use super::*; use std::io::{Error, ErrorKind}; use std::sync::Arc; -counter!(SMEMBERS); -counter!(SMEMBERS_EX); +#[metric(name = "smembers")] +pub static SMEMBERS: Counter = Counter::new(); + +#[metric(name = "smembers_ex")] +pub static SMEMBERS_EX: Counter = Counter::new(); #[derive(Debug, PartialEq, Eq)] pub struct SetMembers { diff --git a/src/protocol/resp/src/request/srem.rs b/src/protocol/resp/src/request/srem.rs index 36aeb3a7..720af049 100644 --- a/src/protocol/resp/src/request/srem.rs +++ b/src/protocol/resp/src/request/srem.rs @@ -7,8 +7,11 @@ use std::sync::Arc; use super::*; -counter!(SREM); -counter!(SREM_EX); +#[metric(name = "srem")] +pub static SREM: Counter = Counter::new(); + +#[metric(name = "srem_ex")] +pub static SREM_EX: Counter = Counter::new(); #[derive(Debug, PartialEq, Eq)] pub struct SetRem { diff --git a/src/protocol/resp/src/request/sunion.rs b/src/protocol/resp/src/request/sunion.rs index 55690838..e209a445 100644 --- a/src/protocol/resp/src/request/sunion.rs +++ b/src/protocol/resp/src/request/sunion.rs @@ -7,8 +7,11 @@ use std::sync::Arc; use super::*; -counter!(SUNION); -counter!(SUNION_EX); +#[metric(name = "sunion")] +pub static SUNION: Counter = Counter::new(); + +#[metric(name = "sunion_ex")] +pub static SUNION_EX: Counter = Counter::new(); #[derive(Debug, PartialEq, Eq)] pub struct SetUnion { diff --git a/src/protocol/thrift/src/lib.rs b/src/protocol/thrift/src/lib.rs index b660450a..b9cedde7 100644 --- a/src/protocol/thrift/src/lib.rs +++ b/src/protocol/thrift/src/lib.rs @@ -13,8 +13,11 @@ use protocol_common::ParseOk; const THRIFT_HEADER_LEN: usize = std::mem::size_of::(); // Stats -counter!(MESSAGES_PARSED); -counter!(MESSAGES_COMPOSED); +#[metric(name = "messages_parsed")] +pub static MESSAGES_PARSED: Counter = Counter::new(); + +#[metric(name = "messages_composed")] +pub static MESSAGES_COMPOSED: Counter = Counter::new(); /// An opaque Thrift message pub struct Message { diff --git a/src/proxy/momento/src/admin.rs b/src/proxy/momento/src/admin.rs index a2e8c427..be8ba589 100644 --- a/src/proxy/momento/src/admin.rs +++ b/src/proxy/momento/src/admin.rs @@ -5,9 +5,14 @@ use crate::*; use session::Buf; -gauge!(ADMIN_CONN_CURR); -counter!(ADMIN_CONN_ACCEPT); -counter!(ADMIN_CONN_CLOSE); +#[metric(name = "admin_conn_curr")] +pub static ADMIN_CONN_CURR: Gauge = Gauge::new(); + +#[metric(name = "admin_conn_accept")] +pub static ADMIN_CONN_ACCEPT: Counter = Counter::new(); + +#[metric(name = "admin_conn_close")] +pub static ADMIN_CONN_CLOSE: Counter = Counter::new(); pub(crate) async fn admin(mut log_drain: Box, admin_listener: TcpListener) { loop { @@ -154,13 +159,14 @@ async fn stats_response(socket: &mut tokio::net::TcpStream) -> Result<(), Error> data.push(format!("STAT {} {}\r\n", metric.name(), gauge.value())); } else if let Some(heatmap) = any.downcast_ref::() { for (label, value) in PERCENTILES { - let percentile = heatmap.percentile(*value).map(|b| b.high()).unwrap_or(0); - data.push(format!( - "STAT {}_{} {}\r\n", - metric.name(), - label, - percentile - )); + if let Some(Ok(bucket)) = heatmap.percentile(*value) { + data.push(format!( + "STAT {}_{} {}\r\n", + metric.name(), + label, + bucket.high() + )); + } } } } diff --git a/src/proxy/momento/src/main.rs b/src/proxy/momento/src/main.rs index d8b7817e..0da515d8 100644 --- a/src/proxy/momento/src/main.rs +++ b/src/proxy/momento/src/main.rs @@ -83,30 +83,71 @@ pub static PERCENTILES: &[(&str, f64)] = &[ ("p9999", 99.99), ]; -counter!(ADMIN_REQUEST_PARSE); -counter!(ADMIN_RESPONSE_COMPOSE); - -counter!(BACKEND_REQUEST); -counter!(BACKEND_EX); -counter!(BACKEND_EX_RATE_LIMITED); -counter!(BACKEND_EX_TIMEOUT); - -counter!(RU_UTIME); -counter!(RU_STIME); -gauge!(RU_MAXRSS); -gauge!(RU_IXRSS); -gauge!(RU_IDRSS); -gauge!(RU_ISRSS); -counter!(RU_MINFLT); -counter!(RU_MAJFLT); -counter!(RU_NSWAP); -counter!(RU_INBLOCK); -counter!(RU_OUBLOCK); -counter!(RU_MSGSND); -counter!(RU_MSGRCV); -counter!(RU_NSIGNALS); -counter!(RU_NVCSW); -counter!(RU_NIVCSW); +#[metric(name = "admin_request_parse")] +pub static ADMIN_REQUEST_PARSE: Counter = Counter::new(); + +#[metric(name = "admin_response_compose")] +pub static ADMIN_RESPONSE_COMPOSE: Counter = Counter::new(); + +#[metric(name = "backend_request")] +pub static BACKEND_REQUEST: Counter = Counter::new(); + +#[metric(name = "backend_ex")] +pub static BACKEND_EX: Counter = Counter::new(); + +#[metric(name = "backend_ex_rate_limited")] +pub static BACKEND_EX_RATE_LIMITED: Counter = Counter::new(); + +#[metric(name = "backend_ex_timeout")] +pub static BACKEND_EX_TIMEOUT: Counter = Counter::new(); + +#[metric(name = "ru_utime")] +pub static RU_UTIME: Counter = Counter::new(); + +#[metric(name = "ru_stime")] +pub static RU_STIME: Counter = Counter::new(); + +#[metric(name = "ru_maxrss")] +pub static RU_MAXRSS: Gauge = Gauge::new(); + +#[metric(name = "ru_ixrss")] +pub static RU_IXRSS: Gauge = Gauge::new(); + +#[metric(name = "ru_idrss")] +pub static RU_IDRSS: Gauge = Gauge::new(); + +#[metric(name = "ru_isrss")] +pub static RU_ISRSS: Gauge = Gauge::new(); + +#[metric(name = "ru_minflt")] +pub static RU_MINFLT: Counter = Counter::new(); + +#[metric(name = "ru_majflt")] +pub static RU_MAJFLT: Counter = Counter::new(); + +#[metric(name = "ru_nswap")] +pub static RU_NSWAP: Counter = Counter::new(); + +#[metric(name = "ru_inblock")] +pub static RU_INBLOCK: Counter = Counter::new(); + +#[metric(name = "ru_oublock")] +pub static RU_OUBLOCK: Counter = Counter::new(); + +#[metric(name = "ru_msgsnd")] +pub static RU_MSGSND: Counter = Counter::new(); + +#[metric(name = "ru_msgrcv")] +pub static RU_MSGRCV: Counter = Counter::new(); + +#[metric(name = "ru_nsignals")] +pub static RU_NSIGNALS: Counter = Counter::new(); + +#[metric(name = "ru_nvcsw")] +pub static RU_NVCSW: Counter = Counter::new(); + +#[metric(name = "ru_nivcsw")] +pub static RU_NIVCSW: Counter = Counter::new(); fn main() -> Result<(), Box> { // custom panic hook to terminate whole process after unwinding diff --git a/src/session/src/client.rs b/src/session/src/client.rs index 0188c67d..859b87a8 100644 --- a/src/session/src/client.rs +++ b/src/session/src/client.rs @@ -81,7 +81,7 @@ where .pop_front() .ok_or_else(|| Error::from(ErrorKind::InvalidInput))?; let latency = now - timestamp; - REQUEST_LATENCY.increment(now, latency.as_nanos(), 1); + let _ = REQUEST_LATENCY.increment(now, latency.as_nanos()); let consumed = res.consumed(); let msg = res.into_inner(); self.session.consume(consumed); diff --git a/src/session/src/lib.rs b/src/session/src/lib.rs index a2997be3..e4a2e5aa 100644 --- a/src/session/src/lib.rs +++ b/src/session/src/lib.rs @@ -27,6 +27,7 @@ use common::time::Nanoseconds; use core::borrow::{Borrow, BorrowMut}; use core::fmt::Debug; use core::marker::PhantomData; +use core::time::Duration; use metriken::*; use protocol_common::Compose; use protocol_common::Parse; @@ -37,31 +38,48 @@ use std::io::Read; use std::io::Result; use std::io::Write; -const ONE_SECOND: u64 = 1_000_000_000; // in nanoseconds - -gauge!( - SESSION_BUFFER_BYTE, - "current size of the session buffers in bytes" -); - -counter!(SESSION_RECV, "number of reads from sessions"); -counter!( - SESSION_RECV_EX, - "number of exceptions while reading from sessions" -); -counter!(SESSION_RECV_BYTE, "number of bytes read from sessions"); -counter!(SESSION_SEND, "number of writes to sessions"); -counter!( - SESSION_SEND_EX, - "number of exceptions while writing to sessions" -); -counter!(SESSION_SEND_BYTE, "number of bytes written to sessions"); - -heatmap!( - REQUEST_LATENCY, - ONE_SECOND, - "distribution of request latencies in nanoseconds" -); +#[metric( + name = "session_buffer_byte", + description = "current size of the session buffers in bytes" +)] +pub static SESSION_BUFFER_BYTE: Gauge = Gauge::new(); + +#[metric(name = "session_recv", description = "number of reads from sessions")] +pub static SESSION_RECV: Counter = Counter::new(); + +#[metric( + name = "session_recv_ex", + description = "number of exceptions while reading from sessions" +)] +pub static SESSION_RECV_EX: Counter = Counter::new(); + +#[metric( + name = "session_recv_byte", + description = "number of bytes read from sessions" +)] +pub static SESSION_RECV_BYTE: Counter = Counter::new(); + +#[metric(name = "session_send", description = "number of writes to sessions")] +pub static SESSION_SEND: Counter = Counter::new(); + +#[metric( + name = "session_send_ex", + description = "number of exceptions while writing to sessions" +)] +pub static SESSION_SEND_EX: Counter = Counter::new(); + +#[metric( + name = "session_send_byte", + description = "number of bytes written to sessions" +)] +pub static SESSION_SEND_BYTE: Counter = Counter::new(); + +#[metric( + name = "request_latency", + description = "distribution of request latencies in nanoseconds" +)] +pub static REQUEST_LATENCY: Heatmap = + Heatmap::new(0, 8, 32, Duration::from_secs(60), Duration::from_secs(1)); type Instant = common::time::Instant>; diff --git a/src/session/src/server.rs b/src/session/src/server.rs index 7577e154..5be5f3f8 100644 --- a/src/session/src/server.rs +++ b/src/session/src/server.rs @@ -97,7 +97,7 @@ where if let Some(timestamp) = timestamp { let now = Instant::now(); let latency = now - timestamp; - REQUEST_LATENCY.increment(now, latency.as_nanos(), 1); + let _ = REQUEST_LATENCY.increment(now, latency.as_nanos()); } } else { // we have bytes in our response, we need to add it on the @@ -129,7 +129,7 @@ where amt -= front.1; if let Some(ts) = front.0 { let latency = now - ts; - REQUEST_LATENCY.increment(now, latency.as_nanos(), 1); + let _ = REQUEST_LATENCY.increment(now, latency.as_nanos()); } } } else { diff --git a/src/storage/seg/src/metrics.rs b/src/storage/seg/src/metrics.rs index 32cea170..319d4a4a 100644 --- a/src/storage/seg/src/metrics.rs +++ b/src/storage/seg/src/metrics.rs @@ -7,73 +7,94 @@ use metriken::*; // segment related -counter!(SEGMENT_REQUEST, "number of segment allocation attempts"); -counter!( - SEGMENT_REQUEST_FAILURE, - "number of segment allocation attempts which failed" -); -counter!( - SEGMENT_REQUEST_SUCCESS, - "number of segment allocation attempts which were successful" -); -counter!(SEGMENT_EVICT, "number of segments evicted"); -counter!( - SEGMENT_EVICT_EX, - "number of exceptions while evicting segments" -); -counter!( - SEGMENT_RETURN, - "total number of segments returned to the free pool" -); -counter!(SEGMENT_MERGE, "total number of segments merged"); -counter!(SEGMENT_CLEAR, "number of segments cleared"); -counter!(SEGMENT_EXPIRE, "number of segments expired"); -counter!( - CLEAR_TIME, - "amount of time, in nanoseconds, spent clearing segments" -); -counter!( - EXPIRE_TIME, - "amount of time, in nanoseconds, spent expiring segments" -); -gauge!(EVICT_TIME, "time, in nanoseconds, spent evicting segments"); -gauge!(SEGMENT_FREE, "current number of free segments"); -gauge!(SEGMENT_CURRENT, "current number of segments"); +#[metric(name = "segment_request", description = "number of segment allocation attempts")] +pub static SEGMENT_REQUEST: Counter = Counter::new(); + +#[metric(name = "segment_request_failure", description = "number of segment allocation attempts which failed")] +pub static SEGMENT_REQUEST_FAILURE: Counter = Counter::new(); + +#[metric(name = "segment_request_success", description = "number of segment allocation attempts which were successful")] +pub static SEGMENT_REQUEST_SUCCESS: Counter = Counter::new(); + +#[metric(name = "segment_evict", description = "number of segments evicted")] +pub static SEGMENT_EVICT: Counter = Counter::new(); + +#[metric(name = "segment_evict_ex", description = "number of exceptions while evicting segments")] +pub static SEGMENT_EVICT_EX: Counter = Counter::new(); + +#[metric(name = "segment_return", description = "total number of segments returned to the free pool")] +pub static SEGMENT_RETURN: Counter = Counter::new(); + +#[metric(name = "segment_merge", description = "total number of segments merged")] +pub static SEGMENT_MERGE: Counter = Counter::new(); + +#[metric(name = "segment_clear", description = "total number of segments cleared")] +pub static SEGMENT_CLEAR: Counter = Counter::new(); + +#[metric(name = "segment_expire", description = "total number of segments expired")] +pub static SEGMENT_EXPIRE: Counter = Counter::new(); + +#[metric(name = "clear_time", description = "amount of time, in nanoseconds, spent clearing segments")] +pub static CLEAR_TIME: Counter = Counter::new(); + +#[metric(name = "expire_time", description = "amount of time, in nanoseconds, spent expiring segments")] +pub static EXPIRE_TIME: Counter = Counter::new(); + +#[metric(name = "evict_time", description = "amount of time, in nanoseconds, spent evicting segments")] +pub static EVICT_TIME: Counter = Counter::new(); + +#[metric(name = "segment_free", description = "current number of free segments")] +pub static SEGMENT_FREE: Gauge = Gauge::new(); + +#[metric(name = "segment_current", description = "current total number of segments")] +pub static SEGMENT_CURRENT: Gauge = Gauge::new(); // hash table related -counter!(HASH_TAG_COLLISION, "number of partial hash collisions"); -counter!(HASH_INSERT, "number of inserts into the hash table"); -counter!( - HASH_INSERT_EX, - "number of hash table inserts which failed, likely due to capacity" -); -counter!( - HASH_REMOVE, - "number of hash table entries which have been removed" -); -counter!( - HASH_LOOKUP, - "total number of lookups against the hash table" -); -counter!( - ITEM_RELINK, - "number of times items have been relinked to different locations" -); +#[metric(name = "hash_tag_collision", description = "number of partial hash collisions")] +pub static HASH_TAG_COLLISION: Counter = Counter::new(); + +#[metric(name = "hash_insert", description = "number of inserts into the hash table")] +pub static HASH_INSERT: Counter = Counter::new(); + +#[metric(name = "hash_insert_ex", description = "number of hash table inserts which failed, likely due to capacity")] +pub static HASH_INSERT_EX: Counter = Counter::new(); + +#[metric(name = "hash_remove", description = "number of hash table entries which have been removed")] +pub static HASH_REMOVE: Counter = Counter::new(); + +#[metric(name = "hash_lookup", description = "total number of lookups against the hash table")] +pub static HASH_LOOKUP: Counter = Counter::new(); // item related -counter!(ITEM_ALLOCATE, "number of times items have been allocated"); -counter!(ITEM_REPLACE, "number of times items have been replaced"); -counter!(ITEM_DELETE, "number of items removed from the hash table"); -counter!(ITEM_EXPIRE, "number of items removed due to expiration"); -counter!(ITEM_EVICT, "number of items removed due to eviction"); -counter!(ITEM_COMPACTED, "number of items which have been compacted"); -gauge!(ITEM_CURRENT, "current number of live items"); -gauge!( - ITEM_CURRENT_BYTES, - "current number of live bytes for storing items" -); -gauge!(ITEM_DEAD, "current number of dead items"); -gauge!( - ITEM_DEAD_BYTES, - "current number of dead bytes for storing items" -); +#[metric(name = "item_allocate", description = "number of times items have been allocated")] +pub static ITEM_ALLOCATE: Counter = Counter::new(); + +#[metric(name = "item_replace", description = "number of times items have been replaced")] +pub static ITEM_REPLACE: Counter = Counter::new(); + +#[metric(name = "item_delete", description = "number of items removed from the hash table")] +pub static ITEM_DELETE: Counter = Counter::new(); + +#[metric(name = "item_expire", description = "number of items removed due to expiration")] +pub static ITEM_EXPIRE: Counter = Counter::new(); + +#[metric(name = "item_evict", description ="number of items removed due to eviction")] +pub static ITEM_EVICT: Counter = Counter::new(); + +#[metric(name = "item_compacted", description = "number of items which have been compacted")] +pub static ITEM_COMPACTED: Counter = Counter::new(); + +#[metric(name = "item_relink", description = "number of times items have been relinked to different locations")] +pub static ITEM_RELINK: Counter = Counter::new(); + +#[metric(name = "item_current", description = "current number of live items")] +pub static ITEM_CURRENT: Gauge = Gauge::new(); + +#[metric(name = "item_current_bytes", description = "current number of live bytes for storing items")] +pub static ITEM_CURRENT_BYTES: Gauge = Gauge::new(); + +#[metric(name = "item_dead", description = "current number of dead items")] +pub static ITEM_DEAD: Gauge = Gauge::new(); + +#[metric(name = "item_dead_bytes", description = "current number of dead bytes for storing items")] +pub static ITEM_DEAD_BYTES: Gauge = Gauge::new();