Skip to content

Instantly share code, notes, and snippets.

@aodj
Created August 10, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aodj/d3feade832614ca42f6e to your computer and use it in GitHub Desktop.
Save aodj/d3feade832614ca42f6e to your computer and use it in GitHub Desktop.
Example Heka configuration to get some metadata items from the `ec2metadata` tool
[ec2_metadata]
type = "ProcessInput"
ticker_interval = 10
decoder = "ec2_metadata_decoder"
[ec2_metadata.command.0]
bin = "/usr/bin/ec2metadata"
args = ["--ami-id", "--instance-id", "--instance-type", "--local-ipv4"]
[ec2_metadata_decoder]
type = "PayloadRegexDecoder"
log_errors = true
match_regex = '^(?P<AmiID>\S+)\n(?P<InstanceID>\S+)\n(?P<InstanceType>\S+)\n(?P<InstanceIPV4>\S+)'
[ec2_metadata_decoder.message_fields]
Type = "ec2metadata"
ami_id = "%AmiID%"
instance_id = "%InstanceID%"
instance_type = "%InstanceType%"
instance_ipv4|ipv4 = "%InstanceIPV4%"
[ec2_metadata_encoder]
type = "ESJsonEncoder"
index = "%{Type}"
type_name = "%{Hostname}"
es_index_from_timestamp = true
fields = ["DynamicFields", "Uuid", "Logger", "Hostname"]
dynamic_fields = ["ami_id", "instance_id", "instance_type", "instance_ipv4"]
[ec2_metadata_encoder.field_mappings]
Timestamp = "@timestamp"
[ESLogstashV0Encoder]
[out:stdout]
type = "LogOutput"
message_matcher = "TRUE"
encoder = "ec2_metadata_encoder"
payload_only = false
@aodj
Copy link
Author

aodj commented Aug 10, 2015

The ec2metadata tool can be found here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment