Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a basic readme to all the metriken crates #99

Merged
merged 2 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions metriken/README.md
Original file line number Diff line number Diff line change
@@ -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 "<crate name>::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}: <custom>")
}
}
}
```

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.
1 change: 1 addition & 0 deletions metriken/core/README.md
1 change: 1 addition & 0 deletions metriken/derive/README.md
10 changes: 8 additions & 2 deletions metriken/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -116,3 +117,8 @@ pub type LazyGauge = Lazy<Gauge>;
pub mod export {
pub use metriken_core::declare_metric_v1;
}

#[cfg(doc)]
#[doc = include_str!("../README.md")]
#[doc(hidden)]
pub mod readme {}
Loading