Skip to content

Commit

Permalink
[metricbeat] check for a valid limit before we process a memory event (
Browse files Browse the repository at this point in the history
…elastic#11676)

* check for a valid limit before we process a memory event

(cherry picked from commit 97aec9b)
  • Loading branch information
fearful-symmetry committed Apr 15, 2019
1 parent 273056b commit 2391b89
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ https://github.com/elastic/beats/compare/v7.0.0...7.0[Check the HEAD diff]

*Metricbeat*

- Add _bucket to histogram metrics in Prometheus Collector {pull}11578[11578]
- Prevent the docker/memory metricset from processing invalid events before container start {pull}11676[11676]

*Packetbeat*

*Winlogbeat*
Expand Down
14 changes: 11 additions & 3 deletions metricbeat/module/docker/memory/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/elastic/beats/metricbeat/module/docker"
)

// MemoryData contains parsed container memory info
type MemoryData struct {
Time common.Time
Container *docker.Container
Expand All @@ -34,12 +35,19 @@ type MemoryData struct {
UsageP float64
}

// MemoryService is placeholder for the the memory stat parsers
type MemoryService struct{}

func (s *MemoryService) getMemoryStatsList(rawStats []docker.Stat, dedot bool) []MemoryData {
func (s *MemoryService) getMemoryStatsList(containers []docker.Stat, dedot bool) []MemoryData {
formattedStats := []MemoryData{}
for _, myRawStats := range rawStats {
formattedStats = append(formattedStats, s.getMemoryStats(myRawStats, dedot))
for _, containerStats := range containers {
//There appears to be a race where a container will report with a stat object before it actually starts
//during this time, there doesn't appear to be any meaningful data,
// and Limit will never be 0 unless the container is not running & there's no cgroup data
if containerStats.Stats.MemoryStats.Limit == 0 {
continue
}
formattedStats = append(formattedStats, s.getMemoryStats(containerStats, dedot))
}

return formattedStats
Expand Down
1 change: 1 addition & 0 deletions metricbeat/module/docker/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func init() {
)
}

// MetricSet type defines all fields of the MetricSet
type MetricSet struct {
mb.BaseMetricSet
memoryService *MemoryService
Expand Down

0 comments on commit 2391b89

Please sign in to comment.