EasyAwscr::CloudWatch::Client
CloudWatch with credentials and connections taken care of.
The everyday calls are wrapped below and documented in Awscr::CloudWatch.
Everything else is reachable through #with_native_client.
client = EasyAwscr::CloudWatch::Client.new
client.put_counter("MyApp", "Requests")
client.describe_alarms(alarm_name_prefix: "MyApp").metric_alarms.each { |a| puts a.alarm_name }
Constants
From time to time, we should recreated the connection pool, so it will reload the SSL context (see https://github.com/crystal-lang/crystal/issues/15419).
AWS accepts at most 500 queries per GetMetricData request: https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_GetMetricData.html
Constructors
Converts an existing client from "awscr-cloudwatch" to use the "easy-awscr" client interface.
Instance methods
The stat (Sum, Average, p99, ...) of every metric per period.
Yields (metric, time, value) for every data point, in time order per metric.
Works for any number of metrics and any time range: 500 metrics per request, all pages followed.
Old data is kept in coarse resolution only. Use a period that is a multiple of 5 minutes for start times older than 15 days, and a multiple of 1 hour for start times older than 63 days, or those points come back empty. The periods start at start_time, so start on a full hour to get calendar hours.
metrics = ["requests.total", "requests.errors"].map { |name| Awscr::CloudWatch::Metric.new("MyApp", name) }
client.each_datapoint(metrics, stat: "Sum", period: 1.hour, start_time: Time.utc - 7.days, end_time: Time.utc) do |metric, time, value|
puts "#{metric.metric_name} #{time}: #{value}"
end
Like get_metric_data, but follows the pages to the end and yields every result (one per query and page).
Points come oldest first unless scan_by says otherwise, and memory stays flat also for long time ranges.
Publishes a single Count value.
Publishes up to 1000 data points (1 MB) in one request.
Runs the block with the native client, for everything that is not wrapped above. Expired credentials are refreshed, like for the wrapped calls.
client.with_native_client &.metrics.put_metric_stream("Stream", "arn:aws:firehose:...", "arn:aws:iam::...", "JSON")
client.with_native_client &.alarms.tag_resource(alarm_arn, {"Env" => "prod"})