logstash ec2 instanceid

How to get Logstash to read your ec2 instance id

logstash.sh

!/bin/bash

EC2_INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
export EC2_INSTANCE_ID
conf=/opt/logstash/simple.conf
lsjar=/opt/logstash/logstash.jar
myjava=$(which java)
if [ -z $myjava ]; then
  echo "java is required; please install openjdk or jre"
  exit 1
fi
# spawn logstash
$myjava -jar $lsjar agent -f $conf

config file /opt/logstash/simple.conf

input {
  exec {
    type => "instance-id"
    command => "echo -e -n ${EC2_INSTANCE_ID}"
    interval => 5
  }
}
filter {
  grok {
    type => "instance-id"
    pattern => "[A-Za-z0-9_-]+"
    named_captures_only => true
  }
}
output {
  stdout { debug => true debug_format => "json" }
}

1 comment to logstash ec2 instanceid

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>