菜单

这是关于下一个洛基的版本。有关最新的稳定版本,请转到最新版本

配置

Promtail在YAML文件中配置(通常称为config.yaml),其中包含Promtail服务器上的信息,位置存储在哪里,以及如何从文件中抓取日志。

在运行时打印Promtail配置

如果你通过了,请举起旗子-print-config-stderr-log-config-reverse-order(或-print-config-stderr = truePromtail将转储它从内置默认值中创建的整个配置对象,首先结合从配置文件的覆盖,然后通过覆盖从标志。

结果是Promtail配置结构体中每个配置对象的值。

有些值可能与您的安装无关,这是预期的,因为每个选项都有一个默认值,无论是否使用。

这个配置是Promtail将用来运行的,它对于调试与配置相关的问题是非常宝贵的,特别是在确保您的配置文件和标志被正确读取和加载时非常有用。

-print-config-stderr当直接运行Promtail时是很好的。。/ promtail因为您可以快速输出整个Promtail配置。

-log-config-reverse-order是我们在所有环境中运行Promtail的标志,配置条目是反向的,以便在Grafana的Explore中查看时,配置的顺序从上到下正确读取。

配置文件参考

参数来指定要加载的配置文件-config.file在命令行标记。文件被写入YAML格式,由下面的模式定义。括号表示参数是可选的。对于非列表参数,该值被设置为指定的默认值。

有关配置如何从目标发现和抓取日志的详细信息,请参见.有关从抓取的目标转换日志的详细信息,请参见管道

在配置中使用环境变量

您可以在配置文件中使用环境变量引用来设置需要在部署期间进行配置的值。要这样做,请通过-config.expand-env = true和使用:

$ {VAR}

其中VAR是环境变量的名称。

每个变量引用在启动时都被环境变量的值替换。替换是区分大小写的,并且发生在YAML文件被解析之前。除非指定默认值或自定义错误文本,否则对未定义变量的引用将被空字符串替换。

要指定一个默认值,请使用:

$ {VAR: default_value}

其中default_value是在环境变量未定义时使用的值。

请注意:expand-env = true配置将首先运行envsubst将双斜杠替换为单斜杠。正因为如此,每一个斜杠的使用需要用双斜杠代替\ \

通用的占位符

  • 布尔> <:可以取值的布尔值真正的
  • < int >:匹配正则表达式的任意整数(1 - 9) + [0 - 9] *
  • <时间>:匹配正则表达式的持续时间[0 - 9] +(女士| [smhdwy])
  • < labelname >:匹配正则表达式的字符串[[a-zA-Z_] - za - z0 - 9 _] *
  • < labelvalue >: Unicode字符串
  • <文件名>:相对于当前工作目录的有效路径或绝对路径。
  • 主机> <:由主机名或IP后跟可选端口号组成的有效字符串
  • <字符串>:字符串
  • <秘密>:表示秘密的字符串,如密码

的支持内容和默认值config.yaml

配置服务器为Promtail。[server: ] #描述Promtail如何连接到Grafana Loki的多个实例#,并向每个实例发送日志。#警告:如果其中一个远程Loki服务器未能响应或响应#与任何错误,这将影响发送日志到任何#其他配置远程Loki服务器。发送是在单个线程上完成的!如果你想发送到多个远程Loki实例,通常建议并行运行多个Promtail客户端。clients: - [] #描述如何将读文件偏移保存到磁盘[positions: ] scrape_configs: - [] #为这个Promtail实例配置全局限制[limits_config: ] #配置如何监视尾部目标。[target_config: ] #配置额外的promtail配置。[options: ] #配置跟踪支持[tracing: ]

服务器

服务器block将Promtail的行为配置为HTTP服务器:

#关闭HTTP和GRPC服务器。[disable:  | default = false] #启用/debug/fgprof和/debug/pprof端点进行分析。[profiling_enabled:  | default = false] # HTTP服务器监听主机[http_listen_address: ] # HTTP服务器监听端口(0表示随机端口)[http_listen_port:  | default = 80] # gRPC服务器监听主机[grpc_listen_address: ] # gRPC服务器监听端口(0表示随机端口)[grpc_listen_port:  | default = 9095] #注册工具处理程序(/metrics等)[register_instrumentation: | default = true] # graceful shutdown Timeout [graceful_shutdown_timeout:  | default = 30s] # HTTP服务器读超时[http_server_read_timeout:  | default = 30s] # HTTP服务器写超时[http_server_write_timeout:  | default = 30s] # HTTP服务器空闲超时[http_server_idle_timeout:  | default = 120s] #可以接收的最大gRPC消息大小[grpc_server_max_recv_msg_size: | default = 4194304] #可以发送的最大gRPC消息大小[grpc_server_max_send_msg_size:  | default = 4194304] # gRPC调用并发流数量限制(0 =无限)[grpc_server_max_concurrent_streams:  | default = 100] #只记录给定级别或以上的消息。支持的值[debug, # info, warn, error] [log_level:  | default = "info"] #服务器所有API路由的基本路径(例如,/v1/)[http_path_prefix: ] #目标管理器检查Promtail准备就绪的标志,如果设置为false,检查将被忽略[health_check_target:  | default = true] #通过HTTP请求启用重新加载。[enable_runtime_reload:  | default = false]

客户

客户block配置Promtail如何连接到Loki实例:

Loki监听的URL,在Loki中表示为http_listen_address和# http_listen_port。如果Loki运行在微服务模式下,这是分发服务器的HTTP # URL。需要包括推送API的路径。#示例:http://example.com:3100/loki/api/v1/push url:  #与每个推送请求一起发送的自定义HTTP报头。注意Promtail本身设置的标题(例如X-Scope-OrgID)不能被覆盖。#示例:CF-Access-Client-Id: xxx [: …]#推送日志到Loki时默认使用的租户ID。如果省略或为空#,则假设Loki运行在单租户模式,并且没有发送X-Scope-OrgID报头#。[tenant_id: ] #发送批处理前的最大等待时间,即使# batch未满。[batchwait:  | default = 1s] #在向Loki发送#批处理之前,可累积的最大批处理大小(以字节为单位) [batchsize:  | default = 1048576] # If using basic auth, configures the username and password # sent. basic_auth: # The username to use for basic auth [username: ] # The password to use for basic auth [password: ] # The file containing the password for basic auth [password_file: ] # Optional OAuth 2.0 configuration # Cannot be used at the same time as basic_auth or authorization oauth2: # Client id and secret for oauth2 [client_id: ] [client_secret: ] # Read the client secret from a file # It is mutually exclusive with `client_secret` [client_secret_file: ] # Optional scopes for the token request scopes: [ -  ... ] # The URL to fetch the token from token_url:  # Optional parameters to append to the token URL endpoint_params: [ :  ... ] # Bearer token to send to the server. [bearer_token: ] # File containing bearer token to send to the server. [bearer_token_file: ] # HTTP proxy server to use to connect to the server. [proxy_url: ] # If connecting to a TLS server, configures how the TLS # authentication handshake will operate. tls_config: # The CA file to use to verify the server [ca_file: ] # The cert file to send to the server for client auth [cert_file: ] # The key file to send to the server for client auth [key_file: ] # Validates that the server name in the server's certificate # is this value. [server_name: ] # If true, ignores the server certificate being signed by an # unknown CA. [insecure_skip_verify:  | default = false] # Configures how to retry requests to Loki when a request # fails. # Default backoff schedule: # 0.5s, 1s, 2s, 4s, 8s, 16s, 32s, 64s, 128s, 256s(4.267m) # For a total time of 511.5s(8.5m) before logs are lost backoff_config: # Initial backoff time between retries [min_period:  | default = 500ms] # Maximum backoff time between retries [max_period:  | default = 5m] # Maximum number of retries to do [max_retries:  | default = 10] # Disable retries of batches that Loki responds to with a 429 status code (TooManyRequests). This reduces # impacts on batches from other tenants, which could end up being delayed or dropped due to exponential backoff. [drop_rate_limited_batches:  | default = false] # Static labels to add to all logs being sent to Loki. # Use map like {"foo": "bar"} to add a label foo with # value bar. # These can also be specified from command line: # -client.external-labels=k1=v1,k2=v2 # (or --client.external-labels depending on your OS) # labels supplied by the command line are applied # to all clients configured in the `clients` section. # NOTE: values defined in the config file will replace values # defined on the command line for a given client if the # label keys are the same. external_labels: [ :  ... ] # Maximum time to wait for a server to respond to a request [timeout:  | default = 10s]

职位

职位block配置Promtail将保存文件的位置,指示它已读取文件的距离。当Promtail重新启动时需要它,以允许它从停止的地方继续。

#位置文件[filename:  | default = "/var/log/positions. "yaml"] #多久更新一次位置文件[sync_period:  | default = 10s] #是否忽略和稍后覆盖位置文件损坏[ignore_invalid_yaml:  | default = false]

scrape_configs

scrape_configsblock配置Promtail如何使用指定的发现方法从一系列目标中抓取日志:

#在Promtail UI中标识此刮取配置的名称。job_name:  #描述如何从目标器转换日志。[pipeline_stages: ] #描述如何从日志中抓取日志。[journal: ] #描述应从哪一种编码转换抓取文件。[encoding: ] #描述如何接收syslog日志。[syslog: ] #描述如何通过Loki推送API接收日志(例如从其他Promtails或Docker日志驱动)[loki_push_api: ] #描述如何从Windows事件日志中抓取日志。[windows_events: ] #提取/接收谷歌GCP日志的配置。[gcplog: ] #描述如何通过消费者组从Kafka获取日志。[kafka: ] #描述如何从elf客户端接收日志。[gelf: ] #从Cloudflare中提取日志的配置。 [cloudflare: ] # Configuration describing how to pull logs from a Heroku LogPlex drain. [heroku_drain: ] # Describes how to relabel targets to determine if they should # be processed. relabel_configs: - [] # Static targets to scrape. static_configs: - [] # Files containing targets to scrape. file_sd_configs: - [] # Describes how to discover Kubernetes services running on the # same host. kubernetes_sd_configs: - [] # Describes how to use the Consul Catalog API to discover services registered with the # consul cluster. consul_sd_configs: [ -  ... ] # Describes how to use the Consul Agent API to discover services registered with the consul agent # running on the same host as Promtail. consulagent_sd_configs: [ -  ... ] # Describes how to use the Docker daemon API to discover containers running on # the same host as Promtail. docker_sd_configs: [ -  ... ]

pipeline_stages

管道阶段用于转换日志条目及其标签。管道在发现过程结束后执行。的pipeline_stages对象由一个阶段列表组成,这些阶段对应于下面列出的项目。

在大多数情况下,从日志中提取数据正则表达式json阶段。提取的数据被转换为一个临时映射对象。数据可以被Promtail使用,例如作为值标签或者作为输出.此外,任何其他阶段之外码头工人而且中国国际广播电台可以访问提取的数据。

- [ |  |  |  |