Skip to content

Commit cfee760

Browse files
authored
Adding x-pack code for elasticsearch/index metricset (#8260)
* Updating test fixture * Extract indicesStruct for reuse within package * Only request specific stats * Add X-Pack switch * Adding explanatory comment * Fleshing it out some more * Remove empty TODO * Adding reference comment for fields + refactoring into helper funcs * Re-formatting * Extract stats API metrics into own const * Using errors.Wrap * Adding logger to elasticsearch metricset * Log errors * Sharing the type not the variable 🤦
1 parent 7b0fb04 commit cfee760

File tree

8 files changed

+1923
-1430
lines changed

8 files changed

+1923
-1430
lines changed

metricbeat/module/elasticsearch/cluster_stats/cluster_stats.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
)
2828

2929
func init() {
30-
mb.Registry.MustAddMetricSet("elasticsearch", "cluster_stats", New,
30+
mb.Registry.MustAddMetricSet(elasticsearch.ModuleName, "cluster_stats", New,
3131
mb.WithHostParser(elasticsearch.HostParser),
3232
mb.WithNamespace("elasticsearch.cluster.stats"),
3333
)

metricbeat/module/elasticsearch/cluster_stats/data_xpack.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ func eventMappingXPack(r mb.ReporterV2, m *MetricSet, content []byte) error {
169169
return err
170170
}
171171

172-
clusterState, err := elasticsearch.GetClusterState(m.HTTP, m.HTTP.GetURI())
172+
clusterStateMetrics := []string{"version", "master_node", "nodes", "routing_table"}
173+
clusterState, err := elasticsearch.GetClusterState(m.HTTP, m.HTTP.GetURI(), clusterStateMetrics)
173174
if err != nil {
174175
return err
175176
}

metricbeat/module/elasticsearch/elasticsearch.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"encoding/json"
2222
"fmt"
2323
"net/url"
24+
"strings"
2425
"sync"
2526
"time"
2627

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

36+
// ModuleName is the ame of this module
37+
const ModuleName = "elasticsearch"
38+
3539
// Info construct contains the data from the Elasticsearch / endpoint
3640
type Info struct {
3741
ClusterName string `json:"cluster_name"`
@@ -202,8 +206,13 @@ func GetLicense(http *helper.HTTP, resetURI string) (common.MapStr, error) {
202206
}
203207

204208
// GetClusterState returns cluster state information
205-
func GetClusterState(http *helper.HTTP, resetURI string) (common.MapStr, error) {
206-
content, err := fetchPath(http, resetURI, "_cluster/state/version,master_node,nodes,routing_table")
209+
func GetClusterState(http *helper.HTTP, resetURI string, metrics []string) (common.MapStr, error) {
210+
clusterStateURI := "_cluster/state"
211+
if metrics != nil && len(metrics) > 0 {
212+
clusterStateURI += "/" + strings.Join(metrics, ",")
213+
}
214+
215+
content, err := fetchPath(http, resetURI, clusterStateURI)
207216
if err != nil {
208217
return nil, err
209218
}

0 commit comments

Comments
 (0)