Skip to content

Commit

Permalink
Add ro metrics (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
perhamm authored Feb 9, 2024
1 parent aa0f428 commit 78e32ef
Showing 1 changed file with 69 additions and 14 deletions.
83 changes: 69 additions & 14 deletions collector/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ type SettingsCollector struct {

datePattern string

fieldsLimit *prometheus.Desc
fieldsGroupLimit *prometheus.Desc
fieldsLimit *prometheus.Desc
fieldsGroupLimit *prometheus.Desc
readOnlyAllowDelete *prometheus.Desc
readOnly *prometheus.Desc
}

func NewSettingsCollector(logger *logrus.Logger, client *Client, labels, labels_group []string, datepattern string,
Expand All @@ -32,12 +34,22 @@ func NewSettingsCollector(logger *logrus.Logger, client *Client, labels, labels_
prometheus.BuildFQName(namespace, "fields_group_limit", "total"),
"Total limit of fields of each index group to date", labels_group, constLabels,
),
readOnlyAllowDelete: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "read_only_allow_delete", "total"),
"State of the read_only_allow_delete field, which means that the index is in readonly mode", labels, constLabels,
),
readOnly: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "read_only", "total"),
"State of the read_only field, which means that the index is in readonly mode", labels, constLabels,
),
}
}

func (c *SettingsCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- c.fieldsLimit
ch <- c.fieldsGroupLimit
ch <- c.readOnlyAllowDelete
ch <- c.readOnly
}

func (c *SettingsCollector) Collect(ch chan<- prometheus.Metric) {
Expand All @@ -56,29 +68,72 @@ func (c *SettingsCollector) Collect(ch chan<- prometheus.Metric) {

data, ok := v.(map[string]interface{})
if !ok {
c.logger.Error("got invalid index setttings for: %s", index)
c.logger.Errorf("got invalid index setttings for: %s", index)
continue
}

path := "index.mapping.total_fields.limit"
limit, ok := walk(data, "settings."+path)
skipFlag := false

path_limit := "index.mapping.total_fields.limit"
limit, ok := walk(data, "settings."+path_limit)
if !ok {
limit, ok = walk(data, "defaults."+path)
limit, ok = walk(data, "defaults."+path_limit)
if !ok {
c.logger.Errorf("%q was not found for: %s", path, index)
continue
c.logger.Errorf("%q was not found for: %s", path_limit, index)
skipFlag = true
}
}
if !skipFlag {
if s, ok := limit.(string); ok {
if v, err := strconv.ParseFloat(s, 64); err == nil {
ch <- prometheus.MustNewConstMetric(c.fieldsLimit, prometheus.GaugeValue, v, index, indexGrouplabel)
fieldsGroupLimit[indexGrouplabel] += v
} else {
c.logger.Errorf("error parsing %q value for: %s: %v ", path_limit, index, err)
}
} else {
c.logger.Errorf("got invalid %q value for: %s value: %#v", path_limit, index, limit)
}
}

if s, ok := limit.(string); ok {
if v, err := strconv.ParseFloat(s, 64); err == nil {
ch <- prometheus.MustNewConstMetric(c.fieldsLimit, prometheus.GaugeValue, v, index, indexGrouplabel)
fieldsGroupLimit[indexGrouplabel] += v
path_block := "index.blocks.read_only_allow_delete"
block, ok := walk(data, "settings."+path_block)
if !ok {
ch <- prometheus.MustNewConstMetric(c.readOnlyAllowDelete, prometheus.GaugeValue, 0, index, indexGrouplabel)
} else {
if s, ok := block.(string); ok {
if v, err := strconv.ParseBool(s); err == nil {
if v {
ch <- prometheus.MustNewConstMetric(c.readOnlyAllowDelete, prometheus.GaugeValue, 1, index, indexGrouplabel)
} else {
ch <- prometheus.MustNewConstMetric(c.readOnlyAllowDelete, prometheus.GaugeValue, 0, index, indexGrouplabel)
}
} else {
c.logger.Errorf("error parsing %q value for: %s: %v ", path_block, index, err)
}
} else {
c.logger.Errorf("error parsing %q value for: %s: %v ", path, index, err)
c.logger.Errorf("got invalid %q value for: %s value: %#v", path_block, index, limit)
}
}

path_roblock := "index.blocks.read_only"
roblock, ok := walk(data, "settings."+path_roblock)
if !ok {
ch <- prometheus.MustNewConstMetric(c.readOnly, prometheus.GaugeValue, 0, index, indexGrouplabel)
} else {
c.logger.Errorf("got invalid %q value for: %s value: %#v", path, index, limit)
if s, ok := roblock.(string); ok {
if v, err := strconv.ParseBool(s); err == nil {
if v {
ch <- prometheus.MustNewConstMetric(c.readOnly, prometheus.GaugeValue, 1, index, indexGrouplabel)
} else {
ch <- prometheus.MustNewConstMetric(c.readOnly, prometheus.GaugeValue, 0, index, indexGrouplabel)
}
} else {
c.logger.Errorf("error parsing %q value for: %s: %v ", path_roblock, index, err)
}
} else {
c.logger.Errorf("got invalid %q value for: %s value: %#v", path_roblock, index, limit)
}
}
}

Expand Down

0 comments on commit 78e32ef

Please sign in to comment.