-
Notifications
You must be signed in to change notification settings - Fork 459
/
http.go
69 lines (56 loc) · 1.83 KB
/
http.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package allocation
import (
"fmt"
"net/url"
"github.com/prometheus/common/model"
)
type LinkJSON struct {
Link string `json:"_link"`
}
type collectorJSON struct {
Link string `json:"_link"`
Jobs []targetGroupJSON `json:"targets"`
}
type targetGroupJSON struct {
Targets []string `json:"targets"`
Labels model.LabelSet `json:"labels"`
}
func GetAllTargetsByJob(job string, cMap map[string][]TargetItem, allocator *Allocator) map[string]collectorJSON {
displayData := make(map[string]collectorJSON)
for _, j := range allocator.TargetItems {
if j.JobName == job {
var targetList []TargetItem
targetList = append(targetList, cMap[j.Collector.Name+j.JobName]...)
var targetGroupList []targetGroupJSON
for _, t := range targetList {
targetGroupList = append(targetGroupList, targetGroupJSON{
Targets: []string{t.TargetURL},
Labels: t.Label,
})
}
displayData[j.Collector.Name] = collectorJSON{Link: fmt.Sprintf("/jobs/%s/targets?collector_id=%s", url.QueryEscape(j.JobName), j.Collector.Name), Jobs: targetGroupList}
}
}
return displayData
}
func GetAllTargetsByCollectorAndJob(collector string, job string, cMap map[string][]TargetItem, allocator *Allocator) []targetGroupJSON {
var tgs []targetGroupJSON
group := make(map[string]string)
labelSet := make(map[string]model.LabelSet)
for _, col := range allocator.collectors {
if col.Name == collector {
for _, targetItemArr := range cMap {
for _, targetItem := range targetItemArr {
if targetItem.Collector.Name == collector && targetItem.JobName == job {
group[targetItem.Label.String()] = targetItem.TargetURL
labelSet[targetItem.TargetURL] = targetItem.Label
}
}
}
}
}
for _, v := range group {
tgs = append(tgs, targetGroupJSON{Targets: []string{v}, Labels: labelSet[v]})
}
return tgs
}