AWS CloudWatch (aws_cloudwatch)
Reads the newest datapoint of one or more Amazon CloudWatch metrics, each given by namespace, metric name, dimensions, statistic and period. Every query fills one channel, so a single sensor can follow a load balancer's request count, a database's connections and a queue's depth, and each channel has its own limits. Nothing is installed in the account: the sensor signs a read-only request with an access key and asks CloudWatch.
What it looks like

The sensor's page after a few polls, reading three queries from a CloudWatch-compatible emulator: two with values, and one that has nothing in the window, which shows as unknown. In the dark theme: the sensor's page. The form for adding it, with its parameters filled in: light, dark.
The access key
Create an IAM user for monitoring and give it a policy with exactly two actions, and nothing else:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["cloudwatch:GetMetricData", "cloudwatch:ListMetrics"],
"Resource": "*"
}
]
}cloudwatch:GetMetricData reads the values. cloudwatch:ListMetrics is used only when a query returns nothing, to tell a metric that does not exist from one that is quiet. Neither action can be limited to one metric: CloudWatch accepts only * as the resource for both. The key can read every metric of the account, and cannot change anything.
In Probeward create a credential of kind aws with the access key id and the secret access key. Fill in the session token only for temporary credentials (an assumed role, or single sign-on): they expire, and then every poll fails with a message that says so until a new token is put in the credential. A long-lived key of an IAM user needs no token. Assign it as the AWS credential of the device, or of a group above it.
The secret access key, the access key id and the token are stored encrypted. They are used to sign the request and are never sent, never written to parameters, messages, logs, events, API answers or exports; an export shows the credential's name and kind only.
The device and the endpoint
Like every sensor that reads a web service, this one connects to the address of its device, and only to it. That keeps a credential from going anywhere but where an administrator said. The device therefore stands for the CloudWatch endpoint:
- A real account. Without
endpointthe sensor signs for the hostmonitoring.<region>.amazonaws.com(withamazonaws.com.cnfor the China regions) on port 443. Give the device the address of that host, or better the address of a VPC interface endpoint for CloudWatch, whose private address does not change. A public address of the regional endpoint is one of many that change, so a sensor on it will fail after the name moves; use the interface endpoint if the probe can reach the VPC. For a VPC endpoint setendpointto its DNS name, for examplehttps://vpce-0123.monitoring.eu-west-1.vpce.amazonaws.com, so that the name that is signed is the one the endpoint's certificate has. - An emulator, GovCloud or anything else. Set
endpointto its URL, for examplehttps://192.0.2.10:9297: only a scheme, a host and a port, nothing else. The device's address is the host the connection goes to.
endpoint is checked when the sensor is saved. It must be https://. An http:// endpoint is refused unless allow_insecure_http is turned on, which is for an emulator on a network that is yours: the secret is never sent, but the answers and the names of your metrics would then travel in clear. A URL with a user name, a path, a query or a fragment is refused.
Parameters
| Parameter | Default | Meaning |
|---|---|---|
region | required | The region the metrics are in, such as eu-west-1. It is signed into every request. |
endpoint | none | The service's URL, see above. Without it the regional host is used. |
allow_insecure_http | false | Accept an http:// endpoint. |
verify_tls | true | Check the certificate. Turn it off, or pin it, for an emulator with a self-signed certificate. |
tls_fingerprint | none | Pin the certificate, see pinning a certificate. |
look_back_minutes | 15 | How far back to look for a datapoint, 1 to 1440. The newest datapoint in the window is the reading. |
queries | required | 1 to 20 metrics, see below. |
Each entry of queries:
| Field | Default | Meaning |
|---|---|---|
key | required | The channel's key: lower case letters, digits and _, at most 40 characters. response_ms is taken. |
name | the key | The channel's name. |
namespace | required | For example AWS/EC2, AWS/RDS or your own. |
metric_name | required | For example CPUUtilization. |
dimensions | none | {"name": ..., "value": ...} pairs. All of the metric's dimensions, exactly. CloudWatch keeps a metric with another set of dimensions apart, so InstanceId alone is not the metric that has InstanceId and ImageId. At most 30. |
stat | required | Average, Sum, Minimum, Maximum, SampleCount, or a percentile such as p99. |
period_secs | 60 | The length of one datapoint: 1, 5, 10, 20 or 30 for high resolution metrics, otherwise a multiple of 60. The look-back may hold at most 500 periods. |
unit | none | The unit CloudWatch reports the metric in, see the table below. |
scale | 1 | Multiplies the value after the unit has been applied. |
The sensor sends one GetMetricData request with all the queries, asking for the look-back window, newest first, and takes for each query the datapoint with the newest timestamp. The value of the period that is still running is partial: a Sum over a five-minute period that began two minutes ago holds two minutes of data. For counters, use a period that is not much longer than the sensor's interval, and expect the newest value to rise within the period.
Units
unit is what CloudWatch says the metric is measured in. The sensor does not ask for it, because CloudWatch decides it, so say it here: it sets the channel's unit and converts a unit that is not the base one.
| CloudWatch unit | Shown as | Value multiplied by |
|---|---|---|
Seconds, Milliseconds | s, ms | 1 |
Microseconds | ms | 0.001 |
Bytes, Kilobytes, Megabytes, Gigabytes, Terabytes | B | 1, 1024, 1024², 1024³, 1024⁴ |
Bits, Kilobits, Megabits, Gigabits, Terabits | bit | 1, 10³, 10⁶, 10⁹, 10¹² |
Bytes/Second and the Kilo, Mega, Giga, Tera forms | B/s | as for bytes |
Bits/Second and the forms with a prefix | bit/s | as for bits |
Percent | % | 1 |
Count, Count/Second | #, #/s | 1 |
None | none | 1 |
A name that is not in the table is kept as the channel's unit and the value is not scaled.
Channels
One channel per query, under its key, and response_ms, the time CloudWatch took to answer the request, with a warning above 5000 ms. The suggested interval is 300 seconds: CloudWatch publishes most metrics once a minute at best, and many once in five, and every request is a billable API call (see cost).
No datapoints is unknown, not zero
A query with no datapoint in the window gives an unknown channel, never 0. The two mean different things: CloudWatch has nothing for a metric that was not reported, such as the error count of a service that had no errors, or the metrics of a stopped instance, and a 0 would say the thing was measured and found to be nothing. A limit such as "warn below 10" would also page for a metric that is only quiet. An unknown channel has no value to compare with a limit. If you do want silence to alert, choose a statistic and a period that always have a datapoint, such as SampleCount of a metric that is reported on a schedule.
When a query has no datapoint the sensor asks ListMetrics for that metric and says why in the message:
| Message | Health | Meaning |
|---|---|---|
<ns>/<metric> has no datapoint in the last 15 minutes | unchanged | The metric exists with exactly these dimensions and has not been reported in the window. Widen look_back_minutes if it reports rarely. |
<ns>/<metric> has no datapoints with exactly the dimensions given; it exists with Az+Host | Warning | The metric exists only with other dimensions, listed by name. Compare them with dimensions. |
<ns>/<metric> does not exist in region <region> | Warning | No such metric in this region: check the namespace, the name and the region. CloudWatch lists a metric some minutes after its first datapoint, so a new one can show this briefly. |
Failures
Every message names the cause, and none contains the key, the secret or the token: what the service says is cleaned of them before it is shown. A collection failure keeps the last reading and counts towards an incident.
| Message | Kind | Meaning |
|---|---|---|
AWS rejected the signature (SignatureDoesNotMatch): the secret access key is not the one that belongs to this access key id ... | auth_failed | The secret is wrong, or the request was signed for a region the endpoint does not expect. |
AWS does not know the access key id, or the session token does not belong to it | auth_failed | The key id is wrong or deleted, or the token is not the one of this key. |
the session token has expired: put a new access key, secret and session token in the aws credential | auth_failed | Temporary credentials ran out. |
AWS knows the key but refused the request (...); the key needs the IAM permission cloudwatch:GetMetricData | auth_failed | The policy lacks the action. |
AWS refused the request because this machine's clock differs from its clock by more than five minutes | auth_failed | The probe's clock is wrong. SigV4 requests expire after five minutes. |
AWS does not accept region "xx-nowhere-1" ... | config | The region is not one the endpoint serves. |
AWS is throttling the requests (Throttling) ... | protocol | Too many requests. Lengthen the interval, or read fewer metrics with it. |
AWS refused a parameter of the GetMetricData request (...) | config | For example a statistic CloudWatch does not know. The reply of the service follows. |
AWS answered HTTP 500 to GetMetricData; it may be having trouble | protocol | A fault at AWS. |
this sensor needs an aws credential and none is assigned to it or inherited | config | No credential. |
TLS error: ..., cannot connect: ..., no complete HTTP response within N ms | protocol, unreachable, timeout | As for every web sensor; see pinning a certificate. |
Cost
CloudWatch charges for API requests, per metric requested by GetMetricData, not per call, at the time of writing a few cents per thousand metrics. One sensor with five queries every five minutes asks for about 43,000 metrics a month. Check the current price for your region, and use as few queries and as long an interval as the decision needs. ListMetrics is sent only when a query has no data.
Verification
Checked against AWS Emulator (aws/aws-emulator, CC0), run from the container image that its documentation builds from the official package, with telemetry turned off. The live tests (crates/probeward-sensors/tests/aws_cloudwatch_live.rs) seed their own metrics with PutMetricData, signed by the same signer, and read them back: a metric with values, a Sum, an Average, a Maximum and a SampleCount over one period, a metric that exists but has nothing in the window, a metric that does not exist, a wrong secret and an unknown key id. The signer is checked against the signature test suite that AWS publishes (get-vanilla, post-vanilla, the query order case, the form post with a signed content type, and the worked example in the Signature Version 4 documentation), and the sensor against a scripted service that recomputes every signature the way the service does.
What the emulator does prove: that the request is well formed for the GetMetricData, ListMetrics and PutMetricData operations, that its signature is accepted by an independent implementation, that a wrong secret is refused with SignatureDoesNotMatch and an unknown key id with AccessDenied, and that the answers parse.
What it does not prove, and was not seen: the real service. Specifically the error answers of CloudWatch for an expired token, throttling, missing IAM permission, clock skew and an unknown region, which are written by hand in the tests from the documented error codes; the real service's rules for dimensions, its rounding of periods, its delay in listing a new metric, and the region check (the emulator accepts any region, so a wrong region was not seen being refused); a VPC endpoint; GovCloud and the China regions; temporary credentials with a session token against a service that checks them. The emulator's own error text differs from the service's, and the sensor classifies by the error type and the text, so a message of the real service that is worded differently from the documentation would be reported as a generic AWS answered HTTP .... Try the sensor against your account before you rely on it.
Testing against an emulator
mkdir awsemu && cd awsemu
cat > Dockerfile <<'EOF'
FROM public.ecr.aws/amazonlinux/amazonlinux:2023-minimal
ADD https://downloads.aws.com/aws-emulator/packages/aws-emulator/LTS/latest/aws-emulator-x86_64.rpm /tmp/aws-emulator.rpm
RUN rpm -i /tmp/aws-emulator.rpm && rm /tmp/aws-emulator.rpm && mkdir -p /home/emulator && chown 1000 /home/emulator
USER 1000
ENV HOME=/home/emulator EMULATOR_BIND_ADDRESS=0.0.0.0
ENTRYPOINT ["aws-emulator"]
EOF
docker build -t aws-emulator .
mkdir -p "$HOME/.aws/emulator"
docker run -d --name pwtest-awsemu --user "$(id -u):$(id -g)" -p 127.0.0.1:9297:9297 \
-e HOME="$HOME" -v "$HOME/.aws/emulator:$HOME/.aws/emulator" \
aws-emulator --telemetry off -p 9297The emulator writes its access key to ~/.aws/emulator/9297/emulator_credentials. Use that key in an aws credential, give the device the address 127.0.0.1, set endpoint to https://127.0.0.1:9297, and pin the certificate: openssl s_client -connect 127.0.0.1:9297 </dev/null | openssl x509 -noout -fingerprint -sha256. The variables the live tests read are listed in live tests.