From d5344b09e4d05d8bf5dde7c4a3b2112c47ece179 Mon Sep 17 00:00:00 2001 From: lucian-ioan <lucian.deaconescu@elastic.co> Date: Fri, 24 Nov 2023 09:41:13 +0200 Subject: [PATCH] add logic for processing limits --- .../module/awsfargate/task_stats/memory.go | 2 +- .../module/awsfargate/task_stats/task_stats.go | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/x-pack/metricbeat/module/awsfargate/task_stats/memory.go b/x-pack/metricbeat/module/awsfargate/task_stats/memory.go index 00ebae2fd2e5..29a8a39c21bc 100644 --- a/x-pack/metricbeat/module/awsfargate/task_stats/memory.go +++ b/x-pack/metricbeat/module/awsfargate/task_stats/memory.go @@ -13,7 +13,7 @@ type memoryStats struct { TotalRss uint64 TotalRssP float64 Usage uint64 - UsageP float64 + // UsageP float64 //Raw stats from the cgroup subsystem Stats map[string]uint64 //Windows-only memory stats diff --git a/x-pack/metricbeat/module/awsfargate/task_stats/task_stats.go b/x-pack/metricbeat/module/awsfargate/task_stats/task_stats.go index 21eab0f0bc74..c22512b59b6c 100644 --- a/x-pack/metricbeat/module/awsfargate/task_stats/task_stats.go +++ b/x-pack/metricbeat/module/awsfargate/task_stats/task_stats.go @@ -80,6 +80,13 @@ type TaskMetadata struct { DesiredStatus string `json:"DesiredStatus"` KnownStatus string `json:"KnownStatus"` Containers []*container `json:"Containers"` + Limits Limits `json:"Limits"` +} + +// Limits is a struct that represents the memory and CPU limits from ${ECS_CONTAINER_METADATA_URI_V4}/task +type Limits struct { + CPU int64 `json:"CPU"` + Memory int64 `json:"Memory"` } // New creates a new instance of the MetricSet. New is responsible for unpacking @@ -182,7 +189,7 @@ func getTask(taskResp *http.Response) (TaskMetadata, error) { return taskOutput, nil } -func getStatsList(taskStatsOutput map[string]types.StatsJSON, taskOutput TaskMetadata) []Stats { +func getStatsList(taskStatsOutput map[string]types.StatsJSON, taskOutput TaskMetadata, memoryLimit int64) []Stats { containersInfo := map[string]container{} taskInfo := TaskInfo{ @@ -214,6 +221,9 @@ func getStatsList(taskStatsOutput map[string]types.StatsJSON, taskOutput TaskMet memoryStats: getMemoryStats(taskStats), networkStats: getNetworkStats(taskStats), blkioStats: getBlkioStats(taskStats.BlkioStats), + Limits: Limits{ + Memory: memoryLimit, + }, } formattedStats = append(formattedStats, statsPerContainer)