Skip to content

Commit

Permalink
Adding x-pack code for elasticsearch/index metricset (#8260)
Browse files Browse the repository at this point in the history
* 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 🤦
  • Loading branch information
ycombinator authored Sep 18, 2018
1 parent 7b0fb04 commit cfee760
Show file tree
Hide file tree
Showing 8 changed files with 1,923 additions and 1,430 deletions.
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

0 comments on commit cfee760

Please sign in to comment.