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

Allow for force gathering ES cluster stats #4345

Merged
merged 2 commits into from
Nov 19, 2018
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
6 changes: 4 additions & 2 deletions etc/telegraf.conf
Original file line number Diff line number Diff line change
Expand Up @@ -1906,10 +1906,12 @@
# ## - cluster
# # cluster_health_level = "indices"
#
# ## Set cluster_stats to true when you want to also obtain cluster stats from the
# ## Master node.
# ## Set cluster_stats to true when you want to also obtain cluster stats.
# cluster_stats = false
#
# ## Only gather cluster_stats from the master node. To work this require local = true
# cluster_stats_only_from_master = true
#
# ## node_stats is a list of sub-stats that you want to have gathered. Valid options
# ## are "indices", "os", "process", "jvm", "thread_pool", "fs", "transport", "http",
# ## "breaker". Per default, all stats are gathered.
Expand Down
6 changes: 4 additions & 2 deletions plugins/inputs/elasticsearch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ or [cluster-stats](https://www.elastic.co/guide/en/elasticsearch/reference/curre
## - cluster
# cluster_health_level = "indices"

## Set cluster_stats to true when you want to also obtain cluster stats from the
## Master node.
## Set cluster_stats to true when you want to also obtain cluster stats.
cluster_stats = false

## Only gather cluster_stats from the master node. To work this require local = true
cluster_stats_only_from_master = true

## node_stats is a list of sub-stats that you want to have gathered. Valid options
## are "indices", "os", "process", "jvm", "thread_pool", "fs", "transport", "http",
## "breaker". Per default, all stats are gathered.
Expand Down
28 changes: 16 additions & 12 deletions plugins/inputs/elasticsearch/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,12 @@ const sampleConfig = `
## - cluster
# cluster_health_level = "indices"

## Set cluster_stats to true when you want to also obtain cluster stats from the
## Master node.
## Set cluster_stats to true when you want to also obtain cluster stats.
cluster_stats = false

## Only gather cluster_stats from the master node. To work this require local = true
cluster_stats_only_from_master = true

## node_stats is a list of sub-stats that you want to have gathered. Valid options
## are "indices", "os", "process", "jvm", "thread_pool", "fs", "transport", "http",
## "breaker". Per default, all stats are gathered.
Expand All @@ -124,13 +126,14 @@ const sampleConfig = `
// Elasticsearch is a plugin to read stats from one or many Elasticsearch
// servers.
type Elasticsearch struct {
Local bool
Servers []string
HttpTimeout internal.Duration
ClusterHealth bool
ClusterHealthLevel string
ClusterStats bool
NodeStats []string
Local bool
Servers []string
HttpTimeout internal.Duration
ClusterHealth bool
ClusterHealthLevel string
ClusterStats bool
ClusterStatsOnlyFromMaster bool
NodeStats []string
tls.ClientConfig

client *http.Client
Expand All @@ -141,8 +144,9 @@ type Elasticsearch struct {
// NewElasticsearch return a new instance of Elasticsearch
func NewElasticsearch() *Elasticsearch {
return &Elasticsearch{
HttpTimeout: internal.Duration{Duration: time.Second * 5},
ClusterHealthLevel: "indices",
HttpTimeout: internal.Duration{Duration: time.Second * 5},
ClusterStatsOnlyFromMaster: true,
ClusterHealthLevel: "indices",
}
}

Expand Down Expand Up @@ -216,7 +220,7 @@ func (e *Elasticsearch) Gather(acc telegraf.Accumulator) error {
}
}

if e.ClusterStats && e.isMaster {
if e.ClusterStats && (e.isMaster || !e.ClusterStatsOnlyFromMaster || !e.Local) {
if err := e.gatherClusterStats(s+"/_cluster/stats", acc); err != nil {
acc.AddError(fmt.Errorf(mask.ReplaceAllString(err.Error(), "http(s)://XXX:XXX@")))
return
Expand Down