Skip to content

Commit

Permalink
Merge pull request #12 from perhamm/master
Browse files Browse the repository at this point in the history
446626 add elasticsearch_clustersettings_stats_max_shards_per_node
  • Loading branch information
uzhinskiy authored Sep 4, 2024
2 parents 55618a6 + 23d343c commit 0ef4d2d
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 13 deletions.
3 changes: 1 addition & 2 deletions collector/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ func (c *Client) GetSettings(s []string) (map[string]interface{}, error) {
func (c *Client) GetClusterSettings() (map[string]interface{}, error) {
c.logger.Debug("Getting cluster settings")
resp, err := c.es.Cluster.GetSettings(
c.es.Cluster.GetSettings.WithIncludeDefaults(true),
c.es.Cluster.GetSettings.WithFilterPath("*.cluster.routing.allocation.exclude"),
c.es.Cluster.GetSettings.WithIncludeDefaults(false),
)
if err != nil {
return nil, fmt.Errorf("error getting response: %s", err)
Expand Down
60 changes: 49 additions & 11 deletions collector/cluster-settings.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package collector

import (
"strconv"

"github.com/prometheus/client_golang/prometheus"
"github.com/sirupsen/logrus"
)
Expand All @@ -9,7 +11,8 @@ type ClusterSettingsCollector struct {
client *Client
logger *logrus.Logger

excludeExists *prometheus.Desc
excludeExists *prometheus.Desc
maxShardsPerNode *prometheus.Desc
}

func NewClusterSettingsCollector(logger *logrus.Logger, client *Client, labels, labels_group []string, datepattern string,
Expand All @@ -22,11 +25,17 @@ func NewClusterSettingsCollector(logger *logrus.Logger, client *Client, labels,
prometheus.BuildFQName(namespace, "exclude", "exists"),
"Exclude exists in cluster settings", labels, constLabels,
),
maxShardsPerNode: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "clustersettings_stats", "max_shards_per_node"),
"Current maximum number of shards per node setting.",
nil, nil,
),
}
}

func (c *ClusterSettingsCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- c.excludeExists
ch <- c.maxShardsPerNode
}

func (c *ClusterSettingsCollector) Collect(ch chan<- prometheus.Metric) {
Expand All @@ -35,19 +44,48 @@ func (c *ClusterSettingsCollector) Collect(ch chan<- prometheus.Metric) {
c.logger.Fatalf("error getting indices settings: %v", err)
}

if len(settings) == 0 {
path := "persistent.cluster.routing.allocation.exclude"
if _, ok := walk(settings, path); ok {
ch <- prometheus.MustNewConstMetric(c.excludeExists, prometheus.CounterValue, 1, "persistent")
} else {
ch <- prometheus.MustNewConstMetric(c.excludeExists, prometheus.CounterValue, 0, "persistent")
ch <- prometheus.MustNewConstMetric(c.excludeExists, prometheus.CounterValue, 0, "transient")
}

path = "transient.cluster.routing.allocation.exclude"
if _, ok := walk(settings, path); ok {
ch <- prometheus.MustNewConstMetric(c.excludeExists, prometheus.CounterValue, 1, "transient")
} else {
if settings["persistent"] == nil {
ch <- prometheus.MustNewConstMetric(c.excludeExists, prometheus.CounterValue, 0, "persistent")
} else {
ch <- prometheus.MustNewConstMetric(c.excludeExists, prometheus.CounterValue, 1, "persistent")
}
if settings["transient"] == nil {
ch <- prometheus.MustNewConstMetric(c.excludeExists, prometheus.CounterValue, 0, "transient")
ch <- prometheus.MustNewConstMetric(c.excludeExists, prometheus.CounterValue, 0, "transient")
}

path = "persistent.cluster.max_shards_per_node"
if count, ok := walk(settings, path); ok {
if v, ok := count.(string); ok {
maxShardsPerNode, err := strconv.ParseInt(v, 10, 64)
if err == nil {
path_transient := "transient.cluster.max_shards_per_node"
if count_transient, ok := walk(settings, path_transient); ok {
if v, ok := count_transient.(string); ok {
maxShardsPerNodeTransient, err := strconv.ParseInt(v, 10, 64)
if err == nil {
ch <- prometheus.MustNewConstMetric(c.maxShardsPerNode, prometheus.GaugeValue, float64(maxShardsPerNodeTransient))
} else {
ch <- prometheus.MustNewConstMetric(c.maxShardsPerNode, prometheus.GaugeValue, float64(maxShardsPerNode))
}
} else {
ch <- prometheus.MustNewConstMetric(c.maxShardsPerNode, prometheus.GaugeValue, float64(maxShardsPerNode))
}
} else {
ch <- prometheus.MustNewConstMetric(c.maxShardsPerNode, prometheus.GaugeValue, float64(maxShardsPerNode))
}
} else {
c.logger.Errorf("got invalid %q value: %#v", path, count)
}
} else {
ch <- prometheus.MustNewConstMetric(c.excludeExists, prometheus.CounterValue, 1, "transient")
c.logger.Errorf("got invalid %q value: %#v", path, count)
}
} else {
ch <- prometheus.MustNewConstMetric(c.maxShardsPerNode, prometheus.GaugeValue, 1000.0)
}

}
17 changes: 17 additions & 0 deletions collector/indices.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type IndicesCollector struct {
indexTotalSize *prometheus.Desc
indexGroupSize *prometheus.Desc
docsCount *prometheus.Desc
shardsDocs *prometheus.Desc
}

func NewIndicesCollector(logger *logrus.Logger, client *Client, labels, labels_group []string, datepattern string,
Expand All @@ -44,6 +45,10 @@ func NewIndicesCollector(logger *logrus.Logger, client *Client, labels, labels_g
prometheus.BuildFQName(namespace, "indices_group_store", "size_bytes"),
"Total size of each index group to date", labels_group, constLabels,
),
shardsDocs: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "indices", "shards_docs"),
"Count of documents on this shard", labels, constLabels,
),
}
}

Expand All @@ -52,6 +57,7 @@ func (c *IndicesCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- c.indexTotalSize
ch <- c.docsCount
ch <- c.indexGroupSize
ch <- c.shardsDocs
}

func (c *IndicesCollector) Collect(ch chan<- prometheus.Metric) {
Expand Down Expand Up @@ -116,6 +122,17 @@ func (c *IndicesCollector) Collect(ch chan<- prometheus.Metric) {
c.logger.Errorf("%q was not found for: %s", path, index)
}

path = "primaries.docs.count"
if count, ok := walk(data, path); ok {
if v, ok := count.(float64); ok {
ch <- prometheus.MustNewConstMetric(c.shardsDocs, prometheus.GaugeValue, v, index, indexGrouplabel)
} else {
c.logger.Errorf("got invalid %q value for: %s value: %#v", path, index, count)
}
} else {
c.logger.Errorf("%q was not found for: %s", path, index)
}

}

for indexGroup, v := range indexGroupSize {
Expand Down

0 comments on commit 0ef4d2d

Please sign in to comment.