Crates.io | metrics_cloudwatch |
lib.rs | metrics_cloudwatch |
version | 3.0.0 |
source | src |
created_at | 2020-02-14 13:53:23.779046 |
updated_at | 2024-06-10 09:45:31.989708 |
description | CloudWatch emitter for the metrics crate |
homepage | https://github.com/ramn/metrics_cloudwatch |
repository | https://github.com/ramn/metrics_cloudwatch |
max_upload_size | |
id | 208934 |
size | 63,992 |
Provide a backend for the metrics
facade
crate, pushing metrics to CloudWatch.
Credentials for AWS needs to be available in the environment, see AWS docs on setting up AWS credentials
cargo add -s metrics metrics_cloudwatch
fn main() {
// Initialize the backend
metrics_cloudwatch::builder()
.cloudwatch_namespace("my-namespace")
.init_thread()
.unwrap();
metrics::counter!("requests", 1);
}
Any labels specified will map to Cloudwatch dimensions
metrics::histogram!("histogram", 100.0, "dimension_name" => "dimension_value");
Specifying the empty string for the value will remove the default dimension of the same name from the metric.
metrics::histogram!("histogram", 100.0, "dimension_name" => "");
The special @unit
label accepts a metrics_cloudwatch::Unit
which specifies the unit for the metric (the unit can also be specified when registering the metric). Other @
prefixed labels are ignored.
metrics::histogram!("histogram", 100.0, "@unit" => metrics_cloudwatch::Unit::Seconds);
The CloudWatch metrics API imposes some limitations.
timing!()
and value!()
) per API
call. Going beyond this works but will incur one API call per batch of 150
unique values. Could be a good idea to measure timing in milliseconds rather
than nanoseconds, to keep down the number of unique values.