Prometheus 配置详解

该文章大部分来自官网文档:prometheus 官网文档

prometheus 通过命令行启动参数和配置文件进行配置。命令行一般定义的是不可改变的系统参数(例如存储位置、要保存在磁盘和内存中的数据量等),文件配置的定义了抓取的job和抓取的 instance,以及文件以哪些规则加载。

查看所有的命令行参数,可以使用prometheus -h

prometheus可以在运行时重载配置。如果配置格式不正确,则不会更改应用。通过向prometheus进程发送SIGHUP信号,或者对/-/reload发送一个HTTP POST请求(前提是--web.enable-lifecycle开启了)。这也会重载配置好的规则文件。

配置文件

如果要指定加载的配置文件,启动需要加上命令参数--config.file

配置文件一般都是YAML格式,由下面描述的方案定义。 括号表示参数是可选的。 对于非列表参数,该值设置为指定的默认值。

通用占位符定义如下:

  • <boolean>:一个可以取值为truefalse的布尔值
  • <duration>:与正则表达式匹配的持续时间[0-9] +(ms | [smhdwy]
  • <labelname>:与正则表达式匹配的字符串[a-zA-Z _] [a-zA-Z0-9 _] *
  • <labelvalue>:一串unicode字符
  • <filename>:当前工作目录中的有效路径
  • <host>:由主机名或IP后跟可选端口号组成的有效字符串
  • <path>:有效的URL路径
  • <scheme>:一个可以取值httphttps的字符串
  • <string>:常规字符串
  • <secret>:一个秘密的常规字符串,例如密码
  • <tmpl_string>:在使用前进行模板扩展的字符串

其他占位符是单独指定的。

全局配置指定在所有其他配置上下文中有效的参数。 它们还可用作其他配置节的默认值。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
global:
# 默认情况下抓取目标的频率.
[ scrape_interval: <duration> | default = 1m ]

# 抓取超时时间.
[ scrape_timeout: <duration> | default = 10s ]

# 评估规则的频率.
[ evaluation_interval: <duration> | default = 1m ]

# 与外部系统通信时添加到任何时间序列或警报的标签
#(联合,远程存储,Alertma# nager).
external_labels:
[ <labelname>: <labelvalue> ... ]

# 记录PROMQL查询的文件。
# 重新加载配置将重新打开文件。
[ query_log_file: <string> ]

# 规则文件指定了一个globs列表.
# 从所有匹配的文件中读取规则和警报.
rule_files:
[ - <filepath_glob> ... ]

# 抓取配置列表.
scrape_configs:
[ - <scrape_config> ... ]

# 警报指定与Alertmanager相关的设置.
alerting:
alert_relabel_configs:
[ - <relabel_config> ... ]
alertmanagers:
[ - <alertmanager_config> ... ]

# 与远程写入功能相关的设置.
remote_write:
[ - <remote_write> ... ]

# 与远程读取功能相关的设置.
remote_read:
[ - <remote_read> ... ]

# 运行时可重新加载的存储相关设置。
storage:
[ - <exemplars> ... ]

# Configures exporting traces.
tracing:
[ <tracing_config> ]

global

scrape_interval

抓取目标的频率

scrape_timeout

抓取超时时间

evaluation_interval

评估规则的频率

external_labels

与外部系统通信时添加到任何时间序列或警报的标签。

scrape_config

<scrape_config>部分指定一组描述如何刮除它们的目标和参数。 在一般情况下,一个scrape配置指定单个作业。 在高级配置中,这可能会改变。

目标可以通过<static_configs>参数静态配置,也可以使用其中一种支持的服务发现机制动态发现。

此外,<relabel_configs>允许在抓取之前对任何目标及其标签进行高级修改。

其中<job_name>在所有scrape配置中必须是唯一的。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# 默认分配给已抓取指标的job名称。
job_name: <job_name>

# 从job中抓取目标的频率.
[ scrape_interval: <duration> | default = <global_config.scrape_interval> ]

# 抓取此job时,每次抓取超时时间.
[ scrape_timeout: <duration> | default = <global_config.scrape_timeout> ]

# 从目标获取指标的HTTP资源路径.
[ metrics_path: <path> | default = /metrics ]

# honor_labels控制Prometheus如何处理已经存在于已抓取数据中的标签与Prometheus将附加服务器端的标签之间的冲突("job"和"instance"标签,手动配置的目标标签以及服务发现实现生成的标签)。
#
# 如果honor_labels设置为"true",则通过保留已抓取数据的标签值并忽略冲突的服务器端标签来解决标签冲突。
#
# 如果honor_labels设置为"false",则通过将已抓取数据中的冲突标签重命名为"exported_ <original-label>"(例如"exported_instance","exported_job")然后附加服务器端标签来解决标签冲突。 这对于联合等用例很有用,其中应保留目标中指定的所有标签。
#
# 请注意,任何全局配置的"external_labels"都不受此设置的影响。 在与外部系统通信时,它们始终仅在时间序列尚未具有给定标签时应用,否则将被忽略。
#
[ honor_labels: <boolean> | default = false ]

# 配置用于请求的协议方案.
[ scheme: <scheme> | default = http ]

# 可选的HTTP URL参数.
params:
[ <string>: [<string>, ...] ]

# 使用配置的用户名和密码在每个scrape请求上设置`Authorization`标头。 password和password_file是互斥的。
basic_auth:
[ username: <string> ]
[ password: <secret> ]
[ password_file: <string> ]

# 每次抓取的认证信息
authorization:
# 认证信息的类型
[ type: <string> | default: Bearer ]
# 认证秘钥
[ credentials: <secret> ]
# 认证秘钥
[ credentials_file: <filename> ]

# oauth2相关配置。
oauth2:
[ <oauth2> ]

# 是否重定向
[ follow_redirects: <boolean> | default = true ]

# 配置scrape请求的TLS设置.
tls_config:
[ <tls_config> ]

# 可选的代理URL.
[ proxy_url: <string> ]

# Azure服务发现配置列表.
azure_sd_configs:
[ - <azure_sd_config> ... ]

# Consul服务发现配置列表.
consul_sd_configs:
[ - <consul_sd_config> ... ]

# DigitalOcean服务发现配置列表。
digitalocean_sd_configs:
[ - <digitalocean_sd_config> ... ]

# Docker服务发现配置列表。
docker_sd_configs:
[ - <docker_sd_config> ... ]

# Docker Swarm服务发现配置列表。
dockerswarm_sd_configs:
[ - <dockerswarm_sd_config> ... ]

# DNS服务发现配置列表。
dns_sd_configs:
[ - <dns_sd_config> ... ]

# EC2服务发现配置列表。
ec2_sd_configs:
[ - <ec2_sd_config> ... ]

# Eureka服务发现配置列表。
eureka_sd_configs:
[ - <eureka_sd_config> ... ]


# 文件服务发现配置列表。
file_sd_configs:
[ - <file_sd_config> ... ]

# GCE服务发现配置列表。
gce_sd_configs:
[ - <gce_sd_config> ... ]

# Hetzner服务发现配置列表。
hetzner_sd_configs:
[ - <hetzner_sd_config> ... ]

# HTTP服务发现配置列表。
http_sd_configs:
[ - <http_sd_config> ... ]

# Kubernetes服务发现配置列表。
kubernetes_sd_configs:
[ - <kubernetes_sd_config> ... ]

# Kuma服务发现配置列表。
kuma_sd_configs:
[ - <kuma_sd_config> ... ]

# Lightsail服务发现配置列表。
lightsail_sd_configs:
[ - <lightsail_sd_config> ... ]

# linode服务发现配置列表。
linode_sd_configs:
[ - <linode_sd_config> ... ]

# Marathon服务发现配置列表。
marathon_sd_configs:
[ - <marathon_sd_config> ... ]

# AirBnB的神经服务发现配置列表。
nerve_sd_configs:
[ - <nerve_sd_config> ... ]

# openstack服务发现配置列表。
openstack_sd_configs:
[ - <openstack_sd_config> ... ]

# puppetdb服务发现配置列表
puppetdb_sd_configs:
[ - <puppetdb_sd_config> ... ]

# scaleway服务发现配置列表
scaleway_sd_configs:
[ - <scaleway_sd_config> ... ]

# Zookeeper Serverset服务发现配置列表。
serverset_sd_configs:
[ - <serverset_sd_config> ... ]

# Triton服务发现配置列表。
triton_sd_configs:
[ - <triton_sd_config> ... ]

# uyuni服务发现配置列表。
uyuni_sd_configs:
[ - <uyuni_sd_config> ... ]

# 此job的标记静态配置目标列表。
static_configs:
[ - <static_config> ... ]

# 目标重新标记配置列表。
relabel_configs:
[ - <relabel_config> ... ]

# 度量标准重新配置列表。
metric_relabel_configs:
[ - <relabel_config> ... ]

# 对每个将被接受的样本数量的每次抓取限制。
# 如果在度量重新标记后存在超过此数量的样本,则整个抓取将被视为失败。 0表示没有限制。
[ sample_limit: <int> | default = 0 ]

# 采样标签数量的限制,如果大于这个限制数量,将视为采集失败。
# 0表示没有限制。
[ label_limit: <int> | default = 0 ]

# 采样的标签名字长度限制,如果标签名字大于这个长度,将采样失败。
# 0表示不限制
[ label_name_length_limit: <int> | default = 0 ]

# 采样的标签值长度限制,如果标签值大于这个长度,将采样失败。
# 0表示不限制
[ label_value_length_limit: <int> | default = 0 ]

# 采集目标数量的限制,如果大于这个限制,将不会在采集。
# 0表示不限制。
# 这是一个实验性的功能,未来可能会更改。
[ target_limit: <int> | default = 0 ]

tls_config

<tls_config>允许配置tls链接

1
2
3
4
5
6
7
8
9
10
11
12
13
# 用于验证API服务器证书的CA证书。
[ ca_file: <filename> ]

# 用于服务器的客户端证书身份验证的证书和密钥文件。
[ cert_file: <filename> ]
[ key_file: <filename> ]

# ServerName扩展名,用于指示服务器的名称。
# https://tools.ietf.org/html/rfc4366#section-3.1
[ server_name: <string> ]

# 禁用服务器证书的验证。
[ insecure_skip_verify: <boolean> ]

oauth2

使用客户端凭据授予类型的 OAuth 2.0 身份验证。Prometheus 使用给定的客户端访问和密钥从指定的端点获取访问令牌。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
client_id: <string>
[ client_secret: <secret> ]

# 从文件中获取秘钥
[ client_secret_file: <filename> ]

# 令牌请求的作用域。
scopes:
[ - <string> ... ]

# 要从中获取令牌的URL。
token_url: <string>

# 附加到令牌URL的可选参数。
endpoint_params:
[ <string>: <string> ... ]

# 配置令牌请求的TLS设置。
tls_config:
[ <tls_config> ]

azure_sd_config

Azure SD 配置允许从Azure VM检索抓取目标。

在重新标记期间,目标上可以使用以下元标签:

  • __meta_azure_machine_id:机器ID
  • __meta_azure_machine_location: 机器运行的位置
  • __meta_azure_machine_name:机器名称
  • __meta_azure_machine_computer_name:机器计算机名
  • __meta_azure_machine_os_type:机器操作系统
  • __meta_azure_machine_private_ip:机器的私有IP
  • __meta_azure_machine_public_ip: 机器的公网 IP(如果存在)
  • __meta_azure_machine_resource_group:机器的资源组
  • _meta_azure_machine_tag:机器的每个标签值
  • __meta_azure_machine_scale_set: vm 所属的规模集的名称(仅当您使用规模集时才设置此值)
  • __meta_azure_subscription_id: 订阅号
  • __meta_azure_tenant_id: 租户 ID

有关 Azure 发现的配置选项,请参见下文:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# 访问Azure API的信息。
# Azure 环境变量
[ environment: <string> | default = AzurePublicCloud ]

# 身份验证方法,OAuth或ManagedIdentity。
# 详情参考 https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview
[ authentication_method: <string> | default = OAuth]
# 订阅ID。必填。
subscription_id: <string>
# 可选的承租者ID。仅在OAuth认证方法中需要。
[ tenant_id: <string> ]
# 可选的客户机ID。仅在OAuth认证方法中需要。
[ client_id: <string> ]
# 可选的客户秘密。仅在OAuth认证方法中需要。
[ client_secret: <secret> ]

# 重新读取实例列表的刷新间隔。
[ refresh_interval: <duration> | default = 300s ]

# 采集端口,如果是公网,必须在标签规则中指定。
[ port: <int> | default = 80 ]

# 用于向Azure API进行认证的认证信息。
# 请注意,' basic auth ', ' authorization '和' oauth2 '选项是互斥的。
# ' password '和' password file '互斥。

# 可选的HTTP基本认证信息,目前Azure不支持。
basic_auth:
[ username: <string> ]
[ password: <secret> ]
[ password_file: <string> ]

# 可选的“授权”头配置,目前Azure不支持。
authorization:
# Sets the authentication type.
[ type: <string> | default: Bearer ]
# Sets the credentials. It is mutually exclusive with
# `credentials_file`.
[ credentials: <secret> ]
# Sets the credentials to the credentials read from the configured file.
# It is mutually exclusive with `credentials`.
[ credentials_file: <filename> ]

# 可选的OAuth 2.0配置,目前Azure不支持。
oauth2:
[ <oauth2> ]

# 可选的代理URL.
[ proxy_url: <string> ]

# 是否允许重定向
[ follow_redirects: <boolean> | default = true ]

# TLS 配置.
tls_config:
[ <tls_config> ]

consul_sd_config

Consul SD 配置允许从Consul 的 Catalog API检索抓取目标。

在重新标记期间,目标上可以使用以下元标签

  • __meta_consul_address: 目标地址
  • __meta_consul_dc:目标的数据中心名称
  • __meta_consul_health:服务的健康状态
  • _meta_consul_metadata:目标的每个节点元数据键值
  • __meta_consul_node:为目标定义的节点名称
  • __meta_consul_service_address:目标的服务地址
  • __meta_consul_service_id:目标的服务ID
  • _meta_consul_service_metadata:目标的每个服务元数据键值
  • __meta_consul_service_port:目标的服务端口
  • __meta_consul_service:目标所属服务的名称
  • _meta_consul_tagged_address:每个节点标记的目标地址键值
  • __meta_consul_tags: 由标签分隔符连接的目标标签列表
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# 用于访问 Consul API的信息,根据Consul 文档定义。
[ server: <host> | default = "localhost:8500" ]
[ token: <secret> ]
[ datacenter: <string> ]
# Consul 企业版才会支持namespace
[ namespace: <string> ]
[ scheme: <string> | default = "http" ]
# 不推荐使用用户名和密码字段,推荐使用basic_auth验证配置。
[ username: <string> ]
[ password: <secret> ]

# 将要采集的服务列表,如果省略,将会采集所有的。
services:
[ - <string> ]

# 如果想知道更多可用的过滤器,请查看 https://www.consul.io/api/catalog.html#list-nodes-for-service

# 用于过滤给定服务的节点的可选标签列表。服务必须包含列表中的所有标签。
tags:
[ - <string> ]

# 对于给定服务的节点元数据键值对。
[ node_meta:
[ <string>: <string> ... ] ]

# consul label 和 consul tag的连接字符串
[ tag_separator: <string> | default = , ]

# 允许过期的consul结果 (文档 https://www.consul.io/api/features/consistency.html). Will reduce load on Consul.
[ allow_stale: <boolean> | default = true ]

# 提供者的名字变更后多久需要刷新
[ refresh_interval: <duration> | default = 30s ]

# consul server的认证信息.
# `basic_auth`, `authorization` and `oauth2` 互斥。
# `password` and `password_file` 互斥。

# 可选的认证信息
basic_auth:
[ username: <string> ]
[ password: <secret> ]
[ password_file: <string> ]

# 可以的 `Authorization` 请求头配置.
authorization:
# Sets the authentication type.
[ type: <string> | default: Bearer ]
# Sets the credentials. It is mutually exclusive with
# `credentials_file`.
[ credentials: <secret> ]
# Sets the credentials to the credentials read from the configured file.
# It is mutually exclusive with `credentials`.
[ credentials_file: <filename> ]

# 可选的oauth2配置
oauth2:
[ <oauth2> ]

# 可选的代理配置
[ proxy_url: <string> ]

# 是否允许重定向。
[ follow_redirects: <boolean> | default = true ]

# TLS 配置.
tls_config:
[ <tls_config> ]

请注意,用于抓取目标的 IP 号和端口组合为 <__meta_consul_address>:<__meta_consul_service_port>. 但是,在某些 Consul 设置中,相关地址位于__meta_consul_service_address. 在这些情况下,您可以使用重新标记 功能来替换特殊__address__标签。

重新标记阶段是基于任意标签过滤服务或服务节点的首选且更强大的方法。对于拥有数千个服务的用户,直接使用 Consul API 会更有效,它对过滤节点有基本的支持(目前通过节点元数据和单个标签)。

digitalocean_sd_config

DigitalOcean SD 配置允许从DigitalOcean 的 Droplets API 检索抓取目标。此服务发现默认使用公共 IPv4 地址,可以通过重新标记来更改,如Prometheus digitalocean-sd 配置文件中所示。

在重新标记期间,目标上可以使用以下元标签

  • __meta_digitalocean_droplet_id: 水滴的id
  • __meta_digitalocean_droplet_name: 水滴的名字
  • __meta_digitalocean_image: 水滴图像的 slug
  • __meta_digitalocean_image_name: 水滴图像的显示名称
  • __meta_digitalocean_private_ipv4: droplet 的私有 IPv4
  • __meta_digitalocean_public_ipv4:droplet 的公网 IPv4
  • __meta_digitalocean_public_ipv6:droplet 的公网 IPv6
  • __meta_digitalocean_region:液滴的区域
  • __meta_digitalocean_size:液滴的大小
  • __meta_digitalocean_status:液滴的状态
  • __meta_digitalocean_features:以逗号分隔的液滴特征列表
  • __meta_digitalocean_tags:以逗号分隔的液滴标签列表
  • __meta_digitalocean_vpc:Droplet 的 VPC 的 id
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
basic_auth:
[ username: <string> ]
[ password: <secret> ]
[ password_file: <string> ]

authorization:
# Sets the authentication type.
[ type: <string> | default: Bearer ]
# Sets the credentials. It is mutually exclusive with
# `credentials_file`.
[ credentials: <secret> ]
# Sets the credentials to the credentials read from the configured file.
# It is mutually exclusive with `credentials`.
[ credentials_file: <filename> ]

# Optional OAuth 2.0 configuration.
# Cannot be used at the same time as basic_auth or authorization.
oauth2:
[ <oauth2> ]

# Optional proxy URL.
[ proxy_url: <string> ]

# Configure whether HTTP requests follow HTTP 3xx redirects.
[ follow_redirects: <boolean> | default = true ]

# TLS configuration.
tls_config:
[ <tls_config> ]

# The port to scrape metrics from.
[ port: <int> | default = 80 ]

# The time after which the droplets are refreshed.
[ refresh_interval: <duration> | default = 60s ]

docker_sd_config

Docker SD 配置允许从Docker 引擎主机检索抓取目标。

此 SD 发现“容器”,并将为容器配置公开的每个网络 IP 和端口创建一个目标。

可用的元标签:

  • __meta_docker_container_id: 容器的id
  • __meta_docker_container_name: 容器的名称
  • __meta_docker_container_network_mode: 容器的网络模式
  • _meta_docker_container_label:容器的每个标签
  • __meta_docker_network_id: 网络ID
  • __meta_docker_network_name: 网络名称
  • __meta_docker_network_ingress: 网络是否是入口
  • __meta_docker_network_internal: 网络是否为内部网络
  • _meta_docker_network_label:网络的每个标签
  • __meta_docker_network_scope: 网络范围
  • __meta_docker_network_ip:该网络中容器的IP
  • __meta_docker_port_private: 容器上的端口
  • __meta_docker_port_public:如果存在端口映射,则为外部端口
  • __meta_docker_port_public_ip:如果存在端口映射,则为公共 IP

有关 Docker 发现的配置选项,请参见下文:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Address of the Docker daemon.
host: <string>

# Optional proxy URL.
[ proxy_url: <string> ]

# TLS configuration.
tls_config:
[ <tls_config> ]

# The port to scrape metrics from, when `role` is nodes, and for discovered
# tasks and services that don't have published ports.
[ port: <int> | default = 80 ]

# The host to use if the container is in host networking mode.
[ host_networking_host: <string> | default = "localhost" ]

# Optional filters to limit the discovery process to a subset of available
# resources.
# The available filters are listed in the upstream documentation:
# https://docs.docker.com/engine/api/v1.40/#operation/ContainerList
[ filters:
[ - name: <string>
values: <string>, [...] ]

# The time after which the containers are refreshed.
[ refresh_interval: <duration> | default = 60s ]

# Authentication information used to authenticate to the Docker daemon.
# Note that `basic_auth` and `authorization` options are
# mutually exclusive.
# password and password_file are mutually exclusive.

# Optional HTTP basic authentication information.
basic_auth:
[ username: <string> ]
[ password: <secret> ]
[ password_file: <string> ]

# Optional `Authorization` header configuration.
authorization:
# Sets the authentication type.
[ type: <string> | default: Bearer ]
# Sets the credentials. It is mutually exclusive with
# `credentials_file`.
[ credentials: <secret> ]
# Sets the credentials to the credentials read from the configured file.
# It is mutually exclusive with `credentials`.
[ credentials_file: <filename> ]

# Optional OAuth 2.0 configuration.
# Cannot be used at the same time as basic_auth or authorization.
oauth2:
[ <oauth2> ]

# Configure whether HTTP requests follow HTTP 3xx redirects.
[ follow_redirects: <boolean> | default = true ]

重新贴标签阶段是过滤容器的首选且更强大的方法。对于拥有数千个容器的用户,直接使用对过滤容器有基本支持的 Docker API 会更有效(使用filters)。

有关为 Docker 引擎配置 Prometheus 的详细示例,请参阅此示例 Prometheus 配置文件

dockerswarm_sd_config

Docker Swarm SD 配置允许从Docker Swarm 引擎检索抓取目标。

可以配置以下角色之一来发现目标:

services

该services角色发现所有Swarm 服务 并将其端口公开为目标。对于服务的每个已发布端口,都会生成一个目标。如果服务没有发布的端口,则使用portSD 配置中定义的参数为每个服务创建一个目标。

可用元标签:

  • __meta_dockerswarm_service_id: 服务的id
  • __meta_dockerswarm_service_name:服务的名称
  • __meta_dockerswarm_service_mode: 服务模式
  • __meta_dockerswarm_service_endpoint_port_name:端点端口的名称(如果可用)
  • __meta_dockerswarm_service_endpoint_port_publish_mode:端点端口的发布方式
  • _meta_dockerswarm_service_label:服务的每个标签
  • __meta_dockerswarm_service_task_container_hostname:目标的容器主机名(如果有)
  • __meta_dockerswarm_service_task_container_image: 目标的容器镜像
  • __meta_dockerswarm_service_updating_status:服务的状态,如果有的话
  • __meta_dockerswarm_network_id: 网络ID
  • __meta_dockerswarm_network_name: 网络名称
  • __meta_dockerswarm_network_ingress: 网络是否是入口
  • __meta_dockerswarm_network_internal: 网络是否为内部网络
  • _meta_dockerswarm_network_label:网络的每个标签
  • __meta_dockerswarm_network_scope: 网络范围

task

该tasks角色发现所有Swarm 任务 并将其端口公开为目标。对于任务的每个发布端口,都会生成一个目标。如果任务没有发布的端口,则使用portSD 配置中定义的参数为每个任务创建一个目标。

可用的元标签:

  • _meta_dockerswarm_container_label:容器的每个标签
  • __meta_dockerswarm_task_id: 任务id
  • __meta_dockerswarm_task_container_id:任务的容器id
  • __meta_dockerswarm_task_desired_state:任务的期望状态
  • __meta_dockerswarm_task_slot: 任务槽
  • __meta_dockerswarm_task_state: 任务状态
  • __meta_dockerswarm_task_port_publish_mode:任务端口的发布方式
  • __meta_dockerswarm_service_id: 服务的id
  • __meta_dockerswarm_service_name:服务的名称
  • __meta_dockerswarm_service_mode: 服务模式
  • _meta_dockerswarm_service_label:服务的每个标签
  • __meta_dockerswarm_network_id: 网络ID
  • __meta_dockerswarm_network_name: 网络名称
  • __meta_dockerswarm_network_ingress: 网络是否是入口
  • __meta_dockerswarm_network_internal: 网络是否为内部网络
  • _meta_dockerswarm_network_label:网络的每个标签
  • __meta_dockerswarm_network_label:网络的每个标签
  • __meta_dockerswarm_network_scope: 网络范围
  • __meta_dockerswarm_node_id: 节点ID
  • __meta_dockerswarm_node_hostname: 节点的主机名
  • __meta_dockerswarm_node_address: 节点地址
  • __meta_dockerswarm_node_availability:节点的可用性
  • _meta_dockerswarm_node_label: 节点的每个标签
  • __meta_dockerswarm_node_platform_architecture: 节点的架构
  • __meta_dockerswarm_node_platform_os:节点的操作系统
  • __meta_dockerswarm_node_role: 节点的作用
  • __meta_dockerswarm_node_status: 节点状态

不会为使用 发布的__meta_dockerswarm_network_*端口填充元标签mode=host。

nodes

该nodes角色用于发现Swarm 节点

可用的元标签:

  • __meta_dockerswarm_node_address: 节点地址
  • __meta_dockerswarm_node_availability:节点的可用性
  • __meta_dockerswarm_node_engine_version:节点引擎的版本
  • __meta_dockerswarm_node_hostname: 节点的主机名
  • __meta_dockerswarm_node_id: 节点ID
  • _meta_dockerswarm_node_label: 节点的每个标签
  • __meta_dockerswarm_node_manager_address: 节点管理器组件的地址
  • __meta_dockerswarm_node_manager_leader:节点的管理器组件的领导状态(真或假)
  • __meta_dockerswarm_node_manager_reachability: 节点管理器组件的可达性
  • __meta_dockerswarm_node_platform_architecture: 节点的架构
  • __meta_dockerswarm_node_platform_os:节点的操作系统
  • __meta_dockerswarm_node_role: 节点的作用
  • __meta_dockerswarm_node_status: 节点状态

有关 Docker Swarm 发现的配置选项,请参见下文:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Address of the Docker daemon.
host: <string>

# Optional proxy URL.
[ proxy_url: <string> ]

# TLS configuration.
tls_config:
[ <tls_config> ]

# Role of the targets to retrieve. Must be `services`, `tasks`, or `nodes`.
role: <string>

# The port to scrape metrics from, when `role` is nodes, and for discovered
# tasks and services that don't have published ports.
[ port: <int> | default = 80 ]

# Optional filters to limit the discovery process to a subset of available
# resources.
# The available filters are listed in the upstream documentation:
# Services: https://docs.docker.com/engine/api/v1.40/#operation/ServiceList
# Tasks: https://docs.docker.com/engine/api/v1.40/#operation/TaskList
# Nodes: https://docs.docker.com/engine/api/v1.40/#operation/NodeList
[ filters:
[ - name: <string>
values: <string>, [...] ]

# The time after which the service discovery data is refreshed.
[ refresh_interval: <duration> | default = 60s ]

# Authentication information used to authenticate to the Docker daemon.
# Note that `basic_auth` and `authorization` options are
# mutually exclusive.
# password and password_file are mutually exclusive.

# Optional HTTP basic authentication information.
basic_auth:
[ username: <string> ]
[ password: <secret> ]
[ password_file: <string> ]

# Optional `Authorization` header configuration.
authorization:
# Sets the authentication type.
[ type: <string> | default: Bearer ]
# Sets the credentials. It is mutually exclusive with
# `credentials_file`.
[ credentials: <secret> ]
# Sets the credentials to the credentials read from the configured file.
# It is mutually exclusive with `credentials`.
[ credentials_file: <filename> ]

# Optional OAuth 2.0 configuration.
# Cannot be used at the same time as basic_auth or authorization.
oauth2:
[ <oauth2> ]

# Configure whether HTTP requests follow HTTP 3xx redirects.
[ follow_redirects: <boolean> | default = true ]

重新标记阶段是过滤任务、服务或节点的首选且更强大的方法。对于拥有数千个任务的用户,直接使用对过滤节点有基本支持的 Swarm API 会更有效(使用filters)。

有关为 Docker Swarm 配置 Prometheus 的详细示例,请参阅此示例 Prometheus 配置文件

dns_sd_config

基于DNS的服务发现配置允许指定一组DNS域名,这些域名会定期查询以发现目标列表。 要联系的DNS服务器从/etc/resolv.conf中读取。

此服务发现方法仅支持基本的DNS AAAAASRV记录查询,但不支持RFC6763中指定的高级DNS-SD方法。

在重新标记阶段,目标上可用的元标签:

  • __meta_dns_name:产生发现目标的记录名称。
  • __meta_dns_srv_record_target: SRV 记录的目标字段
  • __meta_dns_srv_record_port: SRV 记录的端口字段
1
2
3
4
5
6
7
8
9
10
11
12
# 要查询的DNS域名列表。
names:
[ - <domain_name> ]

# 要执行的DNS查询的类型。
[ type: <query_type> | default = 'SRV' ]

# 查询类型不是SRV时使用的端口号。
[ port: <number>]

# 提供名称后刷新的时间。
[ refresh_interval: <duration> | default = 30s ]

ec2_sd_config

EC2 SD 配置允许从 AWS EC2 实例中检索抓取目标。默认使用私有 IP 地址,但可以通过重新标记更改为公共 IP 地址。

在重新标记期间,目标上可以使用以下元标签

  • __meta_ec2_ami:EC2 亚马逊系统映像
  • __meta_ec2_architecture: 实例的架构
  • __meta_ec2_availability_zone:实例运行所在的可用区
  • __meta_ec2_availability_zone_id:实例运行所在的可用区ID(需要ec2:DescribeAvailabilityZones)
  • __meta_ec2_instance_id: EC2 实例 ID
  • __meta_ec2_instance_lifecycle: EC2 实例的生命周期,仅针对 ‘spot’ 或 ‘scheduled’ 实例设置,否则不存在
  • __meta_ec2_instance_state: EC2 实例的状态
  • __meta_ec2_instance_type: EC2 实例的类型
  • __meta_ec2_ipv6_addresses:分配给实例网络接口的 IPv6 地址的逗号分隔列表(如果存在)
  • __meta_ec2_owner_id:拥有 EC2 实例的 AWS 账户的 ID
  • __meta_ec2_platform:操作系统平台,在 Windows 服务器上设置为“windows”,否则不存在
  • __meta_ec2_primary_subnet_id:主网络接口的子网 ID(如果可用)
  • __meta_ec2_private_dns_name:实例的私有 DNS 名称(如果可用)
  • __meta_ec2_private_ip:实例的私有 IP 地址(如果存在)
  • __meta_ec2_public_dns_name:实例的公共 DNS 名称(如果可用)
  • __meta_ec2_public_ip:实例的公共 IP 地址(如果有)
  • __meta_ec2_subnet_id:实例运行所在的子网 ID 的逗号分隔列表(如果可用)
  • _meta_ec2_tag: 实例的每个标签值
  • __meta_ec2_vpc_id:运行实例的 VPC 的 ID(如果可用)

有关 EC2 发现的配置选项,请参见下文:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# The information to access the EC2 API.

# The AWS region. If blank, the region from the instance metadata is used.
[ region: <string> ]

# Custom endpoint to be used.
[ endpoint: <string> ]

# The AWS API keys. If blank, the environment variables `AWS_ACCESS_KEY_ID`
# and `AWS_SECRET_ACCESS_KEY` are used.
[ access_key: <string> ]
[ secret_key: <secret> ]
# Named AWS profile used to connect to the API.
[ profile: <string> ]

# AWS Role ARN, an alternative to using AWS API keys.
[ role_arn: <string> ]

# Refresh interval to re-read the instance list.
[ refresh_interval: <duration> | default = 60s ]

# The port to scrape metrics from. If using the public IP address, this must
# instead be specified in the relabeling rule.
[ port: <int> | default = 80 ]

# Filters can be used optionally to filter the instance list by other criteria.
# Available filter criteria can be found here:
# https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeInstances.html
# Filter API documentation: https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_Filter.html
filters:
[ - name: <string>
values: <string>, [...] ]

重新标记阶段是基于任意标签过滤目标的首选且更强大的方法。对于拥有数千个实例的用户,直接使用支持过滤实例的 EC2 API 会更有效。

openstack_sd_config

OpenStack SD 配置允许从 OpenStack Nova 实例中检索抓取目标。

可以配置以下类型之一来发现目标:

hypervisor

该hypervisor角色为每个 Nova 管理程序节点发现一个目标。目标地址默认为host_ip管理程序的属性。

在重新标记期间,目标上可以使用以下元标签

  • __meta_openstack_hypervisor_host_ip:管理程序节点的 IP 地址。
  • __meta_openstack_hypervisor_hostname:管理程序节点的名称。
  • __meta_openstack_hypervisor_id:管理程序节点的 ID。
  • __meta_openstack_hypervisor_state:管理程序节点的状态。
  • __meta_openstack_hypervisor_status:管理程序节点的状态。
  • __meta_openstack_hypervisor_type:管理程序节点的类型。

instance

该instance角色为 Nova 实例的每个网络接口发现一个目标。目标地址默认为网络接口的私有 IP 地址。

在重新标记期间,目标上可以使用以下元标签

  • __meta_openstack_address_pool:私有IP的池。
  • __meta_openstack_instance_flavor: OpenStack 实例的味道。
  • __meta_openstack_instance_id:OpenStack 实例 ID。
  • __meta_openstack_instance_name:OpenStack 实例名称。
  • __meta_openstack_instance_status:OpenStack 实例的状态。
  • __meta_openstack_private_ip:OpenStack 实例的私有 IP。
  • __meta_openstack_project_id:拥有此实例的项目(租户)。
  • __meta_openstack_public_ip:OpenStack实例的公网IP。
  • _meta_openstack_tag:实例的每个标签值。
  • __meta_openstack_user_id:拥有租户的用户帐户。

有关 OpenStack 发现的配置选项,请参见下文:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# The information to access the OpenStack API.

# The OpenStack role of entities that should be discovered.
role: <openstack_role>

# The OpenStack Region.
region: <string>

# identity_endpoint specifies the HTTP endpoint that is required to work with
# the Identity API of the appropriate version. While it's ultimately needed by
# all of the identity services, it will often be populated by a provider-level
# function.
[ identity_endpoint: <string> ]

# username is required if using Identity V2 API. Consult with your provider's
# control panel to discover your account's username. In Identity V3, either
# userid or a combination of username and domain_id or domain_name are needed.
[ username: <string> ]
[ userid: <string> ]

# password for the Identity V2 and V3 APIs. Consult with your provider's
# control panel to discover your account's preferred method of authentication.
[ password: <secret> ]

# At most one of domain_id and domain_name must be provided if using username
# with Identity V3. Otherwise, either are optional.
[ domain_name: <string> ]
[ domain_id: <string> ]

# The project_id and project_name fields are optional for the Identity V2 API.
# Some providers allow you to specify a project_name instead of the project_id.
# Some require both. Your provider's authentication policies will determine
# how these fields influence authentication.
[ project_name: <string> ]
[ project_id: <string> ]

# The application_credential_id or application_credential_name fields are
# required if using an application credential to authenticate. Some providers
# allow you to create an application credential to authenticate rather than a
# password.
[ application_credential_name: <string> ]
[ application_credential_id: <string> ]

# The application_credential_secret field is required if using an application
# credential to authenticate.
[ application_credential_secret: <secret> ]

# Whether the service discovery should list all instances for all projects.
# It is only relevant for the 'instance' role and usually requires admin permissions.
[ all_tenants: <boolean> | default: false ]

# Refresh interval to re-read the instance list.
[ refresh_interval: <duration> | default = 60s ]

# The port to scrape metrics from. If using the public IP address, this must
# instead be specified in the relabeling rule.
[ port: <int> | default = 80 ]

# The availability of the endpoint to connect to. Must be one of public, admin or internal.
[ availability: <string> | default = "public" ]

# TLS configuration.
tls_config:
[ <tls_config> ]

puppetdb_sd_config

PuppetDB SD 配置允许从 PuppetDB资源中检索抓取目标。

此 SD 发现资源并将为 API 返回的每个资源创建一个目标。

资源地址是资源的地址certname,可以在 重新标记期间更改。

在重新标记期间,目标上可以使用以下元标签

  • __meta_puppetdb_certname:与资源关联的节点的名称
  • __meta_puppetdb_resource:资源类型、标题和参数的 SHA-1 哈希,用于标识
  • __meta_puppetdb_type: 资源类型
  • __meta_puppetdb_title: 资源标题
  • __meta_puppetdb_exported: 资源是否被导出 (“true”或”false”)
  • __meta_puppetdb_tags: 逗号分隔的资源标签列表
  • __meta_puppetdb_file: 声明资源的清单文件
  • __meta_puppetdb_environment:与资源关联的节点的环境
  • _meta_puppetdb_parameter: 资源的参数

有关 PuppetDB 发现的配置选项,请参见下文:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# The URL of the PuppetDB root query endpoint.
url: <string>

# Puppet Query Language (PQL) query. Only resources are supported.
# https://puppet.com/docs/puppetdb/latest/api/query/v4/pql.html
query: <string>

# Whether to include the parameters as meta labels.
# Due to the differences between parameter types and Prometheus labels,
# some parameters might not be rendered. The format of the parameters might
# also change in future releases.
#
# Note: Enabling this exposes parameters in the Prometheus UI and API. Make sure
# that you don't have secrets exposed as parameters if you enable this.
[ include_parameters: <boolean> | default = false ]

# Refresh interval to re-read the resources list.
[ refresh_interval: <duration> | default = 60s ]

# The port to scrape metrics from.
[ port: <int> | default = 80 ]

# TLS configuration to connect to the PuppetDB.
tls_config:
[ <tls_config> ]

# basic_auth, authorization, and oauth2, are mutually exclusive.

# Optional HTTP basic authentication information.
basic_auth:
[ username: <string> ]
[ password: <secret> ]
[ password_file: <string> ]

# `Authorization` HTTP header configuration.
authorization:
# Sets the authentication type.
[ type: <string> | default: Bearer ]
# Sets the credentials. It is mutually exclusive with
# `credentials_file`.
[ credentials: <secret> ]
# Sets the credentials with the credentials read from the configured file.
# It is mutually exclusive with `credentials`.
[ credentials_file: <filename> ]

# Optional OAuth 2.0 configuration.
# Cannot be used at the same time as basic_auth or authorization.
oauth2:
[ <oauth2> ]

# Optional proxy URL.
[ proxy_url: <string> ]

# Configure whether HTTP requests follow HTTP 3xx redirects.
[ follow_redirects: <boolean> | default = true ]

有关使用 PuppetDB 配置 Prometheus 的详细示例,请参阅此示例 Prometheus 配置文件

file_sd_config

基于文件的服务发现提供了一种更通用的方式来配置静态目标并用作插入自定义服务发现机制的接口。

它读取一组包含零个或多个 s 列表的文件。通过磁盘监视检测所有定义文件的更改并立即应用。文件可能以 YAML 或 JSON 格式提供。仅应用导致结构良好的目标组的更改。

文件必须包含静态配置列表,使用以下格式:

JSON json [ { “targets”: [ ““, … ], “labels”: { ““: ““, … } }, … ]

YAML yaml - targets: [ - ‘‘ ] labels: [ : … ]

作为回退,文件内容也会以指定的刷新间隔定期重新读取。

每个目标__meta_filepath在 重新标记阶段都有一个元标签。它的值设置为从中提取目标的文件路径。

有一个 与此发现机制的集成列表。

1
2
3
4
5
6
# Patterns for files from which target groups are extracted.
files:
[ - <filename_pattern> ... ]

# Refresh interval to re-read the files.
[ refresh_interval: <duration> | default = 5m ]

其中可能是以.json,.yml或结尾的路径.yaml。最后一个路径段可能包含一个匹配任何字符序列的单个,例如my/path/tg_.json.

gce_sd_config

GCE SD 配置允许从 GCP GCE 实例中检索抓取目标。默认使用私有 IP 地址,但可以通过重新标记更改为公共 IP 地址。

在重新标记期间,目标上可以使用以下元标签

  • __meta_gce_instance_id: 实例的数字 id
  • __meta_gce_instance_name: 实例名称
  • _meta_gce_label: 实例的每个 GCE 标签
  • __meta_gce_machine_type: 实例机器类型的完整或部分 URL
  • _meta_gce_metadata:实例的每个元数据项
  • __meta_gce_network: 实例的网络 URL
  • __meta_gce_private_ip:实例的私有IP地址
  • _meta_gce_interface_ipv4: 每个命名接口的 IPv4 地址
  • __meta_gce_project: 实例运行所在的 GCP 项目
  • __meta_gce_public_ip:实例的公共 IP 地址(如果存在)
  • __meta_gce_subnetwork: 实例的子网 URL
  • __meta_gce_tags: 逗号分隔的实例标签列表
  • __meta_gce_zone:运行实例的 GCE 区域 URL

有关 GCE 发现的配置选项,请参见下文:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# The information to access the GCE API.

# The GCP Project
project: <string>

# The zone of the scrape targets. If you need multiple zones use multiple
# gce_sd_configs.
zone: <string>

# Filter can be used optionally to filter the instance list by other criteria
# Syntax of this filter string is described here in the filter query parameter section:
# https://cloud.google.com/compute/docs/reference/latest/instances/list
[ filter: <string> ]

# Refresh interval to re-read the instance list
[ refresh_interval: <duration> | default = 60s ]

# The port to scrape metrics from. If using the public IP address, this must
# instead be specified in the relabeling rule.
[ port: <int> | default = 80 ]

# The tag separator is used to separate the tags on concatenation
[ tag_separator: <string> | default = , ]

Google Cloud SDK 默认客户端通过查看以下位置(首选找到的第一个位置)来发现凭据:

  1. GOOGLE_APPLICATION_CREDENTIALS由环境变量指定的 JSON 文件
  2. 已知路径中的 JSON 文件$HOME/.config/gcloud/application_default_credentials.json
  3. 从 GCE 元数据服务器获取

如果 Prometheus 在 GCE 中运行,则与其运行的实例关联的服务帐户应至少对计算资源具有只读权限。如果在 GCE 之外运行,请确保创建适当的服务帐户并将凭证文件放在预期的位置之一。

hetzner_sd_config

Hetzner SD 配置允许从 HetznerCloud API 和 Robot API 检索抓取目标。此服务发现默认使用公共 IPv4 地址,但可以通过重新标记来更改,如Prometheus hetzner-sd 配置文件中所示。

在重新标记期间,所有目标都可以使用以下元标签

  • __meta_hetzner_server_id: 服务器的ID
  • __meta_hetzner_server_name: 服务器的名字
  • __meta_hetzner_server_status: 服务器的状态
  • __meta_hetzner_public_ipv4:服务器的公共ipv4地址
  • __meta_hetzner_public_ipv6_network: 服务器的公共 ipv6 网络 (/64)
  • __meta_hetzner_datacenter:服务器的数据中心

以下标签仅适用于role设置为 的目标hcloud:

  • _meta_hetzner_hcloud_image_name: 服务器的镜像名称
  • __meta_hetzner_hcloud_image_description: 服务器镜像的描述
  • __meta_hetzner_hcloud_image_os_flavor: 服务器镜像的操作系统风格
  • __meta_hetzner_hcloud_image_os_version: 服务器镜像的操作系统版本
  • __meta_hetzner_hcloud_image_description: 服务器镜像的描述
  • __meta_hetzner_hcloud_datacenter_location: 服务器的位置
  • __meta_hetzner_hcloud_datacenter_location_network_zone: 服务器的网络区域
  • __meta_hetzner_hcloud_server_type: 服务器的类型
  • __meta_hetzner_hcloud_cpu_cores: 服务器的 CPU 核心数
  • __meta_hetzner_hcloud_cpu_type: 服务器的 CPU 类型(共享或专用)
  • __meta_hetzner_hcloud_memory_size_gb: 服务器的内存量(GB)
  • __meta_hetzner_hcloud_disk_size_gb: 服务器的磁盘大小(以 GB 为单位)
  • _meta_hetzner_hcloud_private_ipv4:给定网络中服务器的私有 ipv4 地址
  • _meta_hetzner_hcloud_label: 服务器的每个标签
  • _meta_hetzner_hcloud_labelpresent:true对于服务器的每个标签

以下标签仅适用于role设置为 的目标robot:

  • __meta_hetzner_robot_product: 服务器的产品
  • __meta_hetzner_robot_cancelled:服务器取消状态
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# The Hetzner role of entities that should be discovered.
# One of robot or hcloud.
role: <string>

# Authentication information used to authenticate to the API server.
# Note that `basic_auth` and `authorization` options are
# mutually exclusive.
# password and password_file are mutually exclusive.

# Optional HTTP basic authentication information, required when role is robot
# Role hcloud does not support basic auth.
basic_auth:
[ username: <string> ]
[ password: <secret> ]
[ password_file: <string> ]

# Optional `Authorization` header configuration, required when role is
# hcloud. Role robot does not support bearer token authentication.
authorization:
# Sets the authentication type.
[ type: <string> | default: Bearer ]
# Sets the credentials. It is mutually exclusive with
# `credentials_file`.
[ credentials: <secret> ]
# Sets the credentials to the credentials read from the configured file.
# It is mutually exclusive with `credentials`.
[ credentials_file: <filename> ]

# Optional OAuth 2.0 configuration.
# Cannot be used at the same time as basic_auth or authorization.
oauth2:
[ <oauth2> ]

# Optional proxy URL.
[ proxy_url: <string> ]

# Configure whether HTTP requests follow HTTP 3xx redirects.
[ follow_redirects: <boolean> | default = true ]

# TLS configuration.
tls_config:
[ <tls_config> ]

# The port to scrape metrics from.
[ port: <int> | default = 80 ]

# The time after which the servers are refreshed.
[ refresh_interval: <duration> | default = 60s ]

http_sd_config

基于 HTTP 的服务发现提供了一种更通用的方式来配置静态目标,并用作插入自定义服务发现机制的接口。

它从包含零个或多个s列表的 HTTP 端点获取目标 。目标必须回复 HTTP 200 响应。HTTP 标头Content-Type必须是application/json,并且正文必须是有效的 JSON。

示例响应正文:

1
2
3
4
5
6
7
8
9
[
{
"targets": [ "<host>", ... ],
"labels": {
"<labelname>": "<labelvalue>", ...
}
},
...
]

以指定的刷新间隔定期查询端点。计数器指标跟踪刷新失败的prometheus_sd_http_failures_total次数。

每个目标__meta_url在 重新标记阶段都有一个元标签。它的值设置为从中提取目标的 URL。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# URL from which the targets are fetched.
url: <string>

# Refresh interval to re-query the endpoint.
[ refresh_interval: <duration> | default = 60s ]

# Authentication information used to authenticate to the API server.
# Note that `basic_auth`, `authorization` and `oauth2` options are
# mutually exclusive.
# `password` and `password_file` are mutually exclusive.

# Optional HTTP basic authentication information.
basic_auth:
[ username: <string> ]
[ password: <secret> ]
[ password_file: <string> ]

# Optional `Authorization` header configuration.
authorization:
# Sets the authentication type.
[ type: <string> | default: Bearer ]
# Sets the credentials. It is mutually exclusive with
# `credentials_file`.
[ credentials: <secret> ]
# Sets the credentials to the credentials read from the configured file.
# It is mutually exclusive with `credentials`.
[ credentials_file: <filename> ]

# Optional OAuth 2.0 configuration.
oauth2:
[ <oauth2> ]

# Optional proxy URL.
[ proxy_url: <string> ]

# Configure whether HTTP requests follow HTTP 3xx redirects.
[ follow_redirects: <boolean> | default = true ]

# TLS configuration.
tls_config:
[ <tls_config> ]

kubernetes_sd_config

Kubernetes SD配置允许从KubernetesRESTAPI中检索scrape目标,并始终与集群状态保持同步。

可以配置一下role类型之一来发现目标。

node

node角色发现每个群集节点有一个目标,其地址默认为KubeletHTTP端口。 目标地址默认为NodeInternalIPNodeExternalIPNodeLegacyHostIPNodeHostName的地址类型顺序中Kubernetes节点对象的第一个现有地址。

可用元标签:

  • __meta_kubernetes_node_name:节点对象的名称。

  • __meta_kubernetes_node_label_ <labelname>:节点对象中的每个标签。

  • _*meta_kubernetes_node_annotation*<annotationname>:节点对象中的每个注释。

  • __meta_kubernetes_node_address_<address_type>:每个节点地址类型的第一个地址(如果存在)。

此外,instance节点的标签将设置为从 API 服务器检索到的节点名称。

service

service角色为每个服务发现每个服务端口的目标。 这对于服务的黑盒监控通常很有用。 该地址将设置为服务的Kubernetes DNS名称和相应的服务端口。

可用元标签:

  • __meta_kubernetes_namespace:服务对象的命名空间。
  • __meta_kubernetes_service_annotation_<annotationname>:服务对象的注释。
  • __meta_kubernetes_service_cluster_ip:服务的群集IP地址。 (不适用于ExternalName类型的服务)
  • __meta_kubernetes_service_external_name:服务的DNS名称。 (适用于ExternalName类型的服务)
  • __meta_kubernetes_service_label_ <labelname>:服务对象的标签。
  • __meta_kubernetes_service_name:服务对象的名称。
  • __meta_kubernetes_service_port_name:目标服务端口的名称。
  • __meta_kubernetes_service_port_number:目标的服务端口号。
  • __meta_kubernetes_service_port_protocol:目标服务端口的协议。

pod

该pod角色发现所有 pod 并将其容器公开为目标。对于容器的每个声明的端口,都会生成一个目标。如果容器没有指定端口,则会为每个容器创建一个无端口目标,以便通过重新标记手动添加端口。

可用的元标签:

  • __meta_kubernetes_namespace: pod 对象的命名空间。
  • __meta_kubernetes_pod_name: pod 对象的名称。
  • __meta_kubernetes_pod_ip: pod 对象的 pod IP。
  • _meta_kubernetes_pod_label: 来自 pod 对象的每个标签。
  • _meta_kubernetes_pod_labelpresent:true对于来自 pod 对象的每个标签。
  • _meta_kubernetes_pod_annotation:来自 pod 对象的每个注释。
  • _meta_kubernetes_pod_annotationpresent:true对于来自 pod 对象的每个注释。
  • __meta_kubernetes_pod_container_init:true如果容器是InitContainer
  • __meta_kubernetes_pod_container_name: 目标地址指向的容器名称。
  • __meta_kubernetes_pod_container_port_name: 集装箱港口名称。
  • __meta_kubernetes_pod_container_port_number: 容器端口号。
  • __meta_kubernetes_pod_container_port_protocol:容器端口的协议。
  • __meta_kubernetes_pod_ready:设置为true或false为 pod 的就绪状态。
  • __meta_kubernetes_pod_phase: 设置为Pending, Running, Succeeded,Failed或Unknown 在生命周期中。
  • __meta_kubernetes_pod_node_name: pod 被调度到的节点的名称。
  • __meta_kubernetes_pod_host_ip: pod 对象的当前主机 IP。
  • __meta_kubernetes_pod_uid: pod 对象的 UID。
  • __meta_kubernetes_pod_controller_kind: pod 控制器的对象类型。
  • __meta_kubernetes_pod_controller_name: pod 控制器的名称。

endpoints

该endpoints角色从列出的服务端点发现目标。对于每个端点地址,每个端口都会发现一个目标。如果端点由 pod 支持,则该 pod 的所有其他容器端口(未绑定到端点端口)也会被发现为目标。

可用的元标签:

  • __meta_kubernetes_namespace:端点对象的命名空间。

  • __meta_kubernetes_endpoints_name:端点对象的名称。

  • 对于直接从端点列表中发现的所有目标(未从底层 pod 额外推断的目标),附加以下标签:

    • __meta_kubernetes_endpoint_hostname:端点的主机名。
    • __meta_kubernetes_endpoint_node_name:托管端点的节点的名称。
    • __meta_kubernetes_endpoint_ready: 设置为true或false为端点的就绪状态。
    • __meta_kubernetes_endpoint_port_name:端点端口的名称。
    • __meta_kubernetes_endpoint_port_protocol:端点端口的协议。
    • __meta_kubernetes_endpoint_address_target_kind:端点地址目标的种类。
    • __meta_kubernetes_endpoint_address_target_name:端点地址目标的名称。
  • 如果端点属于服务,role: service则附加发现的所有标签。

  • 对于 pod 支持的所有目标,role: pod附加发现的所有标签。

endpointslice

该endpointslice角色从现有端点片中发现目标。对于 endpointslice 对象中引用的每个端点地址,都会发现一个目标。如果端点由 pod 支持,则该 pod 的所有其他容器端口(未绑定到端点端口)也会被发现为目标。

可用的元标签:

  • __meta_kubernetes_namespace:端点对象的命名空间。

  • __meta_kubernetes_endpointslice_name:端点切片对象的名称。

  • 对于直接从 endpointslice 列表中发现的所有目标(那些不是从底层 pod 额外推断的目标),附加以下标签:

    • __meta_kubernetes_endpointslice_address_target_kind: 被引用对象的种类。
    • __meta_kubernetes_endpointslice_address_target_name: 引用对象的名称。
    • __meta_kubernetes_endpointslice_address_type:目标地址的ip协议族。
    • __meta_kubernetes_endpointslice_endpoint_conditions_ready:设置为true或false为引用端点的就绪状态。
    • __meta_kubernetes_endpointslice_endpoint_topology_kubernetes_io_hostname:托管引用端点的节点的名称。
    • __meta_kubernetes_endpointslice_endpoint_topology_present_kubernetes_io_hostname: 显示被引用对象是否有 kubernetes.io/hostname 注释的标志。
    • __meta_kubernetes_endpointslice_port: 引用端点的端口。
    • __meta_kubernetes_endpointslice_port_name:被引用端点的命名端口。
    • __meta_kubernetes_endpointslice_port_protocol: 引用端点的协议。
  • 如果端点属于服务,role: service则附加发现的所有标签。

  • 对于 pod 支持的所有目标,role: pod附加发现的所有标签。

ingress

该ingress角色为每个入口的每个路径发现一个目标。这对于入口的黑盒监控通常很有用。该地址将设置为入口规范中指定的主机。

可用的元标签:

  • __meta_kubernetes_namespace:入口对象的命名空间。
  • __meta_kubernetes_ingress_name:入口对象的名称。
  • _meta_kubernetes_ingress_label:来自入口对象的每个标签。
  • _meta_kubernetes_ingress_labelpresent:true对于来自入口对象的每个标签。
  • _meta_kubernetes_ingress_annotation:来自入口对象的每个注释。
  • _meta_kubernetes_ingress_annotationpresent:true对于来自入口对象的每个注释。
  • __meta_kubernetes_ingress_class_name:来自入口规范的类名(如果存在)。
  • __meta_kubernetes_ingress_scheme:入口的协议方案,https如果设置了 TLS 配置。默认为http.
  • __meta_kubernetes_ingress_path:来自入口规范的路径。默认为/.

有关 Kubernetes 发现的配置选项,请参见下文:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# The information to access the Kubernetes API.

# The API server addresses. If left empty, Prometheus is assumed to run inside
# of the cluster and will discover API servers automatically and use the pod's
# CA certificate and bearer token file at /var/run/secrets/kubernetes.io/serviceaccount/.
[ api_server: <host> ]

# The Kubernetes role of entities that should be discovered.
# One of endpoints, endpointslice, service, pod, node, or ingress.
role: <string>

# Optional path to a kubeconfig file.
# Note that api_server and kube_config are mutually exclusive.
[ kubeconfig_file: <filename> ]

# Optional authentication information used to authenticate to the API server.
# Note that `basic_auth` and `authorization` options are mutually exclusive.
# password and password_file are mutually exclusive.

# Optional HTTP basic authentication information.
basic_auth:
[ username: <string> ]
[ password: <secret> ]
[ password_file: <string> ]

# Optional `Authorization` header configuration.
authorization:
# Sets the authentication type.
[ type: <string> | default: Bearer ]
# Sets the credentials. It is mutually exclusive with
# `credentials_file`.
[ credentials: <secret> ]
# Sets the credentials to the credentials read from the configured file.
# It is mutually exclusive with `credentials`.
[ credentials_file: <filename> ]

# Optional OAuth 2.0 configuration.
# Cannot be used at the same time as basic_auth or authorization.
oauth2:
[ <oauth2> ]

# Optional proxy URL.
[ proxy_url: <string> ]

# Configure whether HTTP requests follow HTTP 3xx redirects.
[ follow_redirects: <boolean> | default = true ]

# TLS configuration.
tls_config:
[ <tls_config> ]

# Optional namespace discovery. If omitted, all namespaces are used.
namespaces:
own_namespace: <boolean>
names:
[ - <string> ]

# Optional label and field selectors to limit the discovery process to a subset of available resources.
# See https://kubernetes.io/docs/concepts/overview/working-with-objects/field-selectors/
# and https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ to learn more about the possible
# filters that can be used. Endpoints role supports pod, service and endpoints selectors, other roles
# only support selectors matching the role itself (e.g. node role can only contain node selectors).

# Note: When making decision about using field/label selector make sure that this
# is the best approach - it will prevent Prometheus from reusing single list/watch
# for all scrape configs. This might result in a bigger load on the Kubernetes API,
# because per each selector combination there will be additional LIST/WATCH. On the other hand,
# if you just want to monitor small subset of pods in large cluster it's recommended to use selectors.
# Decision, if selectors should be used or not depends on the particular situation.
[ selectors:
[ - role: <string>
[ label: <string> ]
[ field: <string> ] ]]

有关为 Kubernetes 配置 Prometheus 的详细示例,请参阅此示例 Prometheus 配置文件。

您可能希望查看第 3 方Prometheus Operator,它可以在 Kubernetes 之上自动设置 Prometheus。

kuma_sd_config

Kuma SD 配置允许从Kuma控制平面检索抓取目标。

此 SD 通过 MADS v1(监控分配发现服务)xDS API 基于 Kuma Dataplane Proxies发现“监控分配” ,并将为启用 Prometheus 的网格内的每个代理创建一个目标。

以下元标签可用于每个目标:

  • __meta_kuma_mesh: 代理的Mesh名称
  • __meta_kuma_dataplane: 代理的名字
  • __meta_kuma_service:代理的关联服务的名称
  • _meta_kuma_label: 代理的每个标签

有关 Kuma MonitoringAssignment 发现的配置选项,请参见下文:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Address of the Kuma Control Plane's MADS xDS server.
server: <string>

# The time to wait between polling update requests.
[ refresh_interval: <duration> | default = 30s ]

# The time after which the monitoring assignments are refreshed.
[ fetch_timeout: <duration> | default = 2m ]

# Optional proxy URL.
[ proxy_url: <string> ]

# TLS configuration.
tls_config:
[ <tls_config> ]

# Authentication information used to authenticate to the Docker daemon.
# Note that `basic_auth` and `authorization` options are
# mutually exclusive.
# password and password_file are mutually exclusive.

# Optional HTTP basic authentication information.
basic_auth:
[ username: <string> ]
[ password: <secret> ]
[ password_file: <string> ]

# Optional the `Authorization` header configuration.
authorization:
# Sets the authentication type.
[ type: <string> | default: Bearer ]
# Sets the credentials. It is mutually exclusive with
# `credentials_file`.
[ credentials: <secret> ]
# Sets the credentials with the credentials read from the configured file.
# It is mutually exclusive with `credentials`.
[ credentials_file: <filename> ]

# Optional OAuth 2.0 configuration.
# Cannot be used at the same time as basic_auth or authorization.
oauth2:
[ <oauth2> ]

# Configure whether HTTP requests follow HTTP 3xx redirects.
[ follow_redirects: <boolean> | default = true ]

重新标记阶段是过滤代理和用户定义标签的首选且更强大的方法。

lightsail_sd_config

Lightsail SD 配置允许从AWS Lightsail 实例中检索抓取目标。默认使用私有 IP 地址,但可以通过重新标记更改为公共 IP 地址。

在重新标记期间,目标上可以使用以下元标签

  • __meta_lightsail_availability_zone:实例运行所在的可用区
  • __meta_lightsail_blueprint_id:Lightsail 蓝图 ID
  • __meta_lightsail_bundle_id:Lightsail 捆绑包 ID
  • __meta_lightsail_instance_name:Lightsail 实例的名称
  • __meta_lightsail_instance_state:Lightsail 实例的状态
  • __meta_lightsail_instance_support_code:Lightsail 实例的支持代码
  • __meta_lightsail_ipv6_addresses:分配给实例网络接口的 IPv6 地址的逗号分隔列表(如果存在)
  • __meta_lightsail_private_ip:实例的私有IP地址
  • __meta_lightsail_public_ip:实例的公共 IP 地址(如果有)
  • _meta_lightsail_tag: 实例的每个标签值

有关 Lightsail 发现的配置选项,请参见下文:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# The information to access the Lightsail API.

# The AWS region. If blank, the region from the instance metadata is used.
[ region: <string> ]

# Custom endpoint to be used.
[ endpoint: <string> ]

# The AWS API keys. If blank, the environment variables `AWS_ACCESS_KEY_ID`
# and `AWS_SECRET_ACCESS_KEY` are used.
[ access_key: <string> ]
[ secret_key: <secret> ]
# Named AWS profile used to connect to the API.
[ profile: <string> ]

# AWS Role ARN, an alternative to using AWS API keys.
[ role_arn: <string> ]

# Refresh interval to re-read the instance list.
[ refresh_interval: <duration> | default = 60s ]

# The port to scrape metrics from. If using the public IP address, this must
# instead be specified in the relabeling rule.
[ port: <int> | default = 80 ]

linode_sd_config

Linode SD 配置允许从Linode 的 Linode APIv4 检索抓取目标。此服务发现默认使用公共 IPv4 地址,可以通过重新标记来更改该地址,如Prometheus linode-sd 配置文件中所示。

在重新标记期间,目标上可以使用以下元标签

  • __meta_linode_instance_id: linode 实例的 id
  • __meta_linode_instance_label: linode 实例的标签
  • __meta_linode_image: linode 实例图像的 slug
  • __meta_linode_private_ipv4: linode 实例的私有 IPv4
  • __meta_linode_public_ipv4: linode 实例的公有 IPv4
  • __meta_linode_public_ipv6: linode 实例的公有 IPv6
  • __meta_linode_region: linode 实例的区域
  • __meta_linode_type: linode 实例的类型
  • __meta_linode_status: linode 实例的状态
  • __meta_linode_tags: 由标签分隔符连接的 linode 实例的标签列表
  • __meta_linode_group: linode 实例所属的显示组
  • __meta_linode_hypervisor:为 linode 实例提供支持的虚拟化软件
  • __meta_linode_backups:linode实例的备份服务状态
  • __meta_linode_specs_disk_bytes: linode 实例可以访问的存储空间量
  • __meta_linode_specs_memory_bytes: linode 实例可以访问的 RAM 量
  • __meta_linode_specs_vcpus: 这个 linode 可以访问的 VCPU 数量
  • __meta_linode_specs_transfer_bytes:每月分配给linode实例的网络传输量
  • __meta_linode_extra_ips:分配给由标签分隔符连接的linode实例的所有额外IPv4地址的列表
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Authentication information used to authenticate to the API server.
# Note that `basic_auth` and `authorization` options are
# mutually exclusive.
# password and password_file are mutually exclusive.
# Note: Linode APIv4 Token must be created with scopes: 'linodes:read_only', 'ips:read_only', and 'events:read_only'

# Optional HTTP basic authentication information, not currently supported by Linode APIv4.
basic_auth:
[ username: <string> ]
[ password: <secret> ]
[ password_file: <string> ]

# Optional the `Authorization` header configuration.
authorization:
# Sets the authentication type.
[ type: <string> | default: Bearer ]
# Sets the credentials. It is mutually exclusive with
# `credentials_file`.
[ credentials: <secret> ]
# Sets the credentials with the credentials read from the configured file.
# It is mutually exclusive with `credentials`.
[ credentials_file: <filename> ]

# Optional OAuth 2.0 configuration.
# Cannot be used at the same time as basic_auth or authorization.
oauth2:
[ <oauth2> ]

# Optional proxy URL.
[ proxy_url: <string> ]

# Configure whether HTTP requests follow HTTP 3xx redirects.
[ follow_redirects: <boolean> | default = true ]

# TLS configuration.
tls_config:
[ <tls_config> ]

# The port to scrape metrics from.
[ port: <int> | default = 80 ]

# The string by which Linode Instance tags are joined into the tag label.
[ tag_separator: <string> | default = , ]

# The time after which the linode instances are refreshed.
[ refresh_interval: <duration> | default = 60s ]

marathon_sd_config

Marathon SD 配置允许使用Marathon REST API检索抓取目标 。Prometheus 将定期检查 REST 端点以查找当前正在运行的任务,并为每个至少有一个健康任务的应用程序创建一个目标组。

在重新标记期间,目标上可以使用以下元标签

  • __meta_marathon_app:应用程序的名称(斜线替换为破折号)
  • __meta_marathon_image: 使用的 Docker 镜像的名称(如果可用)
  • __meta_marathon_task: Mesos 任务的 ID
  • _meta_marathon_app_label:附加到应用程序的任何马拉松标签
  • _meta_marathon_port_definition_label:端口定义标签
  • _meta_marathon_port_mapping_label:端口映射标签
  • __meta_marathon_port_index: 端口索引号(例如1for PORT1)

有关 Marathon 发现的配置选项,请参见下文:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# List of URLs to be used to contact Marathon servers.
# You need to provide at least one server URL.
servers:
- <string>

# Polling interval
[ refresh_interval: <duration> | default = 30s ]

# Optional authentication information for token-based authentication
# https://docs.mesosphere.com/1.11/security/ent/iam-api/#passing-an-authentication-token
# It is mutually exclusive with `auth_token_file` and other authentication mechanisms.
[ auth_token: <secret> ]

# Optional authentication information for token-based authentication
# https://docs.mesosphere.com/1.11/security/ent/iam-api/#passing-an-authentication-token
# It is mutually exclusive with `auth_token` and other authentication mechanisms.
[ auth_token_file: <filename> ]

# Sets the `Authorization` header on every request with the
# configured username and password.
# This is mutually exclusive with other authentication mechanisms.
# password and password_file are mutually exclusive.
basic_auth:
[ username: <string> ]
[ password: <secret> ]
[ password_file: <string> ]

# Optional `Authorization` header configuration.
# NOTE: The current version of DC/OS marathon (v1.11.0) does not support
# standard `Authentication` header, use `auth_token` or `auth_token_file`
# instead.
authorization:
# Sets the authentication type.
[ type: <string> | default: Bearer ]
# Sets the credentials. It is mutually exclusive with
# `credentials_file`.
[ credentials: <secret> ]
# Sets the credentials to the credentials read from the configured file.
# It is mutually exclusive with `credentials`.
[ credentials_file: <filename> ]

# Optional OAuth 2.0 configuration.
# Cannot be used at the same time as basic_auth or authorization.
oauth2:
[ <oauth2> ]

# Configure whether HTTP requests follow HTTP 3xx redirects.
[ follow_redirects: <boolean> | default = true ]

# TLS configuration for connecting to marathon servers
tls_config:
[ <tls_config> ]

# Optional proxy URL.
[ proxy_url: <string> ]

默认情况下,Prometheus 会抓取 Marathon 中列出的每个应用程序。如果不是所有服务都提供 Prometheus 指标,您可以使用 Marathon 标签和 Prometheus 重新标记来控制哪些实例将被实际抓取。 有关如何设置 Marathon 应用程序和 Prometheus 配置的实际示例,请参阅Prometheus marathon-sd 配置文件。

默认情况下,所有应用程序将在 Prometheus 中显示为单个作业(在配置文件中指定的作业),也可以使用重新标记来更改。

nerve_sd_config

Nerve SD 配置允许从AirBnB 的 Nerve中检索存储在 Zookeeper中的抓取目标。

在重新标记期间,目标上可以使用以下元标签

  • __meta_nerve_path: Zookeeper 中端点节点的完整路径
  • __meta_nerve_endpoint_host: 端点的主机
  • __meta_nerve_endpoint_port: 端点的端口
  • __meta_nerve_endpoint_name: 端点的名称
1
2
3
4
5
6
7
# The Zookeeper servers.
servers:
- <host>
# Paths can point to a single service, or the root of a tree of services.
paths:
- <string>
[ timeout: <duration> | default = 10s ]

serverset_sd_config

Serverset SD 配置允许从存储在Zookeeper中的Serverset中检索抓取目标。服务器集通常由FinagleAurora使用。

在重新标记期间,目标上可以使用以下元标签

  • __meta_serverset_path:Zookeeper 中 serverset 成员节点的完整路径
  • __meta_serverset_endpoint_host: 默认端点的主机
  • __meta_serverset_endpoint_port: 默认端点的端口
  • _meta_serverset_endpoint_host: 给定端点的主机
  • _meta_serverset_endpoint_port:给定端点的端口
  • __meta_serverset_shard: 成员的分片号
  • __meta_serverset_status:成员的状态
1
2
3
4
5
6
7
# The Zookeeper servers.
servers:
- <host>
# Paths can point to a single serverset, or the root of a tree of serversets.
paths:
- <string>
[ timeout: <duration> | default = 10s ]

Serverset 数据必须是 JSON 格式,目前不支持 Thrift 格式。

triton_sd_config

Triton SD 配置允许从Container Monitor 发现端点检索抓取目标。

可以配置以下类型之一来发现目标:

container

该container角色为每个拥有的“虚拟机”发现一个目标account。这些是 SmartOS 区域或 lx/KVM/bhyve 品牌区域。

在重新标记期间,目标上可以使用以下元标签

  • __meta_triton_groups:属于由逗号分隔符连接的目标的组列表
  • __meta_triton_machine_alias:目标容器的别名
  • __meta_triton_machine_brand:目标容器的品牌
  • __meta_triton_machine_id: 目标容器的 UUID
  • __meta_triton_machine_image:目标容器的图像类型
  • __meta_triton_server_id:目标容器正在运行的服务器 UUID

cn

该cn角色为组成 Triton 基础架构的每个计算节点(也称为“服务器”或“全局区域”)发现一个目标。必须是 Triton 操作员,account并且目前需要拥有至少一个container.

在重新标记期间,目标上可以使用以下元标签

  • __meta_triton_machine_alias:目标的主机名(需要 triton-cmon 1.7.0 或更高版本)
  • __meta_triton_machine_id: 目标的 UUID

有关 Triton 发现的配置选项,请参见下文:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# The information to access the Triton discovery API.

# The account to use for discovering new targets.
account: <string>

# The type of targets to discover, can be set to:
# * "container" to discover virtual machines (SmartOS zones, lx/KVM/bhyve branded zones) running on Triton
# * "cn" to discover compute nodes (servers/global zones) making up the Triton infrastructure
[ role : <string> | default = "container" ]

# The DNS suffix which should be applied to target.
dns_suffix: <string>

# The Triton discovery endpoint (e.g. 'cmon.us-east-3b.triton.zone'). This is
# often the same value as dns_suffix.
endpoint: <string>

# A list of groups for which targets are retrieved, only supported when `role` == `container`.
# If omitted all containers owned by the requesting account are scraped.
groups:
[ - <string> ... ]

# The port to use for discovery and metric scraping.
[ port: <int> | default = 9163 ]

# The interval which should be used for refreshing targets.
[ refresh_interval: <duration> | default = 60s ]

# The Triton discovery API version.
[ version: <int> | default = 1 ]

# TLS configuration.
tls_config:
[ <tls_config> ]

eureka_sd_config

Eureka SD 配置允许使用Eureka REST API检索抓取目标 。Prometheus 将定期检查 REST 端点并为每个应用程序实例创建一个目标。

在重新标记期间,目标上可以使用以下元标签

  • __meta_eureka_app_name:应用程序的名称
  • __meta_eureka_app_instance_id:应用实例的ID
  • __meta_eureka_app_instance_hostname: 实例的主机名
  • __meta_eureka_app_instance_homepage_url: 应用实例的主页 url
  • __meta_eureka_app_instance_statuspage_url: 应用实例的状态页 url
  • __meta_eureka_app_instance_healthcheck_url: 应用实例的健康检查 url
  • __meta_eureka_app_instance_ip_addr:应用实例的IP地址
  • __meta_eureka_app_instance_vip_address:应用实例的VIP地址
  • __meta_eureka_app_instance_secure_vip_address: 应用实例的安全 VIP 地址
  • __meta_eureka_app_instance_status: 应用实例的状态
  • __meta_eureka_app_instance_port: 应用实例的端口
  • __meta_eureka_app_instance_port_enabled: 应用实例启用的端口
  • __meta_eureka_app_instance_secure_port:应用实例的安全端口地址
  • __meta_eureka_app_instance_secure_port_enabled: 应用实例的安全端口
  • __meta_eureka_app_instance_country_id: 应用实例的国家 ID
  • _meta_eureka_app_instance_metadata: 应用实例元数据
  • __meta_eureka_app_instance_datacenterinfo_name:应用实例的数据中心名称
  • _meta_eureka_app_instance_datacenterinfo:数据中心元数据

有关 Eureka 发现的配置选项,请参见下文:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# The URL to connect to the Eureka server.
server: <string>

# Sets the `Authorization` header on every request with the
# configured username and password.
# password and password_file are mutually exclusive.
basic_auth:
[ username: <string> ]
[ password: <secret> ]
[ password_file: <string> ]

# Optional `Authorization` header configuration.
authorization:
# Sets the authentication type.
[ type: <string> | default: Bearer ]
# Sets the credentials. It is mutually exclusive with
# `credentials_file`.
[ credentials: <secret> ]
# Sets the credentials to the credentials read from the configured file.
# It is mutually exclusive with `credentials`.
[ credentials_file: <filename> ]

# Optional OAuth 2.0 configuration.
# Cannot be used at the same time as basic_auth or authorization.
oauth2:
[ <oauth2> ]

# Configures the scrape request's TLS settings.
tls_config:
[ <tls_config> ]

# Optional proxy URL.
[ proxy_url: <string> ]

# Configure whether HTTP requests follow HTTP 3xx redirects.
[ follow_redirects: <boolean> | default = true ]

# Refresh interval to re-read the app instance list.
[ refresh_interval: <duration> | default = 30s ]

有关如何设置 Eureka 应用程序和 Prometheus 配置的实际示例,请参阅Prometheus eureka-sd 配置文件。

scaleway_sd_config

Scaleway SD 配置允许从Scaleway instancesbaremetal services.中检索抓取目标。

在重新标记期间,目标上可以使用以下元标签

Instance role

  • __meta_scaleway_instance_boot_type: 服务器的启动类型
  • __meta_scaleway_instance_hostname: 服务器的主机名
  • __meta_scaleway_instance_id: 服务器的ID
  • __meta_scaleway_instance_image_arch: 服务器镜像的拱门
  • __meta_scaleway_instance_image_id:服务器镜像的ID
  • __meta_scaleway_instance_image_name: 服务器镜像的名称
  • __meta_scaleway_instance_location_cluster_id:服务器位置的集群 ID
  • __meta_scaleway_instance_location_hypervisor_id:服务器位置的管理程序 ID
  • __meta_scaleway_instance_location_node_id:服务器位置的节点ID
  • __meta_scaleway_instance_name: 服务器名称
  • __meta_scaleway_instance_organization_id: 服务器的组织
  • __meta_scaleway_instance_private_ipv4: 服务器的私有 IPv4 地址
  • __meta_scaleway_instance_project_id: 服务器的项目ID
  • __meta_scaleway_instance_public_ipv4:服务器的公共 IPv4 地址
  • __meta_scaleway_instance_public_ipv6:服务器的公共 IPv6 地址
  • __meta_scaleway_instance_region: 服务器所在区域
  • __meta_scaleway_instance_security_group_id:服务器的安全组ID
  • __meta_scaleway_instance_security_group_name: 服务器的安全组名称
  • __meta_scaleway_instance_status: 服务器的状态
  • __meta_scaleway_instance_tags:标签分隔符加入的服务器标签列表
  • __meta_scaleway_instance_type:服务器的商业类型
  • __meta_scaleway_instance_zone:服务器的区域(例如: ,此处fr-par-1的完整列表)

此角色默认使用私有 IPv4 地址。这可以通过重新标记来更改,如Prometheus scaleway-sd 配置文件中所示。

Baremetal role

  • __meta_scaleway_baremetal_id: 服务器的ID
  • __meta_scaleway_baremetal_public_ipv4:服务器的公共 IPv4 地址
  • __meta_scaleway_baremetal_public_ipv6:服务器的公共 IPv6 地址
  • __meta_scaleway_baremetal_name: 服务器的名字
  • __meta_scaleway_baremetal_os_name: 服务器的操作系统名称
  • __meta_scaleway_baremetal_os_version: 服务器的操作系统版本
  • __meta_scaleway_baremetal_project_id:服务器的项目ID
  • __meta_scaleway_baremetal_status: 服务器的状态
  • __meta_scaleway_baremetal_tags:标签分隔符加入的服务器标签列表
  • __meta_scaleway_baremetal_type:服务器的商业类型
  • __meta_scaleway_baremetal_zone:服务器的区域(例如: ,此处fr-par-1的完整列表)

此角色默认使用公共 IPv4 地址。这可以通过重新标记来更改,如Prometheus scaleway-sd 配置文件中所示。

有关 Scaleway 发现的配置选项,请参见下文:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Access key to use. https://console.scaleway.com/project/credentials
access_key: <string>

# Secret key to use when listing targets. https://console.scaleway.com/project/credentials
# It is mutually exclusive with `secret_key_file`.
[ secret_key: <secret> ]

# Sets the secret key with the credentials read from the configured file.
# It is mutually exclusive with `secret_key`.
[ secret_key_file: <filename> ]

# Project ID of the targets.
project_id: <string>

# Role of the targets to retrieve. Must be `instance` or `baremetal`.
role: <string>

# The port to scrape metrics from.
[ port: <int> | default = 80 ]

# API URL to use when doing the server listing requests.
[ api_url: <string> | default = "https://api.scaleway.com" ]

# Zone is the availability zone of your targets (e.g. fr-par-1).
[ zone: <string> | default = fr-par-1 ]

# NameFilter specify a name filter (works as a LIKE) to apply on the server listing request.
[ name_filter: <string> ]

# TagsFilter specify a tag filter (a server needs to have all defined tags to be listed) to apply on the server listing request.
tags_filter:
[ - <string> ]

# Refresh interval to re-read the targets list.
[ refresh_interval: <duration> | default = 60s ]

# Configure whether HTTP requests follow HTTP 3xx redirects.
[ follow_redirects: <boolean> | default = true ]

# Optional proxy URL.
[ proxy_url: <string> ]

# TLS configuration.
tls_config:
[ <tls_config> ]

uyuni_sd_config

Uyuni SD 配置允许通过Uyuni API从托管系统中检索抓取目标。

在重新标记期间,目标上可以使用以下元标签

  • __meta_uyuni_endpoint_name:应用程序端点的名称
  • __meta_uyuni_exporter: 为目标公开指标的导出器
  • __meta_uyuni_groups:目标的系统组
  • __meta_uyuni_metrics_path:目标的指标路径
  • __meta_uyuni_minion_hostname: Uyuni 客户端的主机名
  • __meta_uyuni_primary_fqdn: Uyuni 客户端的主 FQDN
  • __meta_uyuni_proxy_module: 如果为目标配置了Exporter Exporter代理,则为模块名称
  • __meta_uyuni_scheme:用于请求的协议方案
  • __meta_uyuni_system_id:客户端的系统ID

有关 Uyuni 发现的配置选项,请参见下文:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# The URL to connect to the Uyuni server.
server: <string>

# Credentials are used to authenticate the requests to Uyuni API.
username: <string>
password: <secret>

# The entitlement string to filter eligible systems.
[ entitlement: <string> | default = monitoring_entitled ]

# The string by which Uyuni group names are joined into the groups label.
[ separator: <string> | default = , ]

# Refresh interval to re-read the managed targets list.
[ refresh_interval: <duration> | default = 60s ]

# Optional HTTP basic authentication information, currently not supported by Uyuni.
basic_auth:
[ username: <string> ]
[ password: <secret> ]
[ password_file: <string> ]

# Optional `Authorization` header configuration, currently not supported by Uyuni.
authorization:
# Sets the authentication type.
[ type: <string> | default: Bearer ]
# Sets the credentials. It is mutually exclusive with
# `credentials_file`.
[ credentials: <secret> ]
# Sets the credentials to the credentials read from the configured file.
# It is mutually exclusive with `credentials`.
[ credentials_file: <filename> ]

# Optional OAuth 2.0 configuration, currently not supported by Uyuni.
# Cannot be used at the same time as basic_auth or authorization.
oauth2:
[ <oauth2> ]

# Optional proxy URL.
[ proxy_url: <string> ]

# Configure whether HTTP requests follow HTTP 3xx redirects.
[ follow_redirects: <boolean> | default = true ]

# TLS configuration.
tls_config:
[ <tls_config> ]

有关如何设置 Uyuni Prometheus 配置的实际示例,请参阅Prometheus uyuni-sd 配置文件。

static_config

static_config允许为它们指定一个目标列表和一个公共标签集。这是在抓取配置中指定静态目标的规范方法。

1
2
3
4
5
6
7
# The targets specified by the static config.
targets:
[ - '<host>' ]

# 给采集到的指标新增的 label
labels:
[ <labelname>: <labelvalue> ... ]

relabel_config

重新标记是一个强大的工具,可以在目标被抓取之前动态重写目标的标签集。每个抓取配置可以配置多个重新标记步骤。它们按照它们在配置文件中出现的顺序应用于每个目标的标签集。

最初,除了配置的每个目标标签之外,目标的job 标签被设置为job_name相应的抓取配置的值。__address__标签设置为目标的地址:。重新标记后,如果在重新标记期间未设置标签,则默认instance设置为 的值。__address__和标签分别设置为目标的方案和指标路径__scheme__。 标签设置为第一个传递的 URL 参数的值,__metrics_path__称为._param

和标签设置为目标的间隔和超时__scrape_interval__。__scrape_timeout__这是实验性的,将来可能会改变。

__meta_在重新标记阶段可能会提供带有前缀的附加标签。它们由提供目标的服务发现机制设置,并且因机制而异。

__目标重新标记完成后,将从标签集中删除以开头的标签。

如果重新标记步骤只需要临时存储标签值(作为后续重新标记步骤的输入),请使用__tmp标签名称前缀。这个前缀保证不会被 Prometheus 本身使用。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# The source labels select values from existing labels. Their content is concatenated
# using the configured separator and matched against the configured regular expression
# for the replace, keep, and drop actions.
[ source_labels: '[' <labelname> [, ...] ']' ]

# Separator placed between concatenated source label values.
[ separator: <string> | default = ; ]

# Label to which the resulting value is written in a replace action.
# It is mandatory for replace actions. Regex capture groups are available.
[ target_label: <labelname> ]

# Regular expression against which the extracted value is matched.
[ regex: <regex> | default = (.*) ]

# Modulus to take of the hash of the source label values.
[ modulus: <int> ]

# Replacement value against which a regex replace is performed if the
# regular expression matches. Regex capture groups are available.
[ replacement: <string> | default = $1 ]

# Action to perform based on regex matching.
[ action: <relabel_action> | default = replace ]

是任何有效的 RE2 正则表达式。它是replace、keep、drop、labelmap和动作所必需labeldrop的。labelkeep正则表达式锚定在两端。要取消锚定正则表达式,请使用...

确定要采取的重新标记操作:

  • replace: 正则匹配源标签的值用来替换目标标签;如果有replacement,使用replacement替换目标标签;
  • keep: 如果正则没有匹配到源标签,删除targets
  • drop: 正则匹配到源标签,删除targets
  • hashmod:设置目标标签值为源标签值的hash值
  • labelmap:正则匹配所有标签名; 将匹配的标签的值复制到由replacement提供的标签名
  • labeldrop:正则匹配所有标签名;匹配则移除标签;
  • labelkeep:正则匹配所有标签名;不匹配的标签会被移除;

必须注意labeldrop并labelkeep确保一旦删除标签,指标仍然被唯一标记。

metric_relabel_configs

度量重新标记作为摄取前的最后一步应用于样本。它具有与目标重新标记相同的配置格式和操作。度量重新标记不适用于自动生成的时间序列,例如up.

这样做的一个用途是排除太昂贵而无法摄取的时间序列。

alert_relabel_configs

在将警报发送到警报管理器之前,警报重新标记将应用于警报。它具有与目标重新标记相同的配置格式和操作。在外部标签之后应用警报重新标记。

这样做的一个用途是确保具有不同外部标签的一对高可用性 Prometheus 服务器发送相同的警报。

alertmanager_config

一个alertmanager_config部分指定 Prometheus 服务器向其发送警报的 Alertmanager 实例。它还提供参数来配置如何与这些 Alertmanager 进行通信。

Alertmanagers 可以通过static_configs参数静态配置或使用支持的服务发现机制之一动态发现。

此外,relabel_configs允许从发现的实体中选择 Alertmanagers,并对使用的 API 路径提供高级修改,该路径通过__alerts_path__标签公开。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# Per-target Alertmanager timeout when pushing alerts.
[ timeout: <duration> | default = 10s ]

# The api version of Alertmanager.
[ api_version: <string> | default = v2 ]

# Prefix for the HTTP path alerts are pushed to.
[ path_prefix: <path> | default = / ]

# Configures the protocol scheme used for requests.
[ scheme: <scheme> | default = http ]

# Sets the `Authorization` header on every request with the
# configured username and password.
# password and password_file are mutually exclusive.
basic_auth:
[ username: <string> ]
[ password: <secret> ]
[ password_file: <string> ]

# Optional `Authorization` header configuration.
authorization:
# Sets the authentication type.
[ type: <string> | default: Bearer ]
# Sets the credentials. It is mutually exclusive with
# `credentials_file`.
[ credentials: <secret> ]
# Sets the credentials to the credentials read from the configured file.
# It is mutually exclusive with `credentials`.
[ credentials_file: <filename> ]

# Optional OAuth 2.0 configuration.
# Cannot be used at the same time as basic_auth or authorization.
oauth2:
[ <oauth2> ]

# Configures the scrape request's TLS settings.
tls_config:
[ <tls_config> ]

# Optional proxy URL.
[ proxy_url: <string> ]

# Configure whether HTTP requests follow HTTP 3xx redirects.
[ follow_redirects: <boolean> | default = true ]

# List of Azure service discovery configurations.
azure_sd_configs:
[ - <azure_sd_config> ... ]

# List of Consul service discovery configurations.
consul_sd_configs:
[ - <consul_sd_config> ... ]

# List of DNS service discovery configurations.
dns_sd_configs:
[ - <dns_sd_config> ... ]

# List of EC2 service discovery configurations.
ec2_sd_configs:
[ - <ec2_sd_config> ... ]

# List of Eureka service discovery configurations.
eureka_sd_configs:
[ - <eureka_sd_config> ... ]

# List of file service discovery configurations.
file_sd_configs:
[ - <file_sd_config> ... ]

# List of DigitalOcean service discovery configurations.
digitalocean_sd_configs:
[ - <digitalocean_sd_config> ... ]

# List of Docker service discovery configurations.
docker_sd_configs:
[ - <docker_sd_config> ... ]

# List of Docker Swarm service discovery configurations.
dockerswarm_sd_configs:
[ - <dockerswarm_sd_config> ... ]

# List of GCE service discovery configurations.
gce_sd_configs:
[ - <gce_sd_config> ... ]

# List of Hetzner service discovery configurations.
hetzner_sd_configs:
[ - <hetzner_sd_config> ... ]

# List of HTTP service discovery configurations.
http_sd_configs:
[ - <http_sd_config> ... ]

# List of Kubernetes service discovery configurations.
kubernetes_sd_configs:
[ - <kubernetes_sd_config> ... ]

# List of Lightsail service discovery configurations.
lightsail_sd_configs:
[ - <lightsail_sd_config> ... ]

# List of Linode service discovery configurations.
linode_sd_configs:
[ - <linode_sd_config> ... ]

# List of Marathon service discovery configurations.
marathon_sd_configs:
[ - <marathon_sd_config> ... ]

# List of AirBnB's Nerve service discovery configurations.
nerve_sd_configs:
[ - <nerve_sd_config> ... ]

# List of OpenStack service discovery configurations.
openstack_sd_configs:
[ - <openstack_sd_config> ... ]

# List of PuppetDB service discovery configurations.
puppetdb_sd_configs:
[ - <puppetdb_sd_config> ... ]

# List of Scaleway service discovery configurations.
scaleway_sd_configs:
[ - <scaleway_sd_config> ... ]

# List of Zookeeper Serverset service discovery configurations.
serverset_sd_configs:
[ - <serverset_sd_config> ... ]

# List of Triton service discovery configurations.
triton_sd_configs:
[ - <triton_sd_config> ... ]

# List of Uyuni service discovery configurations.
uyuni_sd_configs:
[ - <uyuni_sd_config> ... ]

# List of labeled statically configured Alertmanagers.
static_configs:
[ - <static_config> ... ]

# List of Alertmanager relabel configurations.
relabel_configs:
[ - <relabel_config> ... ]

tracing_config

tracing_config配置通过 OTLP 协议从 Prometheus 导出跟踪到跟踪后端。跟踪目前是一项实验性功能,未来可能会发生变化。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Client used to export the traces. Options are 'http' or 'grpc'.
[ client_type: <string> | default = grpc ]

# Endpoint to send the traces to. Should be provided in format <host>:<port>.
[ endpoint: <string> ]

# Sets the probability a given trace will be sampled. Must be a float from 0 through 1.
[ sampling_fraction: <float> | default = 0 ]

# If disabled, the client will use a secure connection.
[ insecure: <boolean> | default = false ]

# Key-value pairs to be used as headers associated with gRPC or HTTP requests.
headers:
[ <string>: <string> ... ]

# Compression key for supported compression types. Supported compression: gzip.
[ compression: <string> ]

# Maximum time the exporter will wait for each batch export.
[ timeout: <duration> | default = 10s ]

# TLS configuration.
tls_config:
[ <tls_config> ]

remote_write

write_relabel_configs在将样本发送到远程端点之前对其应用重新标记。写入重新标记在外部标签之后应用。这可用于限制发送哪些样本。

有一个关于如何使用此功能的小演示。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# The URL of the endpoint to send samples to.
url: <string>

# Timeout for requests to the remote write endpoint.
[ remote_timeout: <duration> | default = 30s ]

# Custom HTTP headers to be sent along with each remote write request.
# Be aware that headers that are set by Prometheus itself can't be overwritten.
headers:
[ <string>: <string> ... ]

# List of remote write relabel configurations.
write_relabel_configs:
[ - <relabel_config> ... ]

# Name of the remote write config, which if specified must be unique among remote write configs.
# The name will be used in metrics and logging in place of a generated value to help users distinguish between
# remote write configs.
[ name: <string> ]

# Enables sending of exemplars over remote write. Note that exemplar storage itself must be enabled for exemplars to be scraped in the first place.
[ send_exemplars: <boolean> | default = false ]

# Sets the `Authorization` header on every remote write request with the
# configured username and password.
# password and password_file are mutually exclusive.
basic_auth:
[ username: <string> ]
[ password: <secret> ]
[ password_file: <string> ]

# Optional `Authorization` header configuration.
authorization:
# Sets the authentication type.
[ type: <string> | default: Bearer ]
# Sets the credentials. It is mutually exclusive with
# `credentials_file`.
[ credentials: <secret> ]
# Sets the credentials to the credentials read from the configured file.
# It is mutually exclusive with `credentials`.
[ credentials_file: <filename> ]

# Optionally configures AWS's Signature Verification 4 signing process to
# sign requests. Cannot be set at the same time as basic_auth, authorization, or oauth2.
# To use the default credentials from the AWS SDK, use `sigv4: {}`.
sigv4:
# The AWS region. If blank, the region from the default credentials chain
# is used.
[ region: <string> ]

# The AWS API keys. If blank, the environment variables `AWS_ACCESS_KEY_ID`
# and `AWS_SECRET_ACCESS_KEY` are used.
[ access_key: <string> ]
[ secret_key: <secret> ]

# Named AWS profile used to authenticate.
[ profile: <string> ]

# AWS Role ARN, an alternative to using AWS API keys.
[ role_arn: <string> ]

# Optional OAuth 2.0 configuration.
# Cannot be used at the same time as basic_auth, authorization, or sigv4.
oauth2:
[ <oauth2> ]

# Configures the remote write request's TLS settings.
tls_config:
[ <tls_config> ]

# Optional proxy URL.
[ proxy_url: <string> ]

# Configure whether HTTP requests follow HTTP 3xx redirects.
[ follow_redirects: <boolean> | default = true ]

# Configures the queue used to write to remote storage.
queue_config:
# Number of samples to buffer per shard before we block reading of more
# samples from the WAL. It is recommended to have enough capacity in each
# shard to buffer several requests to keep throughput up while processing
# occasional slow remote requests.
[ capacity: <int> | default = 2500 ]
# Maximum number of shards, i.e. amount of concurrency.
[ max_shards: <int> | default = 200 ]
# Minimum number of shards, i.e. amount of concurrency.
[ min_shards: <int> | default = 1 ]
# Maximum number of samples per send.
[ max_samples_per_send: <int> | default = 500]
# Maximum time a sample will wait in buffer.
[ batch_send_deadline: <duration> | default = 5s ]
# Initial retry delay. Gets doubled for every retry.
[ min_backoff: <duration> | default = 30ms ]
# Maximum retry delay.
[ max_backoff: <duration> | default = 5s ]
# Retry upon receiving a 429 status code from the remote-write storage.
# This is experimental and might change in the future.
[ retry_on_http_429: <boolean> | default = false ]

# Configures the sending of series metadata to remote storage.
# Metadata configuration is subject to change at any point
# or be removed in future releases.
metadata_config:
# Whether metric metadata is sent to remote storage or not.
[ send: <boolean> | default = true ]
# How frequently metric metadata is sent to remote storage.
[ send_interval: <duration> | default = 1m ]
# Maximum number of samples per send.
[ max_samples_per_send: <int> | default = 500]

remote_read

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# The URL of the endpoint to query from.
url: <string>

# Name of the remote read config, which if specified must be unique among remote read configs.
# The name will be used in metrics and logging in place of a generated value to help users distinguish between
# remote read configs.
[ name: <string> ]

# An optional list of equality matchers which have to be
# present in a selector to query the remote read endpoint.
required_matchers:
[ <labelname>: <labelvalue> ... ]

# Timeout for requests to the remote read endpoint.
[ remote_timeout: <duration> | default = 1m ]

# Custom HTTP headers to be sent along with each remote read request.
# Be aware that headers that are set by Prometheus itself can't be overwritten.
headers:
[ <string>: <string> ... ]

# Whether reads should be made for queries for time ranges that
# the local storage should have complete data for.
[ read_recent: <boolean> | default = false ]

# Sets the `Authorization` header on every remote read request with the
# configured username and password.
# password and password_file are mutually exclusive.
basic_auth:
[ username: <string> ]
[ password: <secret> ]
[ password_file: <string> ]

# Optional `Authorization` header configuration.
authorization:
# Sets the authentication type.
[ type: <string> | default: Bearer ]
# Sets the credentials. It is mutually exclusive with
# `credentials_file`.
[ credentials: <secret> ]
# Sets the credentials to the credentials read from the configured file.
# It is mutually exclusive with `credentials`.
[ credentials_file: <filename> ]

# Optional OAuth 2.0 configuration.
# Cannot be used at the same time as basic_auth or authorization.
oauth2:
[ <oauth2> ]

# Configures the remote read request's TLS settings.
tls_config:
[ <tls_config> ]

# Optional proxy URL.
[ proxy_url: <string> ]

# Configure whether HTTP requests follow HTTP 3xx redirects.
[ follow_redirects: <boolean> | default = true ]

# Whether to use the external labels as selectors for the remote read endpoint.
[ filter_external_labels: <boolean> | default = true ]

有一个 与此功能的集成列表。

exemplars

请注意,示例存储仍被认为是实验性的,必须通过–enable-feature=exemplar-storage.

1
2
# Configures the maximum size of the circular buffer used to store exemplars for all series. Resizable during runtime.
[ max_exemplars: <int> | default = 100000 ]

Prometheus 配置详解
https://randzz.cn/3bd158d06e6a/prometheus-配置详解/
作者
Ezreal Rao
发布于
2022年5月15日
许可协议