记录下自己线上服务器一个简单的prometheus.yml配置文件,部分敏感信息抹除:
[root@cn-hz-21yunwei-devops rule]# cat ../prometheus.yml # my global config global: scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. # scrape_timeout is set to the global default (10s). # Alertmanager configuration:告警配置,集成alertmanager插件 alerting: alertmanagers: - static_configs: - targets: - 127.0.0.1:9093 # Load rules once and periodically evaluate them according to the global 'evaluation_interval'. rule_files: - "rule/*.yml" # A scrape configuration containing exactly one endpoint to scrape: # Here it's Prometheus itself. scrape_configs: # The job name is added as a label `job=` to any timeseries scraped from this config. - job_name: 'cn-hz-21yunwei-devops' # metrics_path defaults to '/metrics' # scheme defaults to 'http'. static_configs: - targets: ['cn-hz-21yunwei-devops:9100'] #通过配置file 获取target,记录21yunwei的 web - job_name: 'cn-hz-21yunwei-other' file_sd_configs: - files: - file_config/21yunwei/host.json #判断告警搜 probe_success ## tcp端口检测 - job_name: "tcp_port_check" scrape_interval: 15s scrape_timeout: 15s metrics_path: /probe params: module: [tcp_connect] file_sd_configs: - files: - check/port/*_port.json relabel_configs: - source_labels: [__address__] target_label: __param_target - source_labels: [__param_target] target_label: instance - target_label: __address__ replacement: ******:9115 ## 判断状态码搜 probe_http_status_code ## 接口检测 - job_name: 'http_url_check' scrape_interval: 15s scrape_timeout: 15s metrics_path: /probe params: module: [http_2xx] # Look for a HTTP 200 response. file_sd_configs: - files: - check/url/*_url.json relabel_configs: - source_labels: [__address__] target_label: __param_target - source_labels: [__param_target] target_label: instance - target_label: __address__ replacement: *******:9115 ### ICMP检测 - job_name: 'icmp_check' scrape_interval: 15s scrape_timeout: 15s metrics_path: /probe params: module: [icmp] file_sd_configs: - files: - check/icmp/*_icmp.json relabel_configs: - source_labels: [__address__] target_label: __param_target - source_labels: [__param_target] target_label: instance - target_label: __address__ replacement: ******:9115
很简单但是实用:
(1)配置global参数(采集周期以及规则扫描周期);
(2)集成alertmanager插件,用于后续报警操作;
(3)设定报警rule 加载目录;
(4)设定采集对象。这里既有静态设置也有设置服务发现。(服务发现用于后续target更改只需要进行规则修改即可,不需要进行prometheus守护进程重启)
(5)设定功能检测。 这里定义了icmp、tcp_port、url三种check,分别通过调用blackbox_exporter来实现。
转载请注明:21运维 » Prometheus 自用配置文件-笔记