Skip to content
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
22 changes: 9 additions & 13 deletions metricbeat/module/elasticsearch/metricset.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,21 @@ import (
"encoding/json"
"errors"
"fmt"
"os"

"github.com/elastic/beats/v7/libbeat/common/productorigin"
"github.com/elastic/beats/v7/metricbeat/helper"
"github.com/elastic/beats/v7/metricbeat/mb"
"github.com/elastic/beats/v7/metricbeat/mb/parse"
)

const (
defaultScheme = "http"
pathConfigKey = "path"
)

var (
// HostParser parses host urls for RabbitMQ management plugin
HostParser = parse.URLHostParserBuilder{
DefaultScheme: defaultScheme,
PathConfigKey: pathConfigKey,
DefaultScheme: "http",
DefaultUsername: os.Getenv("ELASTICSEARCH_READ_USERNAME"),
DefaultPassword: os.Getenv("ELASTICSEARCH_READ_PASSWORD"),
PathConfigKey: "path",
}.Build()
)

Expand Down Expand Up @@ -98,7 +96,7 @@ func NewMetricSet(base mb.BaseMetricSet, servicePath string) (*MetricSet, error)
}{
Scope: ScopeNode,
XPackEnabled: false,
ApiKey: "",
ApiKey: os.Getenv("ELASTICSEARCH_READ_API_KEY"),
}
if err := base.Module().UnpackConfig(&config); err != nil {
return nil, err
Expand Down Expand Up @@ -135,7 +133,7 @@ func (m *MetricSet) GetServiceURI() string {
// SetServiceURI updates the URI of the Elasticsearch service being monitored by this metricset
func (m *MetricSet) SetServiceURI(servicePath string) {
m.servicePath = servicePath
m.HTTP.SetURI(m.GetServiceURI())
m.SetURI(m.GetServiceURI())
}

func (m *MetricSet) ShouldSkipFetch() (bool, error) {
Expand All @@ -159,10 +157,9 @@ func (m *MetricSet) ShouldSkipFetch() (bool, error) {

// GetMasterNodeID returns the ID of the Elasticsearch cluster's master node
func (m *MetricSet) GetMasterNodeID() (string, error) {
http := m.HTTP
resetURI := m.GetServiceURI()

content, err := fetchPath(http, resetURI, "_nodes/_master", "filter_path=nodes.*.name")
content, err := fetchPath(m.HTTP, resetURI, "_nodes/_master", "filter_path=nodes.*.name")
if err != nil {
return "", err
}
Expand All @@ -184,10 +181,9 @@ func (m *MetricSet) GetMasterNodeID() (string, error) {

// IsMLockAllEnabled returns if the given Elasticsearch node has mlockall enabled
func (m *MetricSet) IsMLockAllEnabled(nodeID string) (bool, error) {
http := m.HTTP
resetURI := m.GetServiceURI()

content, err := fetchPath(http, resetURI, "_nodes/"+nodeID, "filter_path=nodes.*.process.mlockall")
content, err := fetchPath(m.HTTP, resetURI, "_nodes/"+nodeID, "filter_path=nodes.*.process.mlockall")
if err != nil {
return false, err
}
Expand Down