prometheus命令_Prometheus配置

配置

Prometheus可以通过命令行参数和配置文件来配置它的服务参数。命令行主要用于配置系统参数(例如:存储的位置,保留在磁盘和内存中的数据量的大小等),配置文件主要用于配置与抓取任务和任务下的实例相关的所有内容, 并且加载指定的抓取规则file。

可以通过运行prometheus -h命令, 查看Prometheus所有可用的命令行参数,

Prometheus服务可以reload它的配置。如果这个配置错误,则更改后的配置不生效。配置reolad是通过给Prometheus服务发送信号量SIGHUP或者通过http发送一个post请求到/-/reload。这也会重载所有配置的规则文件(rule files)。

配置文件(Configuration file)

使用-config.file命令行参数来指定Prometheus启动所需要的配置文件。

这个配置文件是YAML格式, 通过下面描述的范式定义, 括号表示参数是可选的。对于非列表参数,这个值被设置了默认值。

通用占位符由下面定义:

: 一个布尔值,包括true或者false.

: 持续时间,与正则表达式[0-9]+(ms|smhdwy)匹配

: 一个与正则表达式[a-zA-Z_][a-zA-Z0-9_]*匹配的字符串

: 一个为unicode字符串

: 当前工作目录下的有效路径

: 一个包含主机名或者IP地址,并且可以带上一个非必需的端口号的有效字符串

: 一个有效的URL路径

: 一个可以是http或者https的字符串

: 一个正则表达式字符串

其他的占位符被分开指定:

一个有效的配置文件示例。

全局配置指定的参数,在其他上下文配置中是生效的。这也默认这些全局参数在其他配置区域有效。

global:

# 抓取目标实例的频率时间值,默认1分钟

[ scrape_interval: | default = 1m ]

# 一次抓取请求超时时间值,默认10s

[ scrape_timeout: | default = 10s ]

# 执行配置文件规则的频率时间值, 默认1m

[ evaluation_interval: | default = 1m ]

# 当和外部系统通信时(federation, remote storage, Alertmanager), 这些标签会增加到度量指标数据中

external_labels:

[ : ... ]

# 规则文件指定规则文件路径列表。规则和警报是从所有匹配的文件中读取的

rule_files:

[ - ... ]

# 抓取配置的列表

scrape_configs:

[ - ... ]

# Alerting指定与Alertmanager相关的设置。

alerting:

alert_relabel_configs:

[ - ... ]

alertmanagers:

[ - ... ]

# 与远程写入功能相关的设置。

remote_write:

[ - ... ]

# 与远程读取功能相关的设置。

remote_read:

[ - ... ]

scrape_config 区域指定了一组目标和描述如何抓取(scrape)目标的参数。通常,一个抓取配置只能指定了一个job。在高级配置中,这可能会改变。

通过static_configs参数静态指定要监控的目标列表,或者使用一些服务发现机制动态的发现目标。

另外,relabel_configs允许在获取度量指标数据之前,对任何目标和它的标签进行进一步地修改。

# 默认下任务名称赋值给要抓取的度量指标

job_name:

# 从这个任务中抓取目标的频率时间值

[ scrape_interval: | default= ]

# 当抓取这个任务的所有目标时,超时时间值

[ scrape_timeout: | default = ]

# 从目标列表中抓取度量指标的http资源路径, 默认为/metrics

[ metrics_path: | default = /metrics ]

# honor_labels controls how Prometheus handles conflicts between would 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 labe# ls. If honor_labels is set to "false", label conflicts are resolved by ren# amin 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 label#s specified in the target should be preserved. Note that any globally configured "external_labels" are unaffected by this

# setting. In communication with external systems, they are always applied

# only when a time series does not have a given label yet and are ignored otherwise.

[ honor_labels: | default = false ]

# 配置请求的协议范式, 默认为http请求

[ scheme: | default = http ]

# 可选的http url参数

params:

[ :[, ...]]

# 在`Authorization`头部设置每次抓取请求的用户名和密码

basic_auth:

[username: ]

[password: ]

# Sets the `Authorization` header on every scrape request with

# the configured bearer token. It is mutually exclusive with `bearer_token_file`.

[ bearer_token: ]

# Sets the `Authorization` header on every scrape request with the bearer token read from the configured file. It is mutually exclusive with `bearer_token`.

