Skip to content

Commit

Permalink
[7.x](backport #28456) Fix rds metricset cpu.total.pct (#28515)
Browse files Browse the repository at this point in the history
* Fix rds metricset cpu.total.pct (#28456)

(cherry picked from commit a98cacd)

* Update CHANGELOG.next.asciidoc

Co-authored-by: kaiyan-sheng <[email protected]>
  • Loading branch information
mergify[bot] and kaiyan-sheng authored Oct 18, 2021
1 parent 2414eaf commit b5665a4
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 45 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Change vsphere.datastore.capacity.used.pct value to betweeen 0 and 1. {pull}23148[23148]
- `beat` module respects `basepath` config option. {pull}28162[28162]
- Fix list_docker.go {pull}28374[28374]
- Divide RDS metric cpu.total.pct by 100. {pull}28456[28456]

*Packetbeat*

Expand Down
55 changes: 37 additions & 18 deletions x-pack/metricbeat/module/aws/cloudwatch/metadata/rds/rds.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,10 @@ import (
"github.com/elastic/beats/v7/libbeat/logp"
"github.com/elastic/beats/v7/metricbeat/mb"
awscommon "github.com/elastic/beats/v7/x-pack/libbeat/common/aws"
"github.com/elastic/beats/v7/x-pack/metricbeat/module/aws"
)

const metadataPrefix = "aws.rds.db_instance."

// DBDetails holds detailed information from DescribeDBInstances for each rds.
type DBDetails struct {
dbArn string
dbClass string
dbAvailabilityZone string
dbIdentifier string
dbStatus string
tags []aws.Tag
}

// AddMetadata adds metadata for RDS instances from a specific region
func AddMetadata(endpoint string, regionName string, awsConfig awssdk.Config, events map[string]mb.Event) map[string]mb.Event {
svc := rds.New(awscommon.EnrichAWSConfigWithEndpoint(
Expand All @@ -43,17 +32,47 @@ func AddMetadata(endpoint string, regionName string, awsConfig awssdk.Config, ev
return events
}

for _, event := range events {
cpuValue, err := event.RootFields.GetValue("aws.rds.metrics.CPUUtilization.avg")
if err == nil {
if value, ok := cpuValue.(float64); ok {
event.RootFields.Put("aws.rds.metrics.CPUUtilization.avg", value/100)
}
}
}

for identifier, output := range dbDetailsMap {
if _, ok := events[identifier]; !ok {
continue
}
events[identifier].RootFields.Put(metadataPrefix+"arn", &output.DBInstanceArn)
events[identifier].RootFields.Put(metadataPrefix+"status", &output.DBInstanceStatus)
events[identifier].RootFields.Put(metadataPrefix+"identifier", &output.DBInstanceIdentifier)
events[identifier].RootFields.Put(metadataPrefix+"db_cluster_identifier", &output.DBClusterIdentifier)
events[identifier].RootFields.Put(metadataPrefix+"class", &output.DBInstanceClass)
events[identifier].RootFields.Put(metadataPrefix+"engine_name", &output.Engine)
events[identifier].RootFields.Put("cloud.availability_zone", &output.AvailabilityZone)

if output.DBInstanceArn != nil {
events[identifier].RootFields.Put(metadataPrefix+"arn", *output.DBInstanceArn)
}

if output.DBInstanceStatus != nil {
events[identifier].RootFields.Put(metadataPrefix+"status", *output.DBInstanceStatus)
}

if output.DBInstanceIdentifier != nil {
events[identifier].RootFields.Put(metadataPrefix+"identifier", *output.DBInstanceIdentifier)
}

if output.DBClusterIdentifier != nil {
events[identifier].RootFields.Put(metadataPrefix+"db_cluster_identifier", *output.DBClusterIdentifier)
}

if output.DBInstanceClass != nil {
events[identifier].RootFields.Put(metadataPrefix+"class", *output.DBInstanceClass)
}

if output.Engine != nil {
events[identifier].RootFields.Put(metadataPrefix+"engine_name", *output.Engine)
}

if output.AvailabilityZone != nil {
events[identifier].RootFields.Put("cloud.availability_zone", *output.AvailabilityZone)
}
}
return events
}
Expand Down
51 changes: 24 additions & 27 deletions x-pack/metricbeat/module/aws/rds/_meta/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@
"namespace": "AWS/RDS"
},
"dimensions": {
"DBClusterIdentifier": "database-1",
"Role": "WRITER"
"DatabaseClass": "db.r5.large"
},
"rds": {
"aurora_bin_log_replica_lag": 0,
"aurora_replica": {
"lag": {
"ms": 19.9485
},
"lag_max": {
"ms": 13.449000358581543
"ms": 21.318500518798828
},
"lag_min": {
"ms": 13.449000358581543
"ms": 21.318500518798828
}
},
"aurora_volume_left_total": {
Expand All @@ -27,54 +29,49 @@
},
"cpu": {
"total": {
"pct": 6.975116251937533
"pct": 0.06552109062928828
}
},
"database_connections": 0,
"deadlocks": 0,
"engine_uptime": {
"sec": 20413803
"sec": 33121208
},
"free_local_storage": {
"bytes": 25608523776
"bytes": 27275925504
},
"freeable_memory": {
"bytes": 4695093248
"bytes": 4604928000
},
"latency": {
"commit": 5.198533333333333,
"commit": 3.2349916666666667,
"ddl": 0,
"delete": 0,
"dml": 0.19726666666666667,
"insert": 0.19726666666666667,
"dml": 0.09888333333333334,
"insert": 0.09888333333333334,
"read": 0,
"select": 0.21317204301075268,
"select": 0.2432811228126595,
"update": 0,
"write": 0.0013534145331858408
"write": 0.0005787267919438727
},
"login_failures": 0,
"queries": 8.830095631601747,
"queries": 7.862475898034027,
"throughput": {
"commit": 0.49980840677740196,
"commit": 0.24950762724254,
"ddl": 0,
"delete": 0,
"dml": 0.49980840677740196,
"insert": 0.49980840677740196,
"network": 1.3998600139986002,
"network_receive": 0.6999300069993001,
"network_transmit": 0.6999300069993001,
"select": 3.098812122019892,
"dml": 0.24950762724254,
"insert": 0.24950762724254,
"network": 1.3985171580449323,
"network_receive": 0.6992585790224661,
"network_transmit": 0.6992585790224661,
"select": 2.9299395125804084,
"update": 0
},
"transactions": {
"active": 0,
"blocked": 0
}
},
"tags": {
"cluster": "database-1",
"created-by": "ks",
"dept": "eng"
}
},
"cloud": {
Expand All @@ -83,7 +80,7 @@
"name": "elastic-beats"
},
"provider": "aws",
"region": "us-east-1"
"region": "eu-west-1"
},
"event": {
"dataset": "aws.rds",
Expand Down

0 comments on commit b5665a4

Please sign in to comment.