--- title: Configuration --- # Configuring Promtail Promtail is configured in a YAML file (usually referred to as `config.yaml`) which contains information on the Promtail server, where positions are stored, and how to scrape logs from files. - [Configuring Promtail](#configuring-promtail) - [Printing Promtail Config At Runtime](#printing-promtail-config-at-runtime) - [Configuration File Reference](#configuration-file-reference) - [server_config](#server_config) - [client_config](#client_config) - [position_config](#position_config) - [scrape_config](#scrape_config) - [pipeline_stages](#pipeline_stages) - [docker](#docker) - [cri](#cri) - [regex](#regex) - [json](#json) - [template](#template) - [match](#match) - [timestamp](#timestamp) - [output](#output) - [labels](#labels) - [metrics](#metrics) - [counter](#counter) - [gauge](#gauge) - [histogram](#histogram) - [tenant](#tenant) - [journal_config](#journal_config) - [syslog_config](#syslog_config) - [Available Labels](#available-labels) - [loki_push_api_config](#loki_push_api_config) - [relabel_config](#relabel_config) - [static_config](#static_config) - [file_sd_config](#file_sd_config) - [kubernetes_sd_config](#kubernetes_sd_config) - [`node`](#node) - [`service`](#service) - [`pod`](#pod) - [`endpoints`](#endpoints) - [`ingress`](#ingress) - [target_config](#target_config) - [Example Docker Config](#example-docker-config) - [Example Static Config](#example-static-config) - [Example Static Config without targets](#example-static-config-without-targets) - [Example Journal Config](#example-journal-config) - [Example Syslog Config](#example-syslog-config) - [Example Push Config](#example-push-config) ## Printing Promtail Config At Runtime If you pass Promtail the flag `-print-config-stderr` or `-log-config-reverse-order`, (or `-print-config-stderr=true`) Promtail will dump the entire config object it has created from the built in defaults combined first with overrides from config file, and second by overrides from flags. The result is the value for every config object in the Promtail config struct. Some values may not be relevant to your install, this is expected as every option has a default value if it is being used or not. This config is what Promtail will use to run, it can be invaluable for debugging issues related to configuration and is especially useful in making sure your config files and flags are being read and loaded properly. `-print-config-stderr` is nice when running Promtail directly e.g. `./promtail ` as you can get a quick output of the entire Promtail config. `-log-config-reverse-order` is the flag we run Promtail with in all our environments, the config entries are reversed so that the order of configs reads correctly top to bottom when viewed in Grafana's Explore. ## Configuration File Reference To specify which configuration file to load, pass the `-config.file` flag at the command line. The file is written in [YAML format](https://en.wikipedia.org/wiki/YAML), defined by the schema below. Brackets indicate that a parameter is optional. For non-list parameters the value is set to the specified default. For more detailed information on configuring how to discover and scrape logs from targets, see [Scraping](../scraping/). For more information on transforming logs from scraped targets, see [Pipelines](../pipelines/). Generic placeholders are defined as follows: * ``: a boolean that can take the values `true` or `false` * ``: any integer matching the regular expression `[1-9]+[0-9]*` * ``: a duration matching the regular expression `[0-9]+(ms|[smhdwy])` * ``: a string matching the regular expression `[a-zA-Z_][a-zA-Z0-9_]*` * ``: a string of Unicode characters * ``: a valid path relative to current working directory or an absolute path. * ``: a valid string consisting of a hostname or IP followed by an optional port number * ``: a regular string * ``: a regular string that is a secret, such as a password Supported contents and default values of `config.yaml`: ```yaml # Configures the server for Promtail. [server: ] # Describes how Promtail connects to multiple instances # of Loki, sending logs to each. # WARNING: If one of the remote Loki servers fails to respond or responds # with any error which is retryable, this will impact sending logs to any # other configured remote Loki servers. Sending is done on a single thread! # It is generally recommended to run multiple promtail clients in parallel # if you want to send to multiple remote Loki instances. clients: - [] # Describes how to save read file offsets to disk [positions: ] scrape_configs: - [] # Configures how tailed targets will be watched. [target_config: ] ``` ## server_config The `server_config` block configures Promtail's behavior as an HTTP server: ```yaml # Disable the HTTP and GRPC server. [disable: | default = false] # HTTP server listen host [http_listen_address: ] # HTTP server listen port (0 means random port) [http_listen_port: | default = 80] # gRPC server listen host [grpc_listen_address: ] # gRPC server listen port (0 means random port) [grpc_listen_port: | default = 9095] # Register instrumentation handlers (/metrics, etc.) [register_instrumentation: | default = true] # Timeout for graceful shutdowns [graceful_shutdown_timeout: | default = 30s] # Read timeout for HTTP server [http_server_read_timeout: | default = 30s] # Write timeout for HTTP server [http_server_write_timeout: | default = 30s] # Idle timeout for HTTP server [http_server_idle_timeout: | default = 120s] # Max gRPC message size that can be received [grpc_server_max_recv_msg_size: | default = 4194304] # Max gRPC message size that can be sent [grpc_server_max_send_msg_size: | default = 4194304] # Limit on the number of concurrent streams for gRPC calls (0 = unlimited) [grpc_server_max_concurrent_streams: | default = 100] # Log only messages with the given severity or above. Supported values [debug, # info, warn, error] [log_level: | default = "info"] # Base path to server all API routes from (e.g., /v1/). [http_path_prefix: ] # Target managers check flag for promtail readiness, if set to false the check is ignored [health_check_target: | default = true] ``` ## client_config The `client_config` block configures how Promtail connects to an instance of Loki: ```yaml # The URL where Loki is listening, denoted in Loki as http_listen_address and # http_listen_port. If Loki is running in microservices mode, this is the HTTP # URL for the Distributor. Path to the push API needs to be included. # Example: http://example.com:3100/loki/api/v1/push url: # The tenant ID used by default to push logs to Loki. If omitted or empty # it assumes Loki is running in single-tenant mode and no X-Scope-OrgID header # is sent. [tenant_id: ] # Maximum amount of time to wait before sending a batch, even if that # batch isn't full. [batchwait: | default = 1s] # Maximum batch size (in bytes) of logs to accumulate before sending # the batch to Loki. [batchsize: | default = 102400] # 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: ] # 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] # 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] ``` ## position_config The `position_config` block configures where Promtail will save a file indicating how far it has read into a file. It is needed for when Promtail is restarted to allow it to continue from where it left off. ```yaml # Location of positions file [filename: | default = "/var/log/positions.yaml"] # How often to update the positions file [sync_period: | default = 10s] # Whether to ignore & later overwrite positions files that are corrupted [ignore_invalid_yaml: | default = false] ``` ## scrape_config The `scrape_config` block configures how Promtail can scrape logs from a series of targets using a specified discovery method: ```yaml # Name to identify this scrape config in the Promtail UI. job_name: # Describes how to parse log lines. Supported values [cri docker raw] # Deprecated in favor of pipeline_stages using the cri or docker stages. [entry_parser: | default = "docker"] # Describes how to transform logs from targets. [pipeline_stages: ] # Describes how to scrape logs from the journal. [journal: ] # Describes how to receive logs from syslog. [syslog: ] # Describes how to receive logs via the Loki push API, (e.g. from other Promtails or the Docker Logging Driver) [loki_push_api: ] # 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: - [] ``` ### pipeline_stages The [pipeline](../pipelines/) stages (`pipeline_stages`) is used to transform log entries and their labels after discovery and consists of a list of any of the items listed below. Stages serve several purposes, more detail can be found [here](../pipelines/), however generally you extract data with `regex` or `json` stages into a temporary map which can then be use as `labels` or `output` or any of the other stages aside from `docker` and `cri` which are explained in more detail below. ```yaml - [ | | | |