Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
14 changes: 14 additions & 0 deletions collector/cluster_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"net/url"
"path"
"strconv"

"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
Expand All @@ -21,6 +22,7 @@ type ClusterSettings struct {

up prometheus.Gauge
shardAllocationEnabled prometheus.Gauge
maxShardsPerNode prometheus.Gauge
totalScrapes, jsonParseFailures prometheus.Counter
}

Expand All @@ -43,6 +45,10 @@ func NewClusterSettings(logger log.Logger, client *http.Client, url *url.URL) *C
Name: prometheus.BuildFQName(namespace, "clustersettings_stats", "shard_allocation_enabled"),
Help: "Current mode of cluster wide shard routing allocation settings.",
}),
maxShardsPerNode: prometheus.NewGauge(prometheus.GaugeOpts{
Name: prometheus.BuildFQName(namespace, "clustersettings_stats", "max_shards_per_node"),
Help: "Current maximum number of shards per node setting.",
}),
jsonParseFailures: prometheus.NewCounter(prometheus.CounterOpts{
Name: prometheus.BuildFQName(namespace, "clustersettings_stats", "json_parse_failures"),
Help: "Number of errors while parsing JSON.",
Expand All @@ -55,6 +61,7 @@ func (cs *ClusterSettings) Describe(ch chan<- *prometheus.Desc) {
ch <- cs.up.Desc()
ch <- cs.totalScrapes.Desc()
ch <- cs.shardAllocationEnabled.Desc()
ch <- cs.maxShardsPerNode.Desc()
ch <- cs.jsonParseFailures.Desc()
}

Expand Down Expand Up @@ -92,6 +99,7 @@ func (cs *ClusterSettings) fetchAndDecodeClusterSettingsStats() (ClusterSettings
u.Path = path.Join(u.Path, "/_cluster/settings")
q := u.Query()
q.Set("include_defaults", "true")
u.RawQuery = q.Encode()
u.RawPath = q.Encode()
var csfr ClusterSettingsFullResponse
var csr ClusterSettingsResponse
Expand Down Expand Up @@ -121,6 +129,7 @@ func (cs *ClusterSettings) Collect(ch chan<- prometheus.Metric) {
ch <- cs.totalScrapes
ch <- cs.jsonParseFailures
ch <- cs.shardAllocationEnabled
ch <- cs.maxShardsPerNode
}()

csr, err := cs.fetchAndDecodeClusterSettingsStats()
Expand All @@ -143,4 +152,9 @@ func (cs *ClusterSettings) Collect(ch chan<- prometheus.Metric) {
}

cs.shardAllocationEnabled.Set(float64(shardAllocationMap[csr.Cluster.Routing.Allocation.Enabled]))

maxShardsPerNode, err := strconv.ParseInt(csr.Cluster.MaxShardsPerNode, 10, 64)
if err == nil {
cs.maxShardsPerNode.Set(float64(maxShardsPerNode))
}
}
3 changes: 2 additions & 1 deletion collector/cluster_settings_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ type ClusterSettingsResponse struct {

// Cluster is a representation of a Elasticsearch Cluster Settings
type Cluster struct {
Routing Routing `json:"routing"`
Routing Routing `json:"routing"`
MaxShardsPerNode string `json:"max_shards_per_node"`
}

// Routing is a representation of a Elasticsearch Cluster shard routing configuration
Expand Down
Loading