Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add calculate_rate for NetworkIn/Out, DiskRead/WriteBytes and DiskRead/WriteOps #13203

Merged
merged 4 commits into from
Aug 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Add cgroup memory stats to docker/memory metricset {pull}12916[12916]
- Add AWS elb metricset. {pull}12952[12952] {issue}11701[11701]
- Add AWS ebs metricset. {pull}13167[13167] {issue}11699[11699]
- Add rate metrics for ec2 metricset. {pull}13203[13203]

*Packetbeat*

Expand Down
80 changes: 80 additions & 0 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,16 @@ type: long
The number of packets received on all network interfaces by the instance.


type: long

--

*`aws.ec2.network.in.packets_per_sec`*::
+
--
The number of packets per second sent out on all network interfaces by the instance.


type: long

--
Expand All @@ -960,6 +970,16 @@ type: long
The number of packets sent out on all network interfaces by the instance.


type: long

--

*`aws.ec2.network.out.packets_per_sec`*::
+
--
The number of packets per second sent out on all network interfaces by the instance.


type: long

--
Expand All @@ -976,6 +996,16 @@ format: bytes

--

*`aws.ec2.network.in.bytes_per_sec`*::
+
--
The number of bytes per second received on all network interfaces by the instance.


type: long

--

*`aws.ec2.network.out.bytes`*::
+
--
Expand All @@ -988,6 +1018,16 @@ format: bytes

--

*`aws.ec2.network.out.bytes_per_sec`*::
+
--
The number of bytes per second sent out on all network interfaces by the instance.


type: long

--

*`aws.ec2.diskio.read.bytes`*::
+
--
Expand All @@ -1000,6 +1040,16 @@ format: bytes

--

*`aws.ec2.diskio.read.bytes_per_sec`*::
+
--
Bytes read per second from all instance store volumes available to the instance.


type: long

--

*`aws.ec2.diskio.write.bytes`*::
+
--
Expand All @@ -1012,12 +1062,32 @@ format: bytes

--

*`aws.ec2.diskio.write.bytes_per_sec`*::
+
--
Bytes written per second to all instance store volumes available to the instance.


type: long

--

*`aws.ec2.diskio.read.ops`*::
+
--
Completed read operations from all instance store volumes available to the instance in a specified period of time.


type: long

--

*`aws.ec2.diskio.read.ops_per_sec`*::
+
--
Completed read operations per second from all instance store volumes available to the instance in a specified period of time.


type: long

--
Expand All @@ -1028,6 +1098,16 @@ type: long
Completed write operations to all instance store volumes available to the instance in a specified period of time.


type: long

--

*`aws.ec2.diskio.write.ops_per_sec`*::
+
--
Completed write operations per second to all instance store volumes available to the instance in a specified period of time.


type: long

