Sort targets by instance within a job

Fixes https://github.com/prometheus/prometheus/issues/2536
This commit is contained in:
Julius Volz 2017-03-30 22:45:18 +02:00
parent 336c7870ea
commit 947c83be3b
2 changed files with 7 additions and 1 deletions

View File

@ -131,7 +131,7 @@ func (tm *TargetManager) reload() {
}
}
// Targets returns the targets currently being scraped bucketed by their job name.
// Targets returns the targets currently being scraped.
func (tm *TargetManager) Targets() []*Target {
tm.mtx.RLock()
defer tm.mtx.RUnlock()

View File

@ -379,6 +379,12 @@ func (h *Handler) targets(w http.ResponseWriter, r *http.Request) {
tps[job] = append(tps[job], t)
}
for _, targets := range tps {
sort.Slice(targets, func(i, j int) bool {
return targets[i].Labels()[model.InstanceLabel] < targets[j].Labels()[model.InstanceLabel]
})
}
h.executeTemplate(w, "targets.html", struct {
TargetPools map[string][]*retrieval.Target
}{