|
|
@ -498,40 +498,51 @@ type DroppedTarget struct {
|
|
|
|
|
|
|
|
|
|
|
|
// TargetDiscovery has all the active targets.
|
|
|
|
// TargetDiscovery has all the active targets.
|
|
|
|
type TargetDiscovery struct {
|
|
|
|
type TargetDiscovery struct {
|
|
|
|
ActiveTargets map[string][]*Target `json:"activeTargets"`
|
|
|
|
ActiveTargets []*Target `json:"activeTargets"`
|
|
|
|
DroppedTargets map[string][]*DroppedTarget `json:"droppedTargets"`
|
|
|
|
DroppedTargets []*DroppedTarget `json:"droppedTargets"`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (api *API) targets(r *http.Request) (interface{}, *apiError, func()) {
|
|
|
|
func (api *API) targets(r *http.Request) (interface{}, *apiError, func()) {
|
|
|
|
tActive := api.targetRetriever.TargetsActive()
|
|
|
|
flatten := func(targets map[string][]*scrape.Target) []*scrape.Target {
|
|
|
|
tDropped := api.targetRetriever.TargetsDropped()
|
|
|
|
var n int
|
|
|
|
res := &TargetDiscovery{ActiveTargets: make(map[string][]*Target, len(tActive)), DroppedTargets: make(map[string][]*DroppedTarget, len(tDropped))}
|
|
|
|
keys := make([]string, 0, len(targets))
|
|
|
|
|
|
|
|
for k := range targets {
|
|
|
|
for tset, targets := range tActive {
|
|
|
|
keys = append(keys, k)
|
|
|
|
for _, target := range targets {
|
|
|
|
n += len(targets[k])
|
|
|
|
lastErrStr := ""
|
|
|
|
}
|
|
|
|
lastErr := target.LastError()
|
|
|
|
sort.Strings(keys)
|
|
|
|
if lastErr != nil {
|
|
|
|
res := make([]*scrape.Target, 0, n)
|
|
|
|
lastErrStr = lastErr.Error()
|
|
|
|
for _, k := range keys {
|
|
|
|
}
|
|
|
|
res = append(res, targets[k]...)
|
|
|
|
|
|
|
|
|
|
|
|
res.ActiveTargets[tset] = append(res.ActiveTargets[tset], &Target{
|
|
|
|
|
|
|
|
DiscoveredLabels: target.DiscoveredLabels().Map(),
|
|
|
|
|
|
|
|
Labels: target.Labels().Map(),
|
|
|
|
|
|
|
|
ScrapeURL: target.URL().String(),
|
|
|
|
|
|
|
|
LastError: lastErrStr,
|
|
|
|
|
|
|
|
LastScrape: target.LastScrape(),
|
|
|
|
|
|
|
|
Health: target.Health(),
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for tset, tt := range tDropped {
|
|
|
|
tActive := flatten(api.targetRetriever.TargetsActive())
|
|
|
|
for _, t := range tt {
|
|
|
|
tDropped := flatten(api.targetRetriever.TargetsDropped())
|
|
|
|
res.DroppedTargets[tset] = append(res.DroppedTargets[tset], &DroppedTarget{
|
|
|
|
res := &TargetDiscovery{ActiveTargets: make([]*Target, 0, len(tActive)), DroppedTargets: make([]*DroppedTarget, 0, len(tDropped))}
|
|
|
|
DiscoveredLabels: t.DiscoveredLabels().Map(),
|
|
|
|
|
|
|
|
})
|
|
|
|
for _, target := range tActive {
|
|
|
|
|
|
|
|
lastErrStr := ""
|
|
|
|
|
|
|
|
lastErr := target.LastError()
|
|
|
|
|
|
|
|
if lastErr != nil {
|
|
|
|
|
|
|
|
lastErrStr = lastErr.Error()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
res.ActiveTargets = append(res.ActiveTargets, &Target{
|
|
|
|
|
|
|
|
DiscoveredLabels: target.DiscoveredLabels().Map(),
|
|
|
|
|
|
|
|
Labels: target.Labels().Map(),
|
|
|
|
|
|
|
|
ScrapeURL: target.URL().String(),
|
|
|
|
|
|
|
|
LastError: lastErrStr,
|
|
|
|
|
|
|
|
LastScrape: target.LastScrape(),
|
|
|
|
|
|
|
|
Health: target.Health(),
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, t := range tDropped {
|
|
|
|
|
|
|
|
res.DroppedTargets = append(res.DroppedTargets, &DroppedTarget{
|
|
|
|
|
|
|
|
DiscoveredLabels: t.DiscoveredLabels().Map(),
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res, nil, nil
|
|
|
|
return res, nil, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|