Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only fetch shard metrics from master node #7635

Merged
merged 2 commits into from
Jul 19, 2018
Merged
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
16 changes: 15 additions & 1 deletion metricbeat/module/elasticsearch/shard/shard.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
package shard

import (
"fmt"

"github.com/elastic/beats/libbeat/common/cfgwarn"
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/metricbeat/mb"
"github.com/elastic/beats/metricbeat/module/elasticsearch"
)
Expand All @@ -32,7 +35,6 @@ func init() {
}

const (
// Get the stats from the local node
statePath = "/_cluster/state/version,master_node,routing_table"
)

Expand All @@ -55,6 +57,18 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) {

// Fetch methods implements the data gathering and data conversion to the right format
func (m *MetricSet) Fetch(r mb.ReporterV2) {
isMaster, err := elasticsearch.IsMaster(m.HTTP, m.HostData().SanitizedURI+statePath)
if err != nil {
r.Error(fmt.Errorf("Error fetch master info: %s", err))
return
}

// Not master, no event sent
if !isMaster {
logp.Debug("elasticsearch", "Trying to fetch shard stats from a non master node.")
return
}

content, err := m.HTTP.FetchContent()
if err != nil {
r.Error(err)
Expand Down