[ bearer_token_file: /path/to/bearer/token/file ]

# 配置抓取请求的TLS设置

tls_config:

[ ]

# 可选的代理URL

[ proxy_url: ]

# 微软的Azure服务发现配置列表

azure_sd_configs:

[ - ... ]

# Consul服务发现配置列表

consul_sd_configs:

[ - ... ]

# DNS服务发现配置列表

dns_sd_configs:

[ - ... ]

# 亚马逊EC2服务发现的配置列表

ec2_sd_configs:

[ - ... ]

# 文件服务发现配置列表

file_sd_configs:

[ - ... ]

# google GCE服务发现配置列表

gce_sd_configs:

[ - ... ]

# Kubernetes服务发现配置列表

kubernetes_sd_configs:

[ - ... ]

# Marathon服务发现配置列表

marathon_sd_configs:

[ - ... ]

# AirBnB的Nerve服务发现配置列表

nerve_sd_configs:

[ - ... ]

# Zookeeper服务发现配置列表

serverset_sd_configs:

[ - ... ]

# Triton服务发现配置列表

triton_sd_configs:

[ - ... ]

# 静态配置目标列表

static_configs:

[ - ... ]

# 抓取之前的标签重构配置列表

relabel_configs:

[ - ... ]

# List of metric relabel configurations.

metric_relabel_configs:

[ - ... ]

# Per-scrape limit on number of scraped samples that will be accepted.

# If more than this number of samples are present after metric relabelling

# the entire scrape will be treated as failed. 0 means no limit.

[ sample_limit: | default = 0 ]

# Per-scrape config limit on number of unique targets that will be

# accepted. If more than this number of targets are present after target

# relabeling, Prometheus will mark the targets as failed without scraping them.

# 0 means no limit. This is an experimental feature, this behaviour could

# change in the future.

[ target_limit: | default = 0 ]

记住:在所有获取配置中必须是唯一的。

允许配置TLS连接。

# CA证书

[ ca_file: ]

# 证书和key文件

[ cert_file: ]

[ key_file: ]

# ServerName extension to indicate the name of the server.

# http://tools.ietf.org/html/rfc4366#section-3.1

[ server_name: ]

# Disable validation of the server certificate.

[ insecure_skip_verify: ]

sd_config配置

一个static_config允许指定目标列表,以及附带的通用标签。在获取配置中指定静态目标是规范的方法

# The targets specified by the static config.

targets:

[ - '' ]

# Labels assigned to all metrics scraped from the targets.

labels:

[ : ... ]

Relabeling是一个非常强大的工具,在获取度量指标之前,它可以动态地重写标签集合。 每个获取配置过程中,多个relabeling步骤能够被配置。它们按照出现在配置文件中的顺序,应用到每个目标的标签集中。

最初,除了配置的每个目标标签之外,目标的job标签设置为相应获取配置的job_name值,这个__address__标签设置为目标地址:。在relabeling之后,这个instance标签默认设置为__address__标签值。这个__scheme__和__metrics_path__标签设置为各自目标的范式和度量指标路径。 __param_标签设置为成为的第一个传入的URL参数。

另外以__meta__为前缀的标签在relabeling阶段是可用的。他们由服务发现机制设置。

在relabeling完成之后,由__开头的标签将会从标签集合从移除。

如果一个relabeling步骤仅仅需要临时地存储标签值(作为后续relabeling步骤的输入),使用以__tmp为前缀的标签名称。这个前缀需要确保Prometheus本身从没有使用。

# 源标签从现有标签中选择值。 它们的内容使用配置的分隔符连接起来,并与配置的正则表达式匹配,以进行替换,保持和`drop`动作。

[ source_labels: '[' [, ...] ']' ]

# 在连接的source label值之间放置分隔符。

[ separator: | default = ; ]

# 在替换操作中将结果值写入的标签。

# 替换操作是必需的。 正则表达式捕获组可用。

[ target_label: ]

# 与提取的值匹配的正则表达式。

[ regex: | default = (.*) ]

# Modulus to take of the hash of the source label values.

[ modulus: ]

# 如果正则表达式匹配,则执行正则表达式替换的替换值。 正则表达式捕获组可用。

[ replacement: | default = $1 ]

# 基于正则表达式匹配执行的操作。

