chore: Added Maven wrapper for consistent build environment (#852)
- chore: Added Maven wrapper
Signed-off-by: dhoard doug.hoard@gmail.com Signed-off-by: Doug Hoard dhoard@users.noreply.github.com
版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9
京公网安备 11010802047560号
CloudWatch Exporter
A Prometheus exporter for Amazon CloudWatch.
Alternatives
For ECS workloads, there is also an ECS exporter.
For a different approach to CloudWatch metrics, with automatic discovery, consider Yet Another CloudWatch Exporter (YACE).
Building and running
Cloudwatch Exporter requires at least Java 11.
./mvnw packageto build.java -jar target/cloudwatch_exporter-*-SNAPSHOT-jar-with-dependencies.jar 9106 example.ymlto run.The most recent pre-built JAR can be found at http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22cloudwatch_exporter%22
Credentials and permissions
The CloudWatch Exporter uses the AWS Java SDK, which offers a variety of ways to provide credentials. This includes the
AWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEYenvironment variables.The
cloudwatch:ListMetrics,cloudwatch:GetMetricStatisticsandcloudwatch:GetMetricDataIAM permissions are required. Thetag:GetResourcesIAM permission is also required to use theaws_tag_selectfeature.Configuration
The configuration is in YAML.
An example with common options and
aws_dimension_select:A similar example with common options and
aws_tag_select:Note: configuration examples for different namespaces can be found in examples directory
Note: A configuration builder can be found here.
aws cloudwatch list-metricsto find out which dimensions you need to include for your metric.aws_tag_select. Specify a map from a tag key to a list of tag values to apply tag filtering on resources from which metrics will be gathered.aws_tag_select. Specify the resource type to filter on.resource_type_selectionshould be comprised asservice:resource_type, as per the resource group tagging API. Whereresource_typecould be an empty string, like in S3 case:resource_type_selection: "s3:".aws_tag_select. For the current metric, specify which CloudWatch dimension maps to the ARN resource ID.resource_id_dimensiondoesn’t conform to the convention for resource ID an alternative regular expression to extract the resource ID from the ARN can be given here. The default is `(?:([^:/]+)pNorpN.N.The above config will export time series such as
If the
aws_tag_selectfeature was used, an additional information metric will be exported for each AWS tagged resource matched by the resource type selection and tag selection (if specified), such asaws_recource_info can be joined with other metrics using group_left in PromQL such as the following:
All metrics are exported as gauges.
In addition
cloudwatch_exporter_scrape_errorwill be non-zero if an error occurred during the scrape, andcloudwatch_exporter_scrape_duration_secondscontains the duration of that scrape.cloudwatch_exporter_build_infocontains labels referencing the current build version and build release date.Build Info Metric
cloudwatch_exporter_build_infois a default cloudwatch exporter metric that contains the current cloudwatch exporter version and release date as label values. The numeric metric value is statically set to 1. If the metrics label values are “unknown” the build information scrap failed.CloudWatch doesn’t always report data
Cloudwatch reports data either always or only in some cases, example only if there is a non-zero value. The CloudWatch Exporter mirrors this behavior, so you should refer to the Cloudwatch documentation to find out if your metric is always reported or not.
Timestamps
CloudWatch has been observed to sometimes take minutes for reported values to converge. The default
delay_secondswill result in data that is at least 10 minutes old being requested to mitigate this. The samples exposed will have the timestamps of the data from CloudWatch, so usual staleness semantics will not apply and values will persist for 5m for instant vectors.In practice this means that if you evaluate an instant vector at the current time, you will not see data from CloudWatch. An expression such as
aws_elb_request_count_sum offset 10mwill allow you to access the data, and should be used in recording rules and alerts.For certain metrics which update relatively rarely, such as from S3,
set_timestampshould be configured to false so that they are not exposed with a timestamp. This is as the true timestamp from CloudWatch could be so old that Prometheus would reject the sample.FAQ: I can see the metrics in
/metricsbut not in the Prometheus web consoleThe metrics will be visible in Prometheus if you look more than
delay_secondsin the past. Try the graph view.This is an unfortunate result of a fundamental mismatch between CloudWatch and Prometheus. CloudWatch metrics converge over time, that is, the value at time
Tcan change up to some later timeT+dT. Meanwhile, Prometheus assumes that once it has scraped a sample, that is the truth, and the past does not change.To compensate for this, by default the exporter delays fetching metrics, that is, it only asks for data 10 minutes later, when almost all AWS services have converged. It also reports to Prometheus that this sample is from the past. Because Prometheus, for an instant request, only looks back 5 minutes, it never sees any data “now”.
Special handling for certain DynamoDB metrics
The DynamoDB metrics listed below break the usual CloudWatch data model.
When these metrics are requested in the TableName dimension CloudWatch will return data only for the table itself, not for its Global Secondary Indexes. Retrieving data for indexes requires requesting data across both the TableName and GlobalSecondaryIndexName dimensions. This behaviour is different to that of every other CloudWatch namespace and requires that the exporter handle these metrics differently to avoid generating duplicate HELP and TYPE lines.
When exporting one of the problematic metrics for an index the exporter will use a metric name in the format
aws_dynamodb_METRIC_index_STATISTICrather than the usualaws_dynamodb_METRIC_STATISTIC. The regular naming scheme will still be used when exporting these metrics for a table, and when exporting any other DynamoDB metrics not listed above.Reloading Configuration
There are two ways to reload configuration:
kill -HUP 1234reloadendpoint:curl -X POST localhost:9106/-/reloadIf an error occurs during the reload, check the exporter’s log output.
Cost
Amazon charges for every CloudWatch API request or for every Cloudwatch metric requested, see the current charges.
GetMetricStatistics(default) - Every metric retrieved requires one API request, which can include multiple statistics.aws_dimensionsis provided, the exporter needs to do API requests to determine what metrics to request. This should be negligible compared to the requests for the metrics themselves.In the case that all
aws_dimensionsare provided in theaws_dimension_selectlist, the exporter will not perform the above API request. It will request all possible combination of values for those dimensions. This will reduce cost as the values for the dimensions do not need to be queried anymore, assuming that all possible value combinations are present in CloudWatch.If you have 100 API requests every minute, with the price of USD10permillionrequests(asofAug2018),thatisaround45 per month. The
cloudwatch_requests_totalcounter tracks how many requests are being made.When using the
aws_tag_selectfeature, additional requests are made to the Resource Groups Tagging API, but these are free. Thetagging_api_requests_totalcounter tracks how many requests are being made for these.Experimental GetMetricData
We are transitioning to use
GetMetricsDatainstead ofGetMetricsStatistics. The benefits of usingGetMetricsDatais mainly around much better performence.Please refer to this doc explaining why it is best practice to use
GetMetricDataGetMetricStatisticsGetMetricDataTransition plan
At first this feature would be opt-in to allow you to decide when and how to test it On later versions we would swap the default so everyone can enjoy the benefits.
Cloudwatch exporter also expose a new self metric called
cloudwatch_metrics_requested_totalthat allows you to track number of requested metrics in addition to the number of API requests.Docker Images
To run the CloudWatch exporter on Docker, you can use the image from
The available tags are
main: snapshot updated on every push to the main branchlatest: the latest released versionvX.Y.Z: the specific version X.Y.Z. Note that up to version 0.11.0, the format wascloudwatch-exporter_X.Y.Z.The image exposes port 9106 and expects the config in
/config/config.yml. To configure it, you can bind-mount a config from your host:Specify the config as the CMD:
Or create a config file named
config.ymlalong with following Dockerfile in the same directory and build it withdocker build: