Skip to content

Commit

Permalink
[Metricbeat AWS] check if cpuOptions is nil in DescribeInstances outp…
Browse files Browse the repository at this point in the history
…ut (#17418)

* check if cpuOptions is nil
  • Loading branch information
kaiyan-sheng committed Apr 3, 2020
1 parent ee1d6f5 commit 8d43169
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Further revise check for bad data in docker/memory. {pull}17400[17400]
- Fix issue in Jolokia module when mbean contains multiple quoted properties. {issue}17375[17375] {pull}17374[17374]
- Combine cloudwatch aggregated metrics into single event. {pull}17345[17345]
- check if cpuOptions field is nil in DescribeInstances output in ec2 metricset. {pull}17418[17418]

*Packetbeat*

Expand Down
27 changes: 18 additions & 9 deletions x-pack/metricbeat/module/aws/ec2/ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,11 @@ func (m *MetricSet) createCloudWatchEvents(getMetricDataResults []cloudwatch.Met

events[instanceID].RootFields.Put("cloud.instance.id", instanceID)
events[instanceID].RootFields.Put("cloud.machine.type", machineType)
events[instanceID].RootFields.Put("cloud.availability_zone", *instanceOutput[instanceID].Placement.AvailabilityZone)

placement := instanceOutput[instanceID].Placement
if placement != nil {
events[instanceID].RootFields.Put("cloud.availability_zone", *placement.AvailabilityZone)
}

if len(output.Values) > timestampIdx {
metricSetFieldResults[instanceID][labels[metricNameIdx]] = fmt.Sprint(output.Values[timestampIdx])
Expand All @@ -227,23 +231,28 @@ func (m *MetricSet) createCloudWatchEvents(getMetricDataResults []cloudwatch.Met

monitoringStates[instanceID] = monitoringState

events[instanceID].MetricSetFields.Put("instance.image.id", *instanceOutput[instanceID].ImageId)
events[instanceID].MetricSetFields.Put("instance.state.name", instanceStateName)
events[instanceID].MetricSetFields.Put("instance.state.code", *instanceOutput[instanceID].State.Code)
events[instanceID].MetricSetFields.Put("instance.monitoring.state", monitoringState)
events[instanceID].MetricSetFields.Put("instance.core.count", *instanceOutput[instanceID].CpuOptions.CoreCount)
events[instanceID].MetricSetFields.Put("instance.threads_per_core", *instanceOutput[instanceID].CpuOptions.ThreadsPerCore)
cpuOptions := instanceOutput[instanceID].CpuOptions
if cpuOptions != nil {
events[instanceID].MetricSetFields.Put("instance.core.count", *cpuOptions.CoreCount)
events[instanceID].MetricSetFields.Put("instance.threads_per_core", *cpuOptions.ThreadsPerCore)
}

publicIP := instanceOutput[instanceID].PublicIpAddress
if publicIP != nil {
events[instanceID].MetricSetFields.Put("instance.public.ip", *publicIP)
}

events[instanceID].MetricSetFields.Put("instance.public.dns_name", *instanceOutput[instanceID].PublicDnsName)
events[instanceID].MetricSetFields.Put("instance.private.dns_name", *instanceOutput[instanceID].PrivateDnsName)
privateIP := instanceOutput[instanceID].PrivateIpAddress
if privateIP != nil {
events[instanceID].MetricSetFields.Put("instance.private.ip", *privateIP)
}

events[instanceID].MetricSetFields.Put("instance.image.id", *instanceOutput[instanceID].ImageId)
events[instanceID].MetricSetFields.Put("instance.state.name", instanceStateName)
events[instanceID].MetricSetFields.Put("instance.state.code", *instanceOutput[instanceID].State.Code)
events[instanceID].MetricSetFields.Put("instance.monitoring.state", monitoringState)
events[instanceID].MetricSetFields.Put("instance.public.dns_name", *instanceOutput[instanceID].PublicDnsName)
events[instanceID].MetricSetFields.Put("instance.private.dns_name", *instanceOutput[instanceID].PrivateDnsName)
}
}
}
Expand Down

0 comments on commit 8d43169

Please sign in to comment.