-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
114 lines (93 loc) · 3.19 KB
/
Copy pathmain.go
File metadata and controls
114 lines (93 loc) · 3.19 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package main
import (
"bufio"
"context"
"fmt"
"net/http"
"os"
"strings"
"time"
"github.com/Shopify/sarama"
log "github.com/sirupsen/logrus"
"github.com/BaritoLog/barito-blackbox-exporter/appgroup"
"github.com/BaritoLog/barito-blackbox-exporter/config"
"github.com/BaritoLog/barito-blackbox-exporter/exporter"
"github.com/BaritoLog/barito-blackbox-exporter/o11y"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
func main() {
log.SetLevel(log.DebugLevel)
cfg := config.NewConfig()
mR := o11y.NewMetricRecorder()
mapAppGroups := map[string]bool{}
appGroups, err := appgroup.GetListAppGroups(*cfg)
if err != nil {
panic(fmt.Sprintf("Failed to get list app group from BaritoMarket: %v", err))
}
for _, aG := range appGroups {
go createPushAgent(aG, cfg, mR).Run()
go createESProbeAgent(aG, cfg, mR).Run()
go createKibanaProbeAgent(aG, cfg, mR).Run()
mapAppGroups[aG.GetClusterName()] = true
}
// todo: disable for now, because after deleting the topic, consumer must be restarted
//go deleteProberKafkaTopic(appGroups, cfg)
http.Handle("/metrics", promhttp.HandlerFor(
mR.GetRegistry(),
promhttp.HandlerOpts{EnableOpenMetrics: true},
))
log.Fatal(http.ListenAndServe(":8000", nil))
}
func createPushAgent(appGroup appgroup.AppGroup, cfg *config.Config, mR o11y.MetricRecorder) *exporter.PushAgent {
return exporter.NewPushAgent(appGroup.GetClusterName(), appGroup.GetSecret(), context.Background(), cfg, mR)
}
func createESProbeAgent(appGroup appgroup.AppGroup, cfg *config.Config, mR o11y.MetricRecorder) *exporter.ESProbeAgent {
return exporter.NewESProbeAgent(appGroup, context.Background(), cfg, mR)
}
func createKibanaProbeAgent(appGroup appgroup.AppGroup, cfg *config.Config, mR o11y.MetricRecorder) *exporter.KibanaProbeAgent {
return exporter.NewKibanaProbeAgent(appGroup, context.Background(), cfg, mR)
}
func getClusterAndSecret() []map[string]string {
result := []map[string]string{}
file, err := os.Open("./secrets_sample")
if err != nil {
log.Fatal(err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
s := strings.Split(scanner.Text(), " ")
result = append(result, map[string]string{"code": s[0], "secret": s[1]})
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
log.Infof("Found %d appgroup", len(result))
return result
}
func deleteProberKafkaTopic(appGroups []appgroup.AppGroup, cfg *config.Config) {
for {
for _, aG := range appGroups {
aG.RefreshMetadata()
listKafka, err := aG.GetListKafka()
if err != nil {
log.Errorf("Failed to GetListKafka on app_group: %q, err: %v", aG.GetClusterName(), err)
continue
}
saramaCfg := sarama.NewConfig()
saramaCfg.Version = sarama.V2_5_0_0
clusterAdmin, err := sarama.NewClusterAdmin(listKafka, saramaCfg)
if err != nil {
log.Errorf("Failed to create sarama client, app_group: %q, err: %v", aG.GetClusterName(), err)
continue
}
topicName := fmt.Sprintf("%s-%s_pb", cfg.ProduceAppPrefix, aG.GetClusterName())
err = clusterAdmin.DeleteTopic(topicName)
if err != nil {
log.Errorf("Failed to delete topic, app_group: %q, err: %v", aG.GetClusterName(), err)
continue
}
}
time.Sleep(cfg.DeleteTopicInterval)
}
}