diff --git a/metricbeat/module/docker/memory/memory.go b/metricbeat/module/docker/memory/memory.go index a4f561389725..140383de833e 100644 --- a/metricbeat/module/docker/memory/memory.go +++ b/metricbeat/module/docker/memory/memory.go @@ -22,6 +22,8 @@ package memory import ( "fmt" + "github.com/elastic/elastic-agent-libs/logp" + "github.com/docker/docker/client" "github.com/elastic/beats/v7/metricbeat/mb" @@ -41,16 +43,18 @@ type MetricSet struct { memoryService *MemoryService dockerClient *client.Client dedot bool + logger *logp.Logger } // New creates a new instance of the docker memory MetricSet. func New(base mb.BaseMetricSet) (mb.MetricSet, error) { + logger := logp.NewLogger("docker.memory") config := docker.DefaultConfig() if err := base.Module().UnpackConfig(&config); err != nil { return nil, err } - client, err := docker.NewDockerClient(base.HostData().URI, config) + dockerClient, err := docker.NewDockerClient(base.HostData().URI, config) if err != nil { return nil, err } @@ -58,8 +62,9 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) { return &MetricSet{ BaseMetricSet: base, memoryService: &MemoryService{}, - dockerClient: client, + dockerClient: dockerClient, dedot: config.DeDot, + logger: logger, }, nil } @@ -72,7 +77,10 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) error { memoryStats := m.memoryService.getMemoryStatsList(stats, m.dedot) if len(memoryStats) == 0 { - return fmt.Errorf("No memory stats data available") + // No memory stats available, probably + // because no containers are running. + m.logger.Debug("No memory stats data available") + return nil } eventsMapping(r, memoryStats)