-
Notifications
You must be signed in to change notification settings - Fork 793
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
zwopir
merged 12 commits into
prometheus-community:master
from
matsumana:feature/add-index-metrics
Aug 29, 2017
Merged
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
27e56d1
add index metrics
matsumana 0bf3dcc
re-format
matsumana e021ec2
moved all indices metric from `collector/nodes.go` to `collector/indi…
matsumana 9116075
gathered the metrics collect logic in metrics_collector
matsumana 5f4f656
remove unreachable code
matsumana 9bd010f
add test pattern
matsumana a3c322b
Make indices metrics optional
matsumana 7af4dc8
revert
matsumana 696489c
revert
matsumana 9c32cc1
Make index metrics optional
matsumana 9df62d3
correct the places that were pointed out
matsumana 6b509f3
fix test
matsumana File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
) | ||
|
||
|
@@ -220,49 +217,14 @@ func (c *ClusterHealth) Describe(ch chan<- *prometheus.Desc) { | |
ch <- c.jsonParseFailures.Desc() | ||
} | ||
|
||
func (c *ClusterHealth) fetchAndDecodeClusterHealth() (clusterHealthResponse, error) { | ||
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||
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, | ||
|
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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