diff --git a/embed/examples/cluster/topology.example.yaml b/embed/examples/cluster/topology.example.yaml index 6bf6a5c772..38c477f819 100644 --- a/embed/examples/cluster/topology.example.yaml +++ b/embed/examples/cluster/topology.example.yaml @@ -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. diff --git a/embed/templates/config/prometheus.yml.tpl b/embed/templates/config/prometheus.yml.tpl index 02226b14eb..3042cb76b0 100644 --- a/embed/templates/config/prometheus.yml.tpl +++ b/embed/templates/config/prometheus.yml.tpl @@ -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" diff --git a/pkg/cluster/spec/monitoring.go b/pkg/cluster/spec/monitoring.go index 2563e6bc76..219ad36443 100644 --- a/pkg/cluster/spec/monitoring.go +++ b/pkg/cluster/spec/monitoring.go @@ -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]interface{} `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 @@ -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 { diff --git a/pkg/cluster/template/config/prometheus.go b/pkg/cluster/template/config/prometheus.go index 8f0ef4233a..ba09ee69ac 100644 --- a/pkg/cluster/template/config/prometheus.go +++ b/pkg/cluster/template/config/prometheus.go @@ -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