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
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

func init() {
mb.Registry.MustAddMetricSet("elasticsearch", "cluster_stats", New,
mb.Registry.MustAddMetricSet(elasticsearch.ModuleName, "cluster_stats", New,
mb.WithHostParser(elasticsearch.HostParser),
mb.WithNamespace("elasticsearch.cluster.stats"),
)
Expand Down
3 changes: 2 additions & 1 deletion metricbeat/module/elasticsearch/cluster_stats/data_xpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ func eventMappingXPack(r mb.ReporterV2, m *MetricSet, content []byte) error {
return err
}

clusterState, err := elasticsearch.GetClusterState(m.HTTP, m.HTTP.GetURI())
clusterStateMetrics := []string{"version", "master_node", "nodes", "routing_table"}
clusterState, err := elasticsearch.GetClusterState(m.HTTP, m.HTTP.GetURI(), clusterStateMetrics)
if err != nil {
return err
}
Expand Down
13 changes: 11 additions & 2 deletions metricbeat/module/elasticsearch/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"encoding/json"
"fmt"
"net/url"
"strings"
"sync"
"time"

Expand All @@ -32,6 +33,9 @@ import (
// Global clusterIdCache. Assumption is that the same node id never can belong to a different cluster id
var clusterIDCache = map[string]string{}

// ModuleName is the ame of this module
const ModuleName = "elasticsearch"

// Info construct contains the data from the Elasticsearch / endpoint
type Info struct {
ClusterName string `json:"cluster_name"`
Expand Down Expand Up @@ -202,8 +206,13 @@ func GetLicense(http *helper.HTTP, resetURI string) (common.MapStr, error) {
}

// GetClusterState returns cluster state information
func GetClusterState(http *helper.HTTP, resetURI string) (common.MapStr, error) {
content, err := fetchPath(http, resetURI, "_cluster/state/version,master_node,nodes,routing_table")
func GetClusterState(http *helper.HTTP, resetURI string, metrics []string) (common.MapStr, error) {
clusterStateURI := "_cluster/state"
if metrics != nil && len(metrics) > 0 {
clusterStateURI += "/" + strings.Join(metrics, ",")
}

content, err := fetchPath(http, resetURI, clusterStateURI)
if err != nil {
return nil, err
}
Expand Down
Loading