Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add index metrics #85

Merged
40 changes: 1 addition & 39 deletions collector/cluster_health.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package collector

import (
"encoding/json"
"fmt"
"net/http"
"net/url"

"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/prometheus/client_golang/prometheus"
)

Expand Down Expand Up @@ -220,49 +217,14 @@ func (c *ClusterHealth) Describe(ch chan<- *prometheus.Desc) {
ch <- c.jsonParseFailures.Desc()
}

func (c *ClusterHealth) fetchAndDecodeClusterHealth() (clusterHealthResponse, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method should remain in this file

var chr clusterHealthResponse

u := *c.url
u.Path = "/_cluster/health"
res, err := c.client.Get(u.String())
if err != nil {
return chr, fmt.Errorf("failed to get cluster health from %s://%s:%s/%s: %s",
u.Scheme, u.Hostname(), u.Port(), u.Path, err)
}
defer res.Body.Close()

if res.StatusCode != http.StatusOK {
return chr, fmt.Errorf("HTTP Request failed with code %d", res.StatusCode)
}

if err := json.NewDecoder(res.Body).Decode(&chr); err != nil {
c.jsonParseFailures.Inc()
return chr, err
}

return chr, nil
}

func (c *ClusterHealth) Collect(ch chan<- prometheus.Metric) {
func (c *ClusterHealth) Collect(ch chan<- prometheus.Metric, clusterHealthResponse clusterHealthResponse) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't work. Collect must fulfill the prometheus. Collector interface and thus the signature must be

Collect(ch chan<- prometheus.Metric)

c.totalScrapes.Inc()
defer func() {
ch <- c.up
ch <- c.totalScrapes
ch <- c.jsonParseFailures
}()

clusterHealthResponse, err := c.fetchAndDecodeClusterHealth()
if err != nil {
c.up.Set(0)
level.Warn(c.logger).Log(
"msg", "failed to fetch and decode cluster health",
"err", err,
)
return
}
c.up.Set(1)

for _, metric := range c.metrics {
ch <- prometheus.MustNewConstMetric(
metric.Desc,
Expand Down
55 changes: 0 additions & 55 deletions collector/cluster_health_test.go

This file was deleted.

Loading