From 10878fd32d917d5dd1a99df220beae0b628dbf23 Mon Sep 17 00:00:00 2001 From: Sean Lynch <42618346+swlynch99@users.noreply.github.com> Date: Wed, 17 Jan 2024 15:56:50 -0800 Subject: [PATCH 1/2] Add a basic readme to all the metriken crates --- metriken/README.md | 38 ++++++++++++++++++++++++++++++++++++++ metriken/core/README.md | 1 + metriken/derive/README.md | 1 + metriken/src/lib.rs | 10 ++++++++-- 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 metriken/README.md create mode 120000 metriken/core/README.md create mode 120000 metriken/derive/README.md diff --git a/metriken/README.md b/metriken/README.md new file mode 100644 index 0000000..d2aa008 --- /dev/null +++ b/metriken/README.md @@ -0,0 +1,38 @@ +# metriken + +Easily registered distributed metrics. + +`metriken` allows you to easily declare static metrics throughout your codebase. +Then, when you want to expose those metrics, you can access them all in one +place. + +```rust +use metriken::{metric, Counter, Gauge, Value}; + +/// A counter metric named "::COUNTER" +#[metric] +static COUNTER: Counter = Counter::new(); + +/// A gauge metric named "my.metric" +#[metric(name = "my.metric")] +static GAUGE: Gauge = Gauge::new(); + +fn main() { + COUNTER.increment(); + + for metric in &metriken::metrics() { + let name = metric.name(); + + match metric.value() { + Some(Value::Counter(val)) => println!("{name}: {val}"), + Some(Value::Gauge(val)) => println!("{name}: {val}"), + _ => println!("{name}: ") + } + } +} +``` + +Code updating the metrics can always access them without needing to go through +any indirections. (It just means accessing a static!). Using `linkme`, the +metrics are all gathered into a single global array that can then be used to +read all of them and expose them. diff --git a/metriken/core/README.md b/metriken/core/README.md new file mode 120000 index 0000000..32d46ee --- /dev/null +++ b/metriken/core/README.md @@ -0,0 +1 @@ +../README.md \ No newline at end of file diff --git a/metriken/derive/README.md b/metriken/derive/README.md new file mode 120000 index 0000000..32d46ee --- /dev/null +++ b/metriken/derive/README.md @@ -0,0 +1 @@ +../README.md \ No newline at end of file diff --git a/metriken/src/lib.rs b/metriken/src/lib.rs index ed9d8a8..6377af2 100644 --- a/metriken/src/lib.rs +++ b/metriken/src/lib.rs @@ -4,8 +4,6 @@ //! Easily registered distributed metrics. //! -//! More docs todo... -//! //! # Creating a Metric //! Registering a metric is straightforward. All that's needed is to declare a //! static within the [`metric`] macro. By default, the metric will have the @@ -32,6 +30,9 @@ //! # assert_eq!(names[0], "COUNTER_A"); //! # assert_eq!(names[1], "my.metric.name"); //! ``` +//! +//! If you want to create and remove metrics dynamically at runtime check out +//! the [`dynmetrics`] module. //! //! # Accessing Metrics //! All metrics registered via the [`metric`] macro can be accessed by calling @@ -116,3 +117,8 @@ pub type LazyGauge = Lazy; pub mod export { pub use metriken_core::declare_metric_v1; } + +#[cfg(doc)] +#[doc = include_str!("../README.md")] +#[doc(hidden)] +pub mod readme {} From 8ec0e16b1c17680a6ec04be89c12b930397aaff4 Mon Sep 17 00:00:00 2001 From: Sean Lynch <42618346+swlynch99@users.noreply.github.com> Date: Wed, 17 Jan 2024 15:59:12 -0800 Subject: [PATCH 2/2] formatting --- metriken/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metriken/src/lib.rs b/metriken/src/lib.rs index 6377af2..240b283 100644 --- a/metriken/src/lib.rs +++ b/metriken/src/lib.rs @@ -30,7 +30,7 @@ //! # assert_eq!(names[0], "COUNTER_A"); //! # assert_eq!(names[1], "my.metric.name"); //! ``` -//! +//! //! If you want to create and remove metrics dynamically at runtime check out //! the [`dynmetrics`] module. //!