Caution
Grafana Alloy is the new name for our distribution of the OTel collector. Grafana Agent has been deprecated and is in Long-Term Support (LTS) through October 31, 2025. Grafana Agent will reach an End-of-Life (EOL) on November 1, 2025. Read more about why we recommend migrating to Grafana Alloy.
logs_config
The logs_config
block configures how the Agent collects logs and sends them to
a Loki push API endpoint. logs_config
is identical to how Promtail is
configured, except deprecated fields have been removed and the server_config is
not supported.
Refer to the Promtail documentation for the supported values for these fields.
# Directory to store Loki Promtail positions files in. Positions files are
# required to read logs, and are used to store the last read offset of log
# sources. The positions files will be stored in
# <positions_directory>/<logs_instance_config.name>.yml.
#
# Optional only if every config has a positions.filename manually provided.
#
# This directory will be automatically created if it doesn't exist.
[positions_directory: <string>]
# Configure values for all Loki Promtail instances.
[global: <global_config>]
# Loki Promtail instances to run for log collection.
configs:
- [<logs_instance_config>]
global_config
The global_config
block configures global values for all launched Loki Promtail
instances.
clients:
- [<promtail.client_config>]
# Configure how frequently log files from disk get polled for changes.
[file_watch_config: <file_watch_config>]
Note: More information on the following types can be found on the documentation for Promtail:
file_watch_config
The file_watch_config
block configures how often to poll log files from disk
for changes:
# Minimum frequency to poll for files. Any time file changes are detected, the
# poll frequency gets reset to this duration.
[min_poll_frequency: <duration> | default = "250ms"]
# Maximum frequency to poll for files. Any time no file changes are detected,
# the poll frequency doubles in value up to the maximum duration specified by
# this value.
#
# The default is set to the same as min_poll_frequency.
[max_poll_frequency: <duration> | default = "250ms"]
logs_instance_config
The logs_instance_config
block is an individual instance of Promtail with its
own set of scrape rules and where to forward logs. It is identical to how
Promtail is configured, except deprecated fields have been removed and the
server_config
block is not supported.
# Name of this config. Required, and must be unique across all Loki configs.
# The name of the config will be the value of a logs_config label for all
# Loki Promtail metrics.
name: <string>
clients:
- [<promtail.client_config>]
# Optional configuration for where to store the positions files. If
# positions.filename is left empty, the file will be stored in
# <logs_config.positions_directory>/<logs_instance_config.name>.yml.
#
# The directory of the positions file will automatically be created on start up
# if it doesn't already exist..
[positions: <promtail.position_config>]
scrape_configs:
- [<promtail.scrape_config>]
[target_config: <promtail.target_config>]
[limits_config: <promtail.limits_config>]
Note: More information on the following types can be found on the documentation for Promtail:
Note: Backticks in values are not supported.
Note: Because of how YAML treats backslashes in double-quoted strings, all backslashes in a regex expression must be escaped when using double quotes. But because of double processing, in Grafana Agent config file you must use quadruple backslash (
\\\\
) construction to add backslashes into regular expressions, here is example forname=(\w+)\s
regex:
selector: '{app="my-app"} |~ "name=(\\\\w+)\\\\s"'
Using single or double backslash construction produces the error:
failed to make file target manager: invalid match stage config: invalid selector syntax for match stage: parse error at line 1, col 40: literal not terminated
Using backticks produces the error:
invalid match stage config: invalid selector syntax for match stage: parse error at line 1, col 51: syntax error: unexpected IDENTIFIER, expecting STRING"