Class: LogStash::Inputs::CloudWatch
- Inherits:
-
Base
- Object
- Base
- LogStash::Inputs::CloudWatch
- Includes:
- PluginMixins::AwsConfig
- Defined in:
- lib/logstash/inputs/cloudwatch.rb
Overview
Pull events from the Amazon Web Services CloudWatch API.
To use this plugin, you must have an AWS account, and the following policy.
Typically, you should setup an IAM policy, create a user and apply the IAM policy to the user.
A sample policy for EC2 metrics is as follows:
- source,json
-
{
"Version": "2012-10-17", "Statement": [ { "Sid": "Stmt1444715676000", "Effect": "Allow", "Action": [ "cloudwatch:GetMetricStatistics", "cloudwatch:ListMetrics" ], "Resource": "*" }, { "Sid": "Stmt1444716576170", "Effect": "Allow", "Action": [ "ec2:DescribeInstances" ], "Resource": "*" } ]
}
See aws.amazon.com/iam/ for more details on setting up AWS identities.
# Configuration Example
- source, ruby
-
input {
cloudwatch { namespace => "AWS/EC2" metrics => [ "CPUUtilization" ] filters => { "tag:Group" => "API-Production" } region => "us-east-1" }
}
input {
cloudwatch { namespace => "AWS/EBS" metrics => ["VolumeQueueLength"] filters => { "tag:Monitoring" => "Yes" } region => "us-east-1" }
}
input {
cloudwatch { namespace => "AWS/RDS" metrics => ["CPUUtilization", "CPUCreditUsage"] filters => { "EngineName" => "mysql" } # Only supports EngineName, DatabaseClass and DBInstanceIdentifier region => "us-east-1" }
}
Instance Method Summary collapse
- #aws_service_endpoint(region) ⇒ Object
- #register ⇒ Object
-
#run(queue) ⇒ Object
Runs the poller to get metrics for the provided namespace.
Instance Method Details
#aws_service_endpoint(region) ⇒ Object
124 125 126 |
# File 'lib/logstash/inputs/cloudwatch.rb', line 124 def aws_service_endpoint(region) { region: region } end |
#register ⇒ Object
128 129 130 131 132 133 134 135 |
# File 'lib/logstash/inputs/cloudwatch.rb', line 128 def register AWS.config(:logger => @logger) raise 'Interval needs to be higher than period' unless @interval >= @period raise 'Interval must be divisible by period' unless @interval % @period == 0 @last_check = Time.now end |
#run(queue) ⇒ Object
Runs the poller to get metrics for the provided namespace
140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/logstash/inputs/cloudwatch.rb', line 140 def run(queue) Stud.interval(@interval) do @logger.info('Polling CloudWatch API') raise 'No metrics to query' unless metrics_for(@namespace).count > 0 metrics_for(@namespace).each do |metric| @logger.debug "Polling metric #{metric}" @logger.debug "Filters: #{aws_filters}" @combined ? from_filters(queue, metric) : from_resources(queue, metric) end end # loop end |