### Install metrics-observer Source: https://github.com/metrics-rs/metrics/blob/main/metrics-observer/README.md Install the metrics-observer tool using cargo. ```bash cargo install metrics-observer ``` -------------------------------- ### Emit a counter metric Source: https://github.com/metrics-rs/metrics/blob/main/metrics/RELEASES.md Basic usage for emitting a counter metric. No special setup is required. ```rust metrics::increment_counter!("my_counter"); ``` -------------------------------- ### Run metrics-observer with default settings Source: https://github.com/metrics-rs/metrics/blob/main/metrics-observer/README.md Connect to an application using the default address (127.0.0.1:5000) for metrics-exporter-tcp. ```bash metrics-observer ``` -------------------------------- ### Run metrics-observer with a custom address Source: https://github.com/metrics-rs/metrics/blob/main/metrics-observer/README.md Specify a custom IP address and port to connect to the metrics-exporter-tcp endpoint. ```bash metrics-observer 192.168.1.1:5000 ``` -------------------------------- ### Old vs. New Metrics Recorder Approach in Rust Source: https://github.com/metrics-rs/metrics/blob/main/metrics/RELEASES.md Compares the previous method of using a global recorder for testing with the new, simplified approach using scoped recorders. The old method required unsafe operations and more boilerplate. ```rust // This is the old approach, which mind you, still isn't thread-safe if you have concurrent tests // doing the same thing: let global = DebuggingRecorder::per_thread(); let snapshotter = global.snapshotter(); unsafe { metrics::clear_recorder(); } global.install().expect("global recorder should not be installed"); increment_counter!("my_counter"); let snapshot = snapshotter.snapshot(); assert_eq!(snapshot.into_vec().len(), 1); // Now let's use a scoped recorder instead: let scoped = DebuggingRecorder::new(); let snapshotter = scoped.snappshotter(); metrics::with_local_recorder(&scoped, || { increment_counter!("my_counter") }); let snapshot = snapppshotter.snapshot(); assert_eq!(snapshot.into_vec().len(), 1); ``` -------------------------------- ### Emit a counter metric with target metadata Source: https://github.com/metrics-rs/metrics/blob/main/metrics/RELEASES.md Emit a counter metric and specify a target for filtering or context. The module path is automatically included. ```rust metrics::increment_counter!(target: "myapp", "my_counter"); ``` -------------------------------- ### Old vs. New Counter Macro Usage Source: https://github.com/metrics-rs/metrics/blob/main/metrics/RELEASES.md Compares the previous method of registering and incrementing a counter with the new, simplified macro usage. The new approach uses a single macro per metric type and method chaining for operations. ```rust // This is the old style of registering a metric and then performing an operation on it. // // We're working with a counter here. let counter_handle = metrics::register_counter!("my_counter"); counter_handle.increment(1); metrics::increment_counter!("my_counter"); // Now let's use the new, simplified macros instead: let counter_handle = metrics::counter!("my_counter"); counter_handle.increment(1); metrics::counter!("my_counter").increment(1); ``` -------------------------------- ### Emit a histogram metric with target and level metadata Source: https://github.com/metrics-rs/metrics/blob/main/metrics/RELEASES.md Emit a histogram metric, specifying both a target and a verbosity level. The module path is automatically included. ```rust metrics::histogram!(target: "myapp", level: metrics::Level::DEBUG, "my_histogram", 180.1); ``` -------------------------------- ### Emit a gauge metric with level metadata Source: https://github.com/metrics-rs/metrics/blob/main/metrics/RELEASES.md Emit a gauge metric and specify a verbosity level (e.g., DEBUG). The module path is automatically included. ```rust metrics::increment_gauge!(level: metrics::Level::DEBUG, "my_gauge", 42.2); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.