Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support config scrape_interval and scrape_timeout for prometheus #2071

Merged
merged 4 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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