[ action: | default = replace ]

是任何有效的正则表达式,它提供replace, keep, drop, labelmap, labeldrop, labelkeep动作,正则表达式处于两端。要取消指定正则表达式,请使用 .*.*。

决定要采取的relabeling动作。

replace: 匹配与source_labels相反的regex。然后,设置target_label替换source_labels, 返回结果包括(${1}, ${2}, ...)。 如果正则表达会不匹配,则不进行任何替换。

keep: 放弃与source_labels标签不匹配的目标

drop: 放弃与source_labels标签匹配的目标

hashmod: 将target_label设置为source_labels的散列模数

labelmap: 匹配所有的标签名称,然后将匹配到的标签值复制为由匹配组引用(${1}, ${2},...) 替换的标签名称替换为其值

labeldrop: 匹配所有的标签名称。然后删除匹配到的标签集合。

labelkeep: 匹配所有的标签名称。然后保留匹配到的标签集合。

必须注意labeldrop和labelkeep, 以确保除去标签后,度量指标仍然会被唯一标识。

在警告被发送到Alertmanager之前,警告relabeling应用到alerts。它有相同配置格式和目标relabeling动作。警告relabeling被应用到外部标签。

一个用途是确保HA对Prometheus服务与不同的外部标签发送相同的警告。

Alertmanager实例的动态发现是处于alpha状态。在将来的版本中配置会发生较大地更改。通过-alertmanager.url标志使用静态配置

alertmanager_config区域指定了Prometheus服务发送警告的Alertmanager实例。它也提供参数配置与这些Alertmanagers的通信。

Alertmanagers可以通过static_configs参数静态配置,或者使用服务发现机制动态发现目标。

另外,从发现的实体和使用的API路径,relabel_configs允许从发现的实体列表和提供可使用的API路径中选择路径。这个api path是通过__alerts_path__标签暴露出来的。

# Per-target Alertmanager timeout when pushing alerts.

[ timeout: | default = 10s ]

# Prefix for the HTTP path alerts are pushed to.

[ path_prefix: | default = / ]

# Configures the protocol scheme used for requests.

[ scheme: | default = http ]

# Sets the `Authorization` header on every request with the

# configured username and password.

basic_auth:

[ username: ]

[ password: ]

# Sets the `Authorization` header on every request with

# the configured bearer token. It is mutually exclusive with `bearer_token_file`.

[ bearer_token: ]

# Sets the `Authorization` header on every request with the bearer token

# read from the configured file. It is mutually exclusive with `bearer_token`.

[ bearer_token_file: /path/to/bearer/token/file ]

# Configures the scrape request's TLS settings.

tls_config:

[ ]

# Optional proxy URL.

[ proxy_url: ]

# List of Azure service discovery configurations.

azure_sd_configs:

[ - ... ]

# List of Consul service discovery configurations.

consul_sd_configs:

[ - ... ]

# List of DNS service discovery configurations.

dns_sd_configs:

[ - ... ]

# List of EC2 service discovery configurations.

ec2_sd_configs:

[ - ... ]

# List of file service discovery configurations.

file_sd_configs:

[ - ... ]

# List of GCE service discovery configurations.

gce_sd_configs:

[ - ... ]

# List of Kubernetes service discovery configurations.

kubernetes_sd_configs:

[ - ... ]

# List of Marathon service discovery configurations.

marathon_sd_configs:

[ - ... ]

# List of AirBnB's Nerve service discovery configurations.

nerve_sd_configs:

[ - ... ]

# List of Zookeeper Serverset service discovery configurations.

serverset_sd_configs:

[ - ... ]

# List of Triton service discovery configurations.

triton_sd_configs:

[ - ... ]

# List of labeled statically configured Alertmanagers.

static_configs:

[ - ... ]

# List of Alertmanager relabel configurations.

relabel_configs:

[ - ... ]

远程写是实验性的:在将来的版本中配置可能会实质性地变化

url是发送样本的端点URL。remote_timeout指定发送请求到URL的超时时间。目前没有重试机制

basic_auth, tls_config和proxy_url和在scrape_config区域里有相同的含义。

write_relabel_configs是relabeling应用到样本数据的。写relabeling是应用到外部标签之后的。这可能有样本发送数量的限制。

这里有一个小Demo,告诉你怎样使用这个功能

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值