--
Expand Down
50 changes: 31 additions & 19 deletions x-pack/metricbeat/module/aws/ec2/_meta/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,45 @@
"aws": {
"ec2": {
"cpu": {
"credit_balance": 144,
"credit_usage": 0.005335,
"credit_balance": 576,
"credit_usage": 0.186525,
"surplus_credit_balance": 0,
"surplus_credits_charged": 0,
"total": {
"pct": 0.0989071038248902
"pct": 2.0000740946562456
}
},
"diskio": {
"read": {
"bytes": 0,
"count": 0
"bytes_per_sec": 0,
"count": 0,
"count_per_sec": 0
},
"write": {
"bytes": 0,
"count": 0
"bytes_per_sec": 0,
"count": 0,
"count_per_sec": 0
}
},
"instance": {
"core": {
"count": 1
"count": 2
},
"image": {
"id": "ami-05b3bcf7f311194b3"
"id": "ami-f920cd94"
},
"monitoring": {
"state": "disabled"
},
"private": {
"dns_name": "ip-172-31-10-23.ap-southeast-1.compute.internal",
"ip": "172.31.10.23"
"dns_name": "ip-10-0-0-148.ec2.internal",
"ip": "10.0.0.148"
},
"public": {
"dns_name": "ec2-18-136-198-93.ap-southeast-1.compute.amazonaws.com",
"ip": "18.136.198.93"
"dns_name": "ec2-54-226-109-162.compute-1.amazonaws.com",
"ip": "54.226.109.162"
},
"state": {
"code": 16,
Expand All @@ -47,31 +51,39 @@
},
"network": {
"in": {
"bytes": 85.2,
"packets": 1.4
"bytes": 1368258.2,
"bytes_per_sec": 4560.8606666666665,
"packets": 2904.6,
"packets_per_sec": 9.682
},
"out": {
"bytes": 108.8,
"packets": 2
"bytes": 425826.8,
"bytes_per_sec": 1419.4226666666666,
"packets": 2910,
"packets_per_sec": 9.7
}
},
"status": {
"check_failed": 0,
"check_failed_instance": 0,
"check_failed_system": 0
}
},
"tags": {
"Cost": "$614.01",
"Name": "container-registry-test-ui.elastic.co"
}
},
"cloud": {
"availability_zone": "ap-southeast-1b",
"availability_zone": "us-east-1b",
"instance": {
"id": "i-0c68eeb552231a8d0"
"id": "i-77f84332"
},
"machine": {
"type": "t2.micro"
"type": "t2.medium"
},
"provider": "aws",
"region": "ap-southeast-1"
"region": "us-east-1"
},
"event": {
"dataset": "aws.ec2",
Expand Down
32 changes: 32 additions & 0 deletions x-pack/metricbeat/module/aws/ec2/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,70 @@
type: long
description: >
The number of packets received on all network interfaces by the instance.
- name: network.in.packets_per_sec
type: long
description: >
The number of packets per second sent out on all network interfaces by the instance.
- name: network.out.packets
type: long
description: >
The number of packets sent out on all network interfaces by the instance.
- name: network.out.packets_per_sec
type: long
description: >
The number of packets per second sent out on all network interfaces by the instance.
- name: network.in.bytes
type: long
format: bytes
description: >
The number of bytes received on all network interfaces by the instance.
- name: network.in.bytes_per_sec
type: long
description: >
The number of bytes per second received on all network interfaces by the instance.
- name: network.out.bytes
type: long
format: bytes
description: >
The number of bytes sent out on all network interfaces by the instance.
- name: network.out.bytes_per_sec
type: long
description: >
The number of bytes per second sent out on all network interfaces by the instance.
- name: diskio.read.bytes
type: long
format: bytes
description: >
Bytes read from all instance store volumes available to the instance.
- name: diskio.read.bytes_per_sec
type: long
description: >
Bytes read per second from all instance store volumes available to the instance.
- name: diskio.write.bytes
type: long
format: bytes
description: >
Bytes written to all instance store volumes available to the instance.
- name: diskio.write.bytes_per_sec
type: long
description: >
Bytes written per second to all instance store volumes available to the instance.
- name: diskio.read.ops
type: long
description: >
Completed read operations from all instance store volumes available to the instance in a specified period of time.
- name: diskio.read.ops_per_sec
type: long
description: >
Completed read operations per second from all instance store volumes available to the instance in a specified period of time.
- name: diskio.write.ops
type: long
description: >
Completed write operations to all instance store volumes available to the instance in a specified period of time.
- name: diskio.write.ops_per_sec
type: long
description: >
Completed write operations per second to all instance store volumes available to the instance in a specified period of time.
- name: status.check_failed
type: long
description: >
Expand Down
35 changes: 35 additions & 0 deletions x-pack/metricbeat/module/aws/ec2/ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"strings"
"time"

"github.com/elastic/beats/libbeat/common"

"github.com/aws/aws-sdk-go-v2/service/cloudwatch"
"github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/aws/aws-sdk-go-v2/service/ec2/ec2iface"
Expand Down Expand Up @@ -160,6 +162,9 @@ func (m *MetricSet) createCloudWatchEvents(getMetricDataResults []cloudwatch.Met
metricSetFieldResults[instanceID] = map[string]interface{}{}
}

// monitoring state for each instance
monitoringStates := map[string]string{}

// Find a timestamp for all metrics in output
timestamp := aws.FindTimestamp(getMetricDataResults)
if !timestamp.IsZero() {
Expand Down Expand Up @@ -193,6 +198,8 @@ func (m *MetricSet) createCloudWatchEvents(getMetricDataResults []cloudwatch.Met
return events, errors.Wrap(err, "instance.Monitoring.State.MarshalValue failed")
}

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)
Expand Down Expand Up @@ -227,6 +234,9 @@ func (m *MetricSet) createCloudWatchEvents(getMetricDataResults []cloudwatch.Met
return events, errors.Wrap(err, "EventMapping failed")
}

// add rate metrics
calculateRate(resultMetricsetFields, monitoringStates[instanceID])

events[instanceID].MetricSetFields.Update(resultMetricsetFields)
if len(events[instanceID].MetricSetFields) < 5 {
m.Logger().Info("Missing Cloudwatch data, this is expected for non-running instances" +
Expand All @@ -239,6 +249,31 @@ func (m *MetricSet) createCloudWatchEvents(getMetricDataResults []cloudwatch.Met
return events, nil
}

func calculateRate(resultMetricsetFields common.MapStr, monitoringState string) {
var period = 300.0
if monitoringState != "disabled" {
period = 60.0
}

metricList := []string{
"network.in.bytes",
"network.out.bytes",
"network.in.packets",
"network.out.packets",
"diskio.read.bytes",
"diskio.write.bytes",
"diskio.read.count",
"diskio.write.count"}

for _, metricName := range metricList {
metricValue, err := resultMetricsetFields.GetValue(metricName)
if err == nil && metricValue != nil {
rateValue := metricValue.(float64) / period
resultMetricsetFields.Put(metricName+"_per_sec", rateValue)
}
}
kaiyan-sheng marked this conversation as resolved.
Show resolved Hide resolved
}

func getInstancesPerRegion(svc ec2iface.ClientAPI) (instanceIDs []string, instancesOutputs map[string]ec2.Instance, err error) {
instancesOutputs = map[string]ec2.Instance{}
output := ec2.DescribeInstancesOutput{NextToken: nil}
Expand Down
Loading