Skip to content

Commit

Permalink
Добавляем метрику oneday_elasticsearch_exclude_exists для transient
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris committed Feb 26, 2024
1 parent 78e32ef commit cfc02b8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion collector/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ 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("persistent.cluster.routing.allocation.exclude"),
c.es.Cluster.GetSettings.WithFilterPath("*.cluster.routing.allocation.exclude"),
)
if err != nil {
return nil, fmt.Errorf("error getting response: %s", err)
Expand Down
20 changes: 19 additions & 1 deletion collector/cluster-settings.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package collector

import (
"fmt"

"github.com/prometheus/client_golang/prometheus"
"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -35,9 +37,25 @@ func (c *ClusterSettingsCollector) Collect(ch chan<- prometheus.Metric) {
c.logger.Fatalf("error getting indices settings: %v", err)
}

fmt.Printf("%v\n", settings["persistent"])

if len(settings) == 0 {
ch <- prometheus.MustNewConstMetric(c.excludeExists, prometheus.CounterValue, 0, "persistent")
ch <- prometheus.MustNewConstMetric(c.excludeExists, prometheus.CounterValue, 0, "transient")
} else {
ch <- prometheus.MustNewConstMetric(c.excludeExists, prometheus.CounterValue, 1, "persistent")
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")
} else {
ch <- prometheus.MustNewConstMetric(c.excludeExists, prometheus.CounterValue, 1, "transient")
}
/* for k := range settings {
ch <- prometheus.MustNewConstMetric(c.excludeExists, prometheus.CounterValue, 1, k)
}
*/
}
}

0 comments on commit cfc02b8

Please sign in to comment.