2020-08-12 04:10:41 +08:00
|
|
|
# Amazon CloudWatch Statistics Input Plugin
|
2016-03-26 06:16:23 +08:00
|
|
|
|
|
|
|
|
This plugin will pull Metric Statistics from Amazon CloudWatch.
|
|
|
|
|
|
2021-11-25 02:55:55 +08:00
|
|
|
## Amazon Authentication
|
2016-03-26 06:16:23 +08:00
|
|
|
|
|
|
|
|
This plugin uses a credential chain for Authentication with the CloudWatch
|
|
|
|
|
API endpoint. In the following order the plugin will attempt to authenticate.
|
2021-11-25 02:55:55 +08:00
|
|
|
|
2022-08-10 00:57:31 +08:00
|
|
|
1. Assumed credentials via STS if `role_arn` attribute is specified
|
|
|
|
|
(source credentials are evaluated from subsequent rules)
|
2016-05-25 19:30:39 +08:00
|
|
|
2. Explicit credentials from `access_key`, `secret_key`, and `token` attributes
|
|
|
|
|
3. Shared profile from `profile` attribute
|
2022-08-10 00:57:31 +08:00
|
|
|
4. [Environment Variables][env]
|
|
|
|
|
5. [Shared Credentials][credentials]
|
|
|
|
|
6. [EC2 Instance Profile][iam-roles]
|
2016-03-26 06:16:23 +08:00
|
|
|
|
2021-11-25 02:55:55 +08:00
|
|
|
## Configuration
|
2016-03-26 06:16:23 +08:00
|
|
|
|
2022-05-24 21:49:47 +08:00
|
|
|
```toml @sample.conf
|
2021-04-28 09:41:52 +08:00
|
|
|
# Pull Metric Statistics from Amazon CloudWatch
|
2016-03-26 06:16:23 +08:00
|
|
|
[[inputs.cloudwatch]]
|
2019-04-23 08:36:46 +08:00
|
|
|
## Amazon Region
|
2016-11-04 21:16:41 +08:00
|
|
|
region = "us-east-1"
|
2016-03-26 06:16:23 +08:00
|
|
|
|
2017-05-09 02:29:26 +08:00
|
|
|
## Amazon Credentials
|
|
|
|
|
## Credentials are loaded in the following order
|
2022-08-10 00:57:31 +08:00
|
|
|
## 1) Web identity provider credentials via STS if role_arn and
|
|
|
|
|
## web_identity_token_file are specified
|
2021-08-04 05:29:26 +08:00
|
|
|
## 2) Assumed credentials via STS if role_arn is specified
|
|
|
|
|
## 3) explicit credentials from 'access_key' and 'secret_key'
|
|
|
|
|
## 4) shared profile from 'profile'
|
|
|
|
|
## 5) environment variables
|
|
|
|
|
## 6) shared credentials file
|
|
|
|
|
## 7) EC2 Instance Profile
|
2022-04-08 06:01:21 +08:00
|
|
|
# access_key = ""
|
|
|
|
|
# secret_key = ""
|
|
|
|
|
# token = ""
|
|
|
|
|
# role_arn = ""
|
|
|
|
|
# web_identity_token_file = ""
|
|
|
|
|
# role_session_name = ""
|
|
|
|
|
# profile = ""
|
|
|
|
|
# shared_credential_file = ""
|
2017-05-09 02:29:26 +08:00
|
|
|
|
2018-08-01 06:07:21 +08:00
|
|
|
## Endpoint to make request against, the correct endpoint is automatically
|
|
|
|
|
## determined and this option should only be set if you wish to override the
|
|
|
|
|
## default.
|
|
|
|
|
## ex: endpoint_url = "http://localhost:8000"
|
|
|
|
|
# endpoint_url = ""
|
|
|
|
|
|
2022-06-22 04:50:06 +08:00
|
|
|
## Set http_proxy
|
|
|
|
|
# use_system_proxy = false
|
2021-02-27 02:58:28 +08:00
|
|
|
# http_proxy_url = "http://localhost:8888"
|
|
|
|
|
|
2022-08-10 00:57:31 +08:00
|
|
|
## The minimum period for Cloudwatch metrics is 1 minute (60s). However not
|
|
|
|
|
## all metrics are made available to the 1 minute period. Some are collected
|
|
|
|
|
## at 3 minute, 5 minute, or larger intervals.
|
|
|
|
|
## See https://aws.amazon.com/cloudwatch/faqs/#monitoring.
|
|
|
|
|
## Note that if a period is configured that is smaller than the minimum for a
|
|
|
|
|
## particular metric, that metric will not be returned by the Cloudwatch API
|
|
|
|
|
## and will not be collected by Telegraf.
|
2016-11-07 20:14:04 +08:00
|
|
|
#
|
2022-08-10 00:57:31 +08:00
|
|
|
## Requested CloudWatch aggregation Period (required)
|
|
|
|
|
## Must be a multiple of 60s.
|
2016-11-07 20:14:04 +08:00
|
|
|
period = "5m"
|
2016-03-26 06:16:23 +08:00
|
|
|
|
2022-08-10 00:57:31 +08:00
|
|
|
## Collection Delay (required)
|
|
|
|
|
## Must account for metrics availability via CloudWatch API
|
2016-11-07 20:14:04 +08:00
|
|
|
delay = "5m"
|
2016-03-26 06:16:23 +08:00
|
|
|
|
2019-04-23 08:36:46 +08:00
|
|
|
## Recommended: use metric 'interval' that is a multiple of 'period' to avoid
|
2016-03-26 06:16:23 +08:00
|
|
|
## gaps or overlap in pulled data
|
2016-11-07 20:14:04 +08:00
|
|
|
interval = "5m"
|
2016-03-26 06:16:23 +08:00
|
|
|
|
2022-08-10 00:57:31 +08:00
|
|
|
## Recommended if "delay" and "period" are both within 3 hours of request
|
|
|
|
|
## time. Invalid values will be ignored. Recently Active feature will only
|
|
|
|
|
## poll for CloudWatch ListMetrics values that occurred within the last 3h.
|
|
|
|
|
## If enabled, it will reduce total API usage of the CloudWatch ListMetrics
|
|
|
|
|
## API and require less memory to retain.
|
|
|
|
|
## Do not enable if "period" or "delay" is longer than 3 hours, as it will
|
|
|
|
|
## not return data more than 3 hours old.
|
2020-09-30 06:31:38 +08:00
|
|
|
## See https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_ListMetrics.html
|
|
|
|
|
#recently_active = "PT3H"
|
|
|
|
|
|
2019-04-23 08:36:46 +08:00
|
|
|
## Configure the TTL for the internal cache of metrics.
|
|
|
|
|
# cache_ttl = "1h"
|
|
|
|
|
|
2021-08-11 05:47:23 +08:00
|
|
|
## Metric Statistic Namespaces (required)
|
|
|
|
|
namespaces = ["AWS/ELB"]
|
2022-08-10 00:57:31 +08:00
|
|
|
## Single metric statistic namespace appended to namespaces on startup
|
2021-08-11 05:47:23 +08:00
|
|
|
# namespace = "AWS/ELB"
|
2016-03-26 06:16:23 +08:00
|
|
|
|
2022-08-10 00:57:31 +08:00
|
|
|
## Maximum requests per second. Note that the global default AWS rate limit
|
|
|
|
|
## is 50 reqs/sec, so if you define multiple namespaces, these should add up
|
|
|
|
|
## to a maximum of 50.
|
2017-03-16 06:20:18 +08:00
|
|
|
## See http://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_limits.html
|
2019-04-23 08:36:46 +08:00
|
|
|
# ratelimit = 25
|
|
|
|
|
|
2019-10-22 05:18:55 +08:00
|
|
|
## Timeout for http requests made by the cloudwatch client.
|
|
|
|
|
# timeout = "5s"
|
|
|
|
|
|
2022-08-02 03:09:25 +08:00
|
|
|
## Batch Size
|
|
|
|
|
## The size of each batch to send requests to Cloudwatch. 500 is the
|
|
|
|
|
## suggested largest size. If a request gets to large (413 errors), consider
|
|
|
|
|
## reducing this amount.
|
|
|
|
|
# batch_size = 500
|
|
|
|
|
|
2019-04-23 08:36:46 +08:00
|
|
|
## Namespace-wide statistic filters. These allow fewer queries to be made to
|
|
|
|
|
## cloudwatch.
|
2022-08-10 00:57:31 +08:00
|
|
|
# statistic_include = ["average", "sum", "minimum", "maximum", sample_count"]
|
2019-04-23 08:36:46 +08:00
|
|
|
# statistic_exclude = []
|
2016-08-26 08:46:38 +08:00
|
|
|
|
2019-04-23 08:36:46 +08:00
|
|
|
## Metrics to Pull
|
2016-03-26 06:16:23 +08:00
|
|
|
## Defaults to all Metrics in Namespace if nothing is provided
|
|
|
|
|
## Refreshes Namespace available metrics every 1h
|
2019-04-23 08:36:46 +08:00
|
|
|
#[[inputs.cloudwatch.metrics]]
|
|
|
|
|
# names = ["Latency", "RequestCount"]
|
|
|
|
|
#
|
|
|
|
|
# ## Statistic filters for Metric. These allow for retrieving specific
|
|
|
|
|
# ## statistics for an individual metric.
|
2022-08-10 00:57:31 +08:00
|
|
|
# # statistic_include = ["average", "sum", "minimum", "maximum", sample_count"]
|
2019-04-23 08:36:46 +08:00
|
|
|
# # statistic_exclude = []
|
|
|
|
|
#
|
2022-08-10 00:57:31 +08:00
|
|
|
# ## Dimension filters for Metric.
|
|
|
|
|
# ## All dimensions defined for the metric names must be specified in order
|
|
|
|
|
# ## to retrieve the metric statistics.
|
2021-04-28 09:41:52 +08:00
|
|
|
# ## 'value' has wildcard / 'glob' matching support such as 'p-*'.
|
2019-04-23 08:36:46 +08:00
|
|
|
# [[inputs.cloudwatch.metrics.dimensions]]
|
|
|
|
|
# name = "LoadBalancerName"
|
|
|
|
|
# value = "p-example"
|
2016-03-26 06:16:23 +08:00
|
|
|
```
|
2021-11-25 02:55:55 +08:00
|
|
|
|
|
|
|
|
## Requirements and Terminology
|
2016-03-26 06:16:23 +08:00
|
|
|
|
2022-08-10 00:57:31 +08:00
|
|
|
Plugin Configuration utilizes [CloudWatch concepts][concept] and access pattern to
|
2022-06-08 05:10:18 +08:00
|
|
|
allow monitoring of any CloudWatch Metric.
|
2016-03-26 06:16:23 +08:00
|
|
|
|
2022-08-10 00:57:31 +08:00
|
|
|
- `region` must be a valid AWS [region][] value
|
|
|
|
|
- `period` must be a valid CloudWatch [period][] value
|
|
|
|
|
- `namespace` must be a valid CloudWatch [namespace][] value
|
|
|
|
|
- `names` must be valid CloudWatch [metric][] names
|
|
|
|
|
- `dimensions` must be valid CloudWatch [dimension][] name/value pairs
|
2016-03-26 06:16:23 +08:00
|
|
|
|
2022-06-08 05:10:18 +08:00
|
|
|
Omitting or specifying a value of `'*'` for a dimension value configures all
|
|
|
|
|
available metrics that contain a dimension with the specified name to be
|
|
|
|
|
retrieved. If specifying >1 dimension, then the metric must contain *all* the
|
|
|
|
|
configured dimensions where the the value of the wildcard dimension is ignored.
|
2016-05-25 19:30:39 +08:00
|
|
|
|
|
|
|
|
Example:
|
2021-11-25 02:55:55 +08:00
|
|
|
|
|
|
|
|
```toml
|
2019-04-23 08:36:46 +08:00
|
|
|
[[inputs.cloudwatch]]
|
|
|
|
|
period = "1m"
|
|
|
|
|
interval = "5m"
|
2016-05-25 19:30:39 +08:00
|
|
|
|
2019-04-23 08:36:46 +08:00
|
|
|
[[inputs.cloudwatch.metrics]]
|
|
|
|
|
names = ["Latency"]
|
2016-05-25 19:30:39 +08:00
|
|
|
|
2019-04-23 08:36:46 +08:00
|
|
|
## Dimension filters for Metric (optional)
|
|
|
|
|
[[inputs.cloudwatch.metrics.dimensions]]
|
|
|
|
|
name = "LoadBalancerName"
|
|
|
|
|
value = "p-example"
|
|
|
|
|
|
|
|
|
|
[[inputs.cloudwatch.metrics.dimensions]]
|
|
|
|
|
name = "AvailabilityZone"
|
|
|
|
|
value = "*"
|
2016-05-25 19:30:39 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
If the following ELBs are available:
|
2021-11-25 02:55:55 +08:00
|
|
|
|
2016-05-25 19:30:39 +08:00
|
|
|
- name: `p-example`, availabilityZone: `us-east-1a`
|
|
|
|
|
- name: `p-example`, availabilityZone: `us-east-1b`
|
|
|
|
|
- name: `q-example`, availabilityZone: `us-east-1a`
|
|
|
|
|
- name: `q-example`, availabilityZone: `us-east-1b`
|
|
|
|
|
|
|
|
|
|
Then 2 metrics will be output:
|
2021-11-25 02:55:55 +08:00
|
|
|
|
2016-05-25 19:30:39 +08:00
|
|
|
- name: `p-example`, availabilityZone: `us-east-1a`
|
|
|
|
|
- name: `p-example`, availabilityZone: `us-east-1b`
|
|
|
|
|
|
2022-06-08 05:10:18 +08:00
|
|
|
If the `AvailabilityZone` wildcard dimension was omitted, then a single metric
|
|
|
|
|
(name: `p-example`) would be exported containing the aggregate values of the ELB
|
|
|
|
|
across availability zones.
|
2016-05-25 19:30:39 +08:00
|
|
|
|
2022-06-08 05:10:18 +08:00
|
|
|
To maximize efficiency and savings, consider making fewer requests by increasing
|
|
|
|
|
`interval` but keeping `period` at the duration you would like metrics to be
|
|
|
|
|
reported. The above example will request metrics from Cloudwatch every 5 minutes
|
|
|
|
|
but will output five metrics timestamped one minute apart.
|
|
|
|
|
|
2021-11-25 02:55:55 +08:00
|
|
|
## Restrictions and Limitations
|
|
|
|
|
|
2022-08-10 00:57:31 +08:00
|
|
|
- CloudWatch metrics are not available instantly via the CloudWatch API.
|
|
|
|
|
You should adjust your collection `delay` to account for this lag in metrics
|
|
|
|
|
availability based on your [monitoring subscription level][using]
|
|
|
|
|
- CloudWatch API usage incurs cost - see [GetMetricData Pricing][pricing]
|
2016-03-26 06:16:23 +08:00
|
|
|
|
2022-06-08 05:10:18 +08:00
|
|
|
## Metrics
|
2016-03-26 06:16:23 +08:00
|
|
|
|
2022-06-08 05:10:18 +08:00
|
|
|
Each CloudWatch Namespace monitored records a measurement with fields for each
|
|
|
|
|
available Metric Statistic. Namespace and Metrics are represented in [snake
|
|
|
|
|
case](https://en.wikipedia.org/wiki/Snake_case)
|
2016-03-26 06:16:23 +08:00
|
|
|
|
|
|
|
|
- cloudwatch_{namespace}
|
|
|
|
|
- {metric}_sum (metric Sum value)
|
|
|
|
|
- {metric}_average (metric Average value)
|
|
|
|
|
- {metric}_minimum (metric Minimum value)
|
|
|
|
|
- {metric}_maximum (metric Maximum value)
|
|
|
|
|
- {metric}_sample_count (metric SampleCount value)
|
|
|
|
|
|
2022-06-08 05:10:18 +08:00
|
|
|
### Tags
|
2016-03-26 06:16:23 +08:00
|
|
|
|
2022-06-08 05:10:18 +08:00
|
|
|
Each measurement is tagged with the following identifiers to uniquely identify
|
|
|
|
|
the associated metric Tag Dimension names are represented in [snake
|
|
|
|
|
case](https://en.wikipedia.org/wiki/Snake_case)
|
2016-03-26 06:16:23 +08:00
|
|
|
|
|
|
|
|
- All measurements have the following tags:
|
|
|
|
|
- region (CloudWatch Region)
|
2022-08-10 00:57:31 +08:00
|
|
|
- {dimension-name} (Cloudwatch Dimension value - one per metric dimension)
|
2016-03-26 06:16:23 +08:00
|
|
|
|
2021-11-25 02:55:55 +08:00
|
|
|
## Troubleshooting
|
2018-07-07 15:21:21 +08:00
|
|
|
|
|
|
|
|
You can use the aws cli to get a list of available metrics and dimensions:
|
2021-11-25 02:55:55 +08:00
|
|
|
|
|
|
|
|
```shell
|
2018-07-07 15:21:21 +08:00
|
|
|
aws cloudwatch list-metrics --namespace AWS/EC2 --region us-east-1
|
|
|
|
|
aws cloudwatch list-metrics --namespace AWS/EC2 --region us-east-1 --metric-name CPUCreditBalance
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
If the expected metrics are not returned, you can try getting them manually
|
|
|
|
|
for a short period of time:
|
2021-11-25 02:55:55 +08:00
|
|
|
|
|
|
|
|
```shell
|
2019-05-02 04:09:32 +08:00
|
|
|
aws cloudwatch get-metric-data \
|
|
|
|
|
--start-time 2018-07-01T00:00:00Z \
|
|
|
|
|
--end-time 2018-07-01T00:15:00Z \
|
|
|
|
|
--metric-data-queries '[
|
|
|
|
|
{
|
|
|
|
|
"Id": "avgCPUCreditBalance",
|
|
|
|
|
"MetricStat": {
|
|
|
|
|
"Metric": {
|
|
|
|
|
"Namespace": "AWS/EC2",
|
|
|
|
|
"MetricName": "CPUCreditBalance",
|
|
|
|
|
"Dimensions": [
|
|
|
|
|
{
|
|
|
|
|
"Name": "InstanceId",
|
|
|
|
|
"Value": "i-deadbeef"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
"Period": 300,
|
|
|
|
|
"Stat": "Average"
|
|
|
|
|
},
|
|
|
|
|
"Label": "avgCPUCreditBalance"
|
|
|
|
|
}
|
|
|
|
|
]'
|
2018-07-07 15:21:21 +08:00
|
|
|
```
|
|
|
|
|
|
2022-06-08 05:10:18 +08:00
|
|
|
## Example Output
|
2016-03-26 06:16:23 +08:00
|
|
|
|
2021-11-25 02:55:55 +08:00
|
|
|
```shell
|
2017-05-13 06:22:29 +08:00
|
|
|
$ ./telegraf --config telegraf.conf --input-filter cloudwatch --test
|
2019-04-23 08:36:46 +08:00
|
|
|
> cloudwatch_aws_elb,load_balancer_name=p-example,region=us-east-1 latency_average=0.004810798017284538,latency_maximum=0.1100282669067383,latency_minimum=0.0006084442138671875,latency_sample_count=4029,latency_sum=19.382705211639404 1459542420000000000
|
2016-03-26 06:16:23 +08:00
|
|
|
```
|
2022-08-10 00:57:31 +08:00
|
|
|
|
|
|
|
|
[concept]: http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/cloudwatch_concepts.html
|
|
|
|
|
[credentials]: https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html#shared-credentials-file
|
|
|
|
|
[dimension]: http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/cloudwatch_concepts.html#Dimension
|
|
|
|
|
[env]: https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html#environment-variables
|
|
|
|
|
[iam-roles]: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html
|
|
|
|
|
[metric]: http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/cloudwatch_concepts.html#Metric
|
|
|
|
|
[namespace]: http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/cloudwatch_concepts.html#Namespace
|
|
|
|
|
[period]: http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/cloudwatch_concepts.html#CloudWatchPeriods
|
|
|
|
|
[pricing]: https://aws.amazon.com/cloudwatch/pricing/
|
|
|
|
|
[region]: http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/cloudwatch_concepts.html#CloudWatchRegions
|
|
|
|
|
[using]: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-cloudwatch-new.html
|