首页  

prometheus配置     所属分类 prometheus 浏览量 5757
https://prometheus.io/docs/prometheus/latest/configuration/configuration/



Prometheus is configured via command-line flags and a configuration file. 
While the command-line flags configure immutable system parameters 
(such as storage locations, amount of data to keep on disk and in memory, etc.), 
the configuration file defines everything related to scraping jobs and their instances, 
as well as which rule files to load.


命令行配置不可变的系统参数

To view all available command-line flags, run ./prometheus -h.


--version                  
Show application version.
--config.file="prometheus.yml"  
Prometheus configuration file path.
--web.listen-address="0.0.0.0:9090"  

--web.enable-lifecycle     
Enable shutdown and reload via HTTP request.
--web.enable-admin-api     
Enable API endpoints for admin control actions.
      
--storage.tsdb.path="data/"  
Base path for metrics storage.
                                 
                                    

Prometheus can reload its configuration at runtime. 
If the new configuration is not well-formed, the changes will not be applied. 
A configuration reload is triggered by sending a SIGHUP to the Prometheus process 
or sending a HTTP POST request to the /-/reload endpoint (when the --web.enable-lifecycle flag is enabled). 
This will also reload any configured rule files.


配置热加载

kill -HUP pid
发送post 到 /-/reload   
需要 加上 --web.enable-lifecycle

否则
post  http://127.0.0.1:9090/-/reload
Lifecycle APIs are not enabled

curl -XPOST  http://127.0.0.1:9090/-/reload


scrape_configs:
  - job_name: 'app1'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.
    static_configs:
    - targets: ['192.168.0.8:8000','192.168.0.8:8010']


  - job_name: 'app2'
    metrics_path:'/my/metrics'
    static_configs:
    - targets: ['127.0.0.1:8080','127.0.0.1:8090']

    

To specify which configuration file to load, use the --config.file flag.
 YAML format,
 
Brackets indicate that a parameter is optional. 
括号表示参数是可选的。


https://github.com/prometheus/prometheus/blob/release-2.8/config/testdata/conf.good.yml

Targets may be statically configured via the static_configs parameter 
or dynamically discovered using one of the supported service-discovery mechanisms.


抓取目标 静态配置 或 动态发现




global:
  # How frequently to scrape targets by default.
  [ scrape_interval: <duration> | default = 1m ]

  # How long until a scrape request times out.
  [ scrape_timeout: <duration> | default = 10s ]

  # How frequently to evaluate rules.
  [ evaluation_interval: <duration> | default = 1m ]

  # The labels to add to any time series or alerts when communicating with
  # external systems (federation, remote storage, Alertmanager).
  external_labels:
    [ <labelname>: <labelvalue> ... ]

# Rule files specifies a list of globs. Rules and alerts are read from
# all matching files.
rule_files:
  [ - <filepath_glob> ... ]

# A list of scrape configurations.
scrape_configs:
  [ - <scrape_config> ... ]

# Alerting specifies settings related to the Alertmanager.
alerting:
  alert_relabel_configs:
    [ - <relabel_config> ... ]
  alertmanagers:
    [ - <alertmanager_config> ... ]

# Settings related to the remote write feature.
remote_write:
  [ - <remote_write> ... ]

# Settings related to the remote read feature.
remote_read:
  [ - <remote_read> ... ]
  



relabel_configs allow advanced modifications to any target and its labels before scraping.

metrics_path
default = /metrics 


#The job name assigned to scraped metrics by default.
job_name: $job_name


honor_labels  default = false 

controls how Prometheus handles conflicts between labels that are already present in scraped data 
and labels that Prometheus would attach server-side 
("job" and "instance" labels, manually configured target labels, 
and labels generated by service discovery implementations).


标签冲突处理

If honor_labels is set to "true", label conflicts are resolved by keeping label
values from the scraped data and ignoring the conflicting server-side labels.

honor_labels 设置为 true ,冲突忽略服务端标签


If honor_labels is set to "false", label conflicts are resolved by renaming
conflicting labels in the scraped data to "exported_" (for
example "exported_instance", "exported_job") and then attaching server-side
labels. This is useful for use cases such as federation, where all labels
specified in the target should be preserved.

冲突指标重命名  增加前缀

Optional HTTP URL parameters.

params:


xxx_sd_configs

sd
service discovery configurations

sd类型

consul  file openstack kubernetes marathon gce nerve  serverset triton   dns ec2 azure


static_configs:
 
# List of target relabel configurations.
relabel_configs

# List of metric relabel configurations.
metric_relabel_configs:

上一篇     下一篇
循环引用导致fastjson序列化与反序列化StackOverflowError

go语言defer机制

简单的清理脚本实战

linux下找出占用指定端口的进程

jvm设置滚动记录GC日志

基于数据库的分布式锁设计