Programable cloudwatch metrics exporter for Prometheus
Install it yourself as:
$ gem install clear_skies
You can also use docker
(from https://github.com/aws/aws-sdk-ruby)
You need to configure :credentials
and a :region
to make API calls. It is recommended that you provide these via your environment. This makes it easier to rotate credentials and it keeps your secrets out of source control.
The SDK searches the following locations for credentials:
ENV['AWS_ACCESS_KEY_ID']
andENV['AWS_SECRET_ACCESS_KEY']
- Unless
ENV['AWS_SDK_CONFIG_OPT_OUT']
is set, the shared configuration files (~/.aws/credentials
and~/.aws/config
) will be checked for arole_arn
andsource_profile
, which if present will be used to attempt to assume a role. - The shared credentials ini file at
~/.aws/credentials
(more information)- Unless
ENV['AWS_SDK_CONFIG_OPT_OUT']
is set, the shared configuration ini file at~/.aws/config
will also be parsed for credentials.
- Unless
- From an instance profile when running on EC2, or from the ECS credential provider when running in an ECS container with that feature enabled.
The SDK searches the following locations for a region:
ENV['AWS_REGION']
- Unless
ENV['AWS_SDK_CONFIG_OPT_OUT']
is set, the shared configuration files (~/.aws/credentials
and~/.aws/config
) will also be checked for a region selection.
The region is used to construct an SSL endpoint. If you need to connect to a non-standard endpoint, you may specify the :endpoint
option.
To run the exporter simple do: $ clear_skies metrics_file
The metrics_file
is a ruby script that registers the metrics you wish to export.
# To grab a generic cloudwatch metric use the following method:
ClearSkies::Gauge.register(namespace, metric_name,dimensions, statistics) do |labels|
labels[:extra] = "label"
labels[:instance_id] == "something specific"
end
If you pass a block, it will be called for each dimension retrieved. The block will be passed a hash of all computed labels, and you may add more if you wish. If the blocks value is false, that dimension will be skipped.
There is a helper class for grabbing RDS metrics. It behaves the same as ClearSkies::Gauge
, except that it automatically adds the vpc_id
and tags as labels.
# To grab an RDS metric
ClearSkies::RDSGauge.register("ReadThroughput", ["DBInstanceIdentifier"], ["Average", "Minimum", "Maximum"])end
There is a helper class for grabbing ELB metrics. It behaves the same as ClearSkies::Gauge
, except that it automatically adds the vpc_id
and tags as labels.
# To grab an ELB metric
ClearSkies::ELBGauge.register("Latency", ["LoadBalancerName"], ["Average", "p90"])
There is a helper class for grabbing ElasticBeanstalk metrics. It behaves the same as ClearSkies::Gauge
, except that it automatically adds vpc_id
and application_name
as labels.
# To grab an ELB metric
ClearSkies::ElasticBeanstalkGauge.register("InstancesOk", ["EnvironmentName"], ["Average", "Minimum", "Maximum"])
If there is a namespace of metrics you wish to add, please submit a PR.
The gem is available as open source under the terms of the MIT License.