Skip to content

Commit

Permalink
support config scrape_interval and scrape_timeout for prometheus (#2071)
Browse files Browse the repository at this point in the history
  • Loading branch information
nexustar authored Nov 10, 2022
1 parent 799b089 commit 75ba04a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions embed/examples/cluster/topology.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ monitoring_servers:
# log_dir: "/tidb-deploy/prometheus-8249/log"
# prometheus rule dir on TiUP machine
# rule_dir: /home/tidb/prometheus_rule
# scrape_interval: 15s
# scrape_timeout: 10s
# # Server configs are used to specify the configuration of Grafana Servers.
grafana_servers:
# # The ip address of the Grafana Server.
Expand Down
10 changes: 8 additions & 2 deletions embed/templates/config/prometheus.yml.tpl
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
---
global:
scrape_interval: 15s # By default, scrape targets every 15 seconds.
{{- if .ScrapeInterval}}
scrape_interval: {{.ScrapeInterval}}
{{- else}}
scrape_interval: 15s # By default, scrape targets every 15 seconds.
{{- end}}
evaluation_interval: 15s # By default, scrape targets every 15 seconds.
# scrape_timeout is set to the global default (10s).
{{- if .ScrapeTimeout}}
scrape_timeout: {{.ScrapeTimeout}}
{{- end}}
external_labels:
cluster: '{{.ClusterName}}'
monitor: "prometheus"
Expand Down
4 changes: 4 additions & 0 deletions pkg/cluster/spec/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ type PrometheusSpec struct {
OS string `yaml:"os,omitempty"`
RuleDir string `yaml:"rule_dir,omitempty" validate:"rule_dir:editable"`
AdditionalScrapeConf map[string]any `yaml:"additional_scrape_conf,omitempty" validate:"additional_scrape_conf:ignore"`
ScrapeInterval string `yaml:"scrape_interval,omitempty" validate:"scrape_interval:editable"`
ScrapeTimeout string `yaml:"scrape_timeout,omitempty" validate:"scrape_timeout:editable"`
}

// Remote prometheus remote config
Expand Down Expand Up @@ -199,6 +201,8 @@ func (i *MonitorInstance) InitConfig(
if monitoredOptions != nil {
cfig.AddBlackbox(i.GetHost(), uint64(monitoredOptions.BlackboxExporterPort))
}
cfig.ScrapeInterval = spec.ScrapeInterval
cfig.ScrapeTimeout = spec.ScrapeTimeout
uniqueHosts := set.NewStringSet()

if servers, found := topoHasField("PDServers"); found {
Expand Down
2 changes: 2 additions & 0 deletions pkg/cluster/template/config/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
// PrometheusConfig represent the data to generate Prometheus config
type PrometheusConfig struct {
ClusterName string
ScrapeInterval string
ScrapeTimeout string
TLSEnabled bool
NodeExporterAddrs []string
TiDBStatusAddrs []string
Expand Down

0 comments on commit 75ba04a

Please sign in to comment.