Skip to content

Commit

Permalink
cherry pick #2835 to release-1.1 (#2838)
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>

Co-authored-by: weekface <weekface@gmail.com>
  • Loading branch information
ti-srebot and weekface committed Jul 1, 2020
1 parent a9e4f17 commit 90e4b56
Show file tree
Hide file tree
Showing 2 changed files with 345 additions and 12 deletions.
66 changes: 55 additions & 11 deletions pkg/monitor/monitor/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,20 @@ const (
)

var (
truePattern config.Regexp
allMatchPattern config.Regexp
portPattern config.Regexp
tikvPattern config.Regexp
pdPattern config.Regexp
tidbPattern config.Regexp
addressPattern config.Regexp
tiflashPattern config.Regexp
pumpPattern config.Regexp
drainerPattern config.Regexp
dashBoardConfig = `{
truePattern config.Regexp
allMatchPattern config.Regexp
portPattern config.Regexp
tikvPattern config.Regexp
pdPattern config.Regexp
tidbPattern config.Regexp
addressPattern config.Regexp
tiflashPattern config.Regexp
pumpPattern config.Regexp
drainerPattern config.Regexp
cdcPattern config.Regexp
importerPattern config.Regexp
lightningPattern config.Regexp
dashBoardConfig = `{
"apiVersion": 1,
"providers": [
{
Expand Down Expand Up @@ -108,6 +111,18 @@ func init() {
if err != nil {
klog.Fatalf("monitor regex template parse error,%v", err)
}
cdcPattern, err = config.NewRegexp("ticdc")
if err != nil {
klog.Fatalf("monitor regex template parse error,%v", err)
}
importerPattern, err = config.NewRegexp("importer")
if err != nil {
klog.Fatalf("monitor regex template parse error,%v", err)
}
lightningPattern, err = config.NewRegexp("tidb-lightning")
if err != nil {
klog.Fatalf("monitor regex template parse error,%v", err)
}
}

type MonitorConfigModel struct {
Expand All @@ -134,6 +149,9 @@ func newPrometheusConfig(cmodel *MonitorConfigModel) *config.Config {
scrapeJob("tiflash-proxy", tiflashPattern, cmodel, buildAddressRelabelConfigByComponent("tiflash-proxy")),
scrapeJob("pump", pumpPattern, cmodel, buildAddressRelabelConfigByComponent("pump")),
scrapeJob("drainer", drainerPattern, cmodel, buildAddressRelabelConfigByComponent("drainer")),
scrapeJob("ticdc", cdcPattern, cmodel, buildAddressRelabelConfigByComponent("ticdc")),
scrapeJob("importer", importerPattern, cmodel, buildAddressRelabelConfigByComponent("importer")),
scrapeJob("lightning", lightningPattern, cmodel, buildAddressRelabelConfigByComponent("lightning")),
},
}
return &c
Expand Down Expand Up @@ -164,6 +182,8 @@ func buildAddressRelabelConfigByComponent(kind string) *config.RelabelConfig {
return f()
case "tiflash":
return f()
case "ticdc":
return f()
case "tiflash-proxy":
return &config.RelabelConfig{
Action: config.RelabelReplace,
Expand All @@ -188,6 +208,18 @@ func buildAddressRelabelConfigByComponent(kind string) *config.RelabelConfig {
portLabel,
},
}
case "importer":
return &config.RelabelConfig{
Action: config.RelabelReplace,
Regex: addressPattern,
Replacement: "$1.$2-importer:$3",
TargetLabel: "__address__",
SourceLabels: model.LabelNames{
podNameLabel,
instanceLabel,
portLabel,
},
}
case "drainer":
return &config.RelabelConfig{
Action: config.RelabelReplace,
Expand All @@ -200,6 +232,18 @@ func buildAddressRelabelConfigByComponent(kind string) *config.RelabelConfig {
portLabel,
},
}
case "lightning":
return &config.RelabelConfig{
Action: config.RelabelReplace,
Regex: addressPattern,
Replacement: "$2:$3",
TargetLabel: "__address__",
SourceLabels: model.LabelNames{
podNameLabel,
nameLabel,
portLabel,
},
}
default:
return &config.RelabelConfig{
SourceLabels: model.LabelNames{
Expand Down
Loading

0 comments on commit 90e4b56

Please sign in to comment.