Skip to content
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
18 changes: 10 additions & 8 deletions metricbeat/module/munin/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ package node
import (
"time"

"github.com/pkg/errors"

"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/metricbeat/mb"
"github.com/elastic/beats/metricbeat/module/munin"
)
Expand Down Expand Up @@ -66,27 +67,28 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
}

// Fetch method implements the data gathering
func (m *MetricSet) Fetch(r mb.ReporterV2) {
func (m *MetricSet) Fetch(r mb.ReporterV2) error {
node, err := munin.Connect(m.Host(), m.timeout)
if err != nil {
r.Error(err)
return
return errors.Wrap(err, "error in Connect")
}
defer node.Close()

plugins := m.plugins
if len(plugins) == 0 {
plugins, err = node.List()
if err != nil {
r.Error(err)
return
return errors.Wrap(err, "error getting plugin list")
}
}

for _, plugin := range plugins {
metrics, err := node.Fetch(plugin, m.sanitize)
if err != nil {
msg := errors.Wrap(err, "error fetching metrics")
r.Error(err)
m.Logger().Error(msg)
continue
}

// Even if there was some error, keep sending succesfully collected metrics if any
Expand All @@ -105,8 +107,8 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) {
},
}
if !r.Event(event) {
logp.Debug("munin", "Failed to report event, interrupting Fetch")
return
return errors.New("metricset has closed")
}
}
return nil
}
8 changes: 4 additions & 4 deletions metricbeat/module/munin/node/node_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import (
func TestFetch(t *testing.T) {
compose.EnsureUp(t, "munin")

f := mbtest.NewReportingMetricSetV2(t, getConfig())
events, errs := mbtest.ReportingFetchV2(f)
f := mbtest.NewReportingMetricSetV2Error(t, getConfig())
events, errs := mbtest.ReportingFetchV2Error(f)

assert.Empty(t, errs)
if !assert.NotEmpty(t, events) {
Expand All @@ -48,8 +48,8 @@ func TestData(t *testing.T) {
compose.EnsureUp(t, "munin")

config := getConfig()
f := mbtest.NewReportingMetricSetV2(t, config)
err := mbtest.WriteEventsReporterV2(f, t, ".")
f := mbtest.NewReportingMetricSetV2Error(t, config)
err := mbtest.WriteEventsReporterV2Error(f, t, ".")
if err != nil {
t.Fatal("write", err)
}
Expand Down