Promtail is an agent which ships the contents of local logs to a private Prometheus instance. It can be used in conjunction with Loki to aggregate logs. Here's a cheatsheet for using Promtail.
Promtail can be installed on Linux, macOS, and Windows. See the official installation guide for detailed instructions.
Promtail is configured using a configuration file. The default configuration file is named promtail-local-config.yaml
.
Promtail defines targets to scrape logs from. Targets can be files, directories, or systemd
journal files.
Here's an example of how to scrape logs from a file:
scrape_configs:
- job_name: myjob
static_configs:
- targets:
- localhost
labels:
job: myjob
__path__: /var/log/mylog.log
Promtail adds labels to logs before sending them to Prometheus. Labels can be static or dynamic.
Here's an example of how to add a static label to logs:
scrape_configs:
- job_name: myjob
static_configs:
- targets:
- localhost
labels:
job: myjob
Here's an example of how to add a dynamic label to logs:
scrape_configs:
- job_name: myjob
pipeline_stages:
- match:
selector: '{job="myjob"}'
stages:
- regex:
expression: '(?P<my_label>my_regex)'
static_configs:
- targets:
- localhost
labels:
job: myjob
my_label: '{{.my_label}}'
Promtail defines pipeline stages to process logs before sending them to Prometheus. Pipeline stages can include matching, parsing, and labelling stages.
Here's an example of how to add a parsing stage to logs:
scrape_configs:
- job_name: myjob
pipeline_stages:
- match:
selector: '{job="myjob"}'
stages:
- json:
expressions:
message: '$.log'
static_configs:
- targets:
- localhost
labels:
job: myjob
Promtail integrates with various logging libraries to support logging in different languages. See the official integration documentation for details.