#metrics #cloudwatch #aws

metrics_cloudwatch

CloudWatch emitter for the metrics crate

21 releases (11 breaking)

0.12.4 Feb 19, 2021
0.11.0 Jan 29, 2021
0.9.2 Nov 2, 2020
0.6.0 Jun 16, 2020
0.4.0 Mar 18, 2020

#17 in Authentication

Download history 216/week @ 2020-11-07 96/week @ 2020-11-14 124/week @ 2020-11-21 136/week @ 2020-11-28 90/week @ 2020-12-05 66/week @ 2020-12-12 93/week @ 2020-12-19 11/week @ 2020-12-26 72/week @ 2021-01-02 145/week @ 2021-01-09 185/week @ 2021-01-16 160/week @ 2021-01-23 156/week @ 2021-01-30 204/week @ 2021-02-06 440/week @ 2021-02-13 135/week @ 2021-02-20

618 downloads per month

MIT/Apache

39KB
910 lines

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

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 10 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

~11–15MB
~332K SLoC