metrics_cloudwatch

crates.io Docs Build status

Purpose

Provide a backend for the metrics facade crate, pushing metrics to CloudWatch.

How to use

Credentials for AWS needs to be available in the environment, see Rusoto docs on AWS credentials

bash cargo add -s metrics metrics_cloudwatch

```rust fn main() { // Initialize the backend metricscloudwatch::builder() .cloudwatchnamespace("my-namespace") .init_thread() .unwrap();

metrics::counter!("requests", 1);

} ```

Any labels specified will map to Cloudwatch dimensions

rust 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.

rust 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.

rust metrics::histogram!("histogram", 100.0, "@unit" => metrics_cloudwatch::Unit::Seconds);

Limitations

The CloudWatch metrics API imposes some limitations.