#metrics #cloud-watch #aws #back-end

metrics_cloudwatch

CloudWatch emitter for the metrics crate

29 releases (3 stable)

3.0.0 Jun 10, 2024
2.0.1 Aug 24, 2023
2.0.0 Feb 3, 2023
1.0.1 Jan 9, 2023
0.4.0 Mar 18, 2020

#326 in Network programming

Download history 101/week @ 2024-06-13 75/week @ 2024-06-20 244/week @ 2024-06-27 285/week @ 2024-07-04 104/week @ 2024-07-11 158/week @ 2024-07-18 409/week @ 2024-07-25 152/week @ 2024-08-01 294/week @ 2024-08-08 384/week @ 2024-08-15 272/week @ 2024-08-22 210/week @ 2024-08-29 244/week @ 2024-09-05 231/week @ 2024-09-12 243/week @ 2024-09-19 293/week @ 2024-09-26

1,060 downloads per month

MIT/Apache

48KB
1K SLoC

metrics_cloudwatch

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 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);

Limitations

The CloudWatch metrics API imposes some limitations.

  • Max 30 labels (dimensions) per metric
  • Max 150 unique histogram values (used by 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.

Dependencies

~19–28MB
~417K SLoC