This library provides both internal and external DSL for querying against metrics stored in Amazon CloudWatch
.
As part of the repo, there is also a simple CLI tool which you can use to interactively query your CloudWatch
metrics using the external DSL and plot the resulting metrics on a graph.
The default maintainer account for projects under "fsprojects" is @fsprojectsgit - F# Community Project Incubation Space (repo management)
To get started, download the library from Nuget.
You can then use both the internal and external DSL via extension methods on an IAmazonCloudWatch
instance.
For example, to answer the question such as
which latency metrics' average over 5 minute intervals were above 1000ms in the last 12 hours?
you can write a query like this in F#:
open Amazon
open Amazon.CloudWatch.Selector
let awsKey = "YOUR_AWS_KEY"
let awsSecret = "YOUR_AWS_SECRET"
let region = RegionEndpoint.USEast1
let cloudWatch = AWSClientFactory.CreateAmazonCloudWatchClient(awsKey, awsSecret, region)
// using the internal DSL
let internalDslRes =
cloudWatch.Select(unitIs "milliseconds" + average (>) 1000.0 @ last 12 hours |> intervalOf 5 minutes)
|> Async.RunSynchronously
// using the external DSL
let externalDslRes =
cloudWatch.Select("unitIs 'milliseconds' and average > 1000.0 duringLast 12 hours at intervalOf 5 minutes")
|> Async.RunSynchronously
Both DSLs support the same set of operators:
NamespaceIs | Filters metrics by the specified namespace. |
NamespaceLike | Filters metrics using a regex pattern against their namespaces. |
NameIs | Filters metrics by the specified name. |
NameLike | Filters metrics using a regex pattern against their names. |
UnitIs | Filters metrics against the unit they’re recorded in, e.g. Count, Bytes, etc. |
Average | Filters metrics by the recorded average data points, e.g. average > 300 looks for metrics whose average in the specified timeframe exceeded 300 at any time. |
Min | Same as above but for the minimum data points. |
Max | Same as above but for the maximum data points. |
Sum | Same as above but for the sum data points. |
SampleCount | Same as above but for the sample count data points. |
DimensionContains | Filters metrics by the dimensions they’re recorded with, please refer to the CloudWatch docs on how this works. |
DuringLast | Specifies the timeframe of the query to be the last X minutes/hours/days. Note: CloudWatch only keeps up to 14 days worth of data so there’s no point going any further back then that. |
Since | Specifies the timeframe of the query to be since the specified timestamp till now. |
Between | Specifies the timeframe of the query to be between the specified start and end timestamp. |
IntervalOf | Specifies the ‘period’ in which the data points will be aggregated into, i.e. 5 minutes, 15 minutes, 1 hour, etc. |
The internal DSL uses the +
operator to concatenate filter conditions against the metrics, then the @
operator to apply a time frame to the query, before finally using |>
to pipe the query so far to the intervalOf
function to specify an interval to group the metrics' data points by.
For time frames and intervals, you can specify the time with the units minutes
, hours
and days
, e.g. ... @ last 2 days |> intervalOf 15 minutes
.
Coming soon.
You can get the CLI tool using Chocolatey:
- install the CLI using Chocolatey
- enter
cwcli
in command line - follow instructions to enter credential for your AWS account
- run queries!
Suppose you want to find CPU metrics for your Amazon ElastiCache
clusters whose max CPU went over 30% at any point over the last 24 hours, you could write a query like this:
namespacelike 'elasticache' and namelike 'cpu' and max > 30.0 duringLast 24 hours at intervalOf 15 minutes
You can then plot the resulting metrics (if any) onto a graph, simply type plot and hit return, e.g.
Finally, to quit the CLI tool, type exit and hit return.