匿名
未登录
登录
Linux78|wiki
搜索
查看“Prometheus配置文件”的源代码
来自Linux78|wiki
名字空间
页面
讨论
更多
更多
页面选项
查看
查看源代码
历史
←
Prometheus配置文件
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
wiki:用户|用户
您可以查看与复制此页面的源代码。
默认配置文件中定义了4个YAML块:global、alerting、rule_files和scrape_configs。 === global === 配置的第一部分是global,它包含了控制Prometheus服务器行为的全局配置。 scrape_interval用来指定应用程序或服务抓取数据的时间间隔(在示例中是15秒)。这个值是时间序列的颗粒度,即该序列中每个数据点所覆盖的时间段。 在从特定位置收集指标时,有可能会覆盖这个全局抓取间隔。强烈建议不要这么做!可以在服务器上保持一个全局抓取间隔,这会确保你的所有时间序列具有相同的颗粒度,并且可以组合在一起计算。但是,当使用了不同的数据间隔来收集数据时,则可能产生不合逻辑的结果。 参数evaluation_interval用来指定Prometheus评估规则的频率。目前主要有两种规则:记录规则(recording rule)和警报规则(alerting rule)。 记录规则:允许预先计算使用频繁且开销大的表达式,并将结果保存为一个新的时间序列数据。 警报规则:允许定义警报条件。根据这个参数,Prometheus将每隔15秒(重新)评估这些规则。我们也将在后续章节中了解有关规则的更多内容。 === alerting === 配置的第二部分是alerting,它用来设置Prometheus的警报。正如我们在上一章中提到的,警报是由名为Alertmanager的独立工具进行管理的。Alertmanager是一个可以集群化的独立警报管理工具。 alerting: alertmanager: - static_configs: - target: # - alertmanager:9093 在默认配置中,alerting部分包含服务器的警报配置,其中alertmanagers块会列出Prometheus服务器使用的每个Alertmanager,static_configs块表示我们要手动指定在targets数组中配置的Alertmanager。 提示 Prometheus还支持Alertmanager的服务发现功能。例如,你可以通过查询外部源(如Consul服务器)来返回可用的Alertmanager列表,而不是单独指定每个Alertmanager。 === scrape_configs === 配置的最后一部分是scrape_configs,用来指定Prometheus抓取的所有目标。Prometheus将它抓取的指标的数据源称为端点。为了抓取这些端点的数据,Prometheus定义了一个目标,这个目标里包含的信息是抓取数据所必需的,比如用到的标签、建立连接所需的身份验证,或者其他定义数据抓取的信息。若干目标构成的组称为作业,作业里每个目标都有一个名为实例(instance)的标签,用来唯一标识这个目标。 scrape_config: - job_name: 'prometheus' static_configs: - targets: ['localhost:9090'] 默认配置中定义了一个作业prometheus,它的static_configs参数部分列出了抓取的目标,这些特定的目标被单独列出来,而不是通过自动服务发现。你也可以将静态配置理解为手动或人工服务发现。 作业prometheus只有一个监控目标:Prometheus服务器自身。它从本地的9090端口抓取数据并返回服务器的健康指标。Prometheus假设抓取的指标将返回到/metrics路径下,因此它会被追加到目标中然后抓取地址http://localhost:9090/metrics。 这个配置文件是YAML格式, 通过下面描述的范式定义, 括号表示参数是可选的。对于非列表参数,这个值被设置了默认值。 通用占位符由下面定义: \<boolean\>: 一个布尔值,包括true或者false. \<duration\>: 持续时间,与正则表达式[0-9]+(ms|smhdwy)匹配 \<labelname\>: 一个与正则表达式[a-zA-Z_][a-zA-Z0-9_]*匹配的字符串 \<labelvalue\>: 一个为unicode字符串 \<filename\>: 当前工作目录下的有效路径 \<host\>: 一个包含主机名或者IP地址,并且可以带上一个非必需的端口号的有效字符串 \<path\>: 一个有效的URL路径 \<scheme\>: 一个可以是http或者https的字符串 \<string\>: 一个正则表达式字符串 其他的占位符被分开指定: 一个有效的配置文件示例。 全局配置指定的参数,在其他上下文配置中是生效的。这也默认这些全局参数在其他配置区域有效。 global: # 抓取目标实例的频率时间值,默认10s [ scrape_interval: <duration> | default = 10s ] # 一次抓取请求超时时间值,默认10s [ scrape_timeout: <duration> | default = 10s ] # 执行配置文件规则的频率时间值, 默认1m [ evaluation_interval: <duration> | default=1m ] # 当和外部系统通信时(federation, remote storage, Alertmanager), 这些标签会增加到度量指标数据中 external_labels: [ <labelname>: <labelvalue> ... ] # 规则文件指定规则文件路径列表。规则和警报是从所有匹配的文件中读取的 rule_files: [ - <filepath_glob> ...] # 抓取配置的列表 scrape_configs: [ - <scrape_config> ... ] # 警报设置 alerting: alert_relabel_configs: [ - <relabel_config> ... ] alertmanagers: [ - <alertmanager_config> ... ] # 设置涉及到未来的实验特征 remote_write: [url: <string> ] [ remote_timeout: <duration> | default = 30s ] tls_config: [ <tls_config> ] [proxy_url: <string> ] basic_auth: [user_name: <string> ] [password: <string> ] write_relabel_configs: [ - <relabel_config> ... ] <scrape_config>区域指定了目标列表和目标下的配置参数, 这些配置参数描述了如何抓取度量指标数据。通常,一个scrape_config只指定一个job,但是可以改变,一个scrape_config可以指定多个job,每个job下有多个targets 通过static_configs参数静态指定要监控的目标列表,或者使用一些服务发现机制发现目标。 另外,relabel_configs允许在获取度量指标数据之前,对任何目标和它的标签进行进一步地修改。 # 默认下任务名称赋值给要抓取的度量指标 job_name: <job_name> # 从这个任务中抓取目标的频率时间值 [ scrape_interval: <duration> | default= <global_config.scrape_interval>] # 当抓取这个任务的所有目标时,超时时间值 [ scrape_timeout: <duration> | default = <global_config.scrape_timeout> ] # 从目标列表中抓取度量指标的http资源路径, 默认为/metrics [ metrics_path: <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_<original-label>" (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: <boolean> | default = false ] # 配置请求的协议范式, 默认为http请求 [ scheme: <scheme> | default = http ] # 可选的http url参数 params: [ <string>:[<string>, ...]] # 在`Authorization`头部设置每次抓取请求的用户名和密码 basic_auth: [username: <string>] [password: <string>] # Sets the `Authorization` header on every scrape request with # the configured bearer token. It is mutually exclusive with `bearer_token_file`. [ bearer_token: <string> ] # 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: [ <tls_config> ] # 可选的代理URL [ proxy_url: <string> ] # 微软的Azure服务发现配置列表 azure_sd_configs: [ - <azure_sd_config> ... ] # Consul服务发现配置列表 consul_sd_configs: [ - <consul_sd_config> ... ] # DNS服务发现配置列表 dns_sd_configs: [ - <dns_sd_config> ... ] # 亚马逊EC2服务发现的配置列表 ec2_sd_configs: [ - <ec2_sd_config> ... ] # 文件服务发现配置列表 file_sd_configs: [ - <file_sd_config> ... ] # google GCE服务发现配置列表 gce_sd_configs: [ - <gce_sd_config> ... ] # Kubernetes服务发现配置列表 kubernetes_sd_configs: [ - <kubernetes_sd_config> ... ] # Marathon服务发现配置列表 marathon_sd_configs: [ - <marathon_sd_config> ... ] # AirBnB的Nerve服务发现配置列表 nerve_sd_configs: [ - <nerve_sd_config> ... ] # Zookeeper服务发现配置列表 serverset_sd_configs: [ - <serverset_sd_config> ... ] # Triton服务发现配置列表 triton_sd_configs: [ - <triton_sd_config> ... ] # 静态配置目标列表 static_configs: [ - <static_config> ... ] # 抓取之前的标签重构配置列表 relabel_configs: [ - <relabel_config> ... ] # List of metric relabel configurations. metric_relabel_configs: [ - <relabel_config> ... ] # 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: <int> | default = 0 ] 记住:在所有获取配置中<job_name>必须是唯一的。 <tls_config>允许配置TLS连接。 # CA证书 [ ca_file: <filename> ] # 证书和key文件 [ cert_file: <filename> ] [ key_file: <filename> ] # ServerName extension to indicate the name of the server. # http://tools.ietf.org/html/rfc4366#section-3.1 [ server_name: <string> ] # Disable validation of the server certificate. [ insecure_skip_verify: <boolean> ]
返回至
Prometheus配置文件
。
导航
导航
首页
最近更改
随机页面
栏目
Nginx
Kubernetes
Spring Cloud
Wiki工具
Wiki工具
特殊页面
页面工具
页面工具
用户页面工具
更多
链入页面
相关更改
页面信息
页面日志