Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Targets not required in promtail config #2026

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion docs/clients/promtail/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,8 @@ configuration.

```yaml
# Configures the discovery to look on the current machine. Must be either
# localhost or the hostname of the current computer.
# localhost or the hostname of the current computer. This is not a mandatory config
# and this can skipped.
targets:
- localhost

Expand Down Expand Up @@ -1078,6 +1079,31 @@ scrape_configs:
__path__: /var/log/*.log # The path matching uses a third party library: https://github.com/bmatcuk/doublestar
```

## Example Static Config without targets

While promtail may have been named for the prometheus service discovery code, that same code works very well for tailing logs without containers or container environments directly on virtual machines or bare metal.

```yaml
server:
http_listen_port: 9080
grpc_listen_port: 0

positions:
filename: /var/log/positions.yaml # This location needs to be writeable by promtail.

client:
url: http://ip_or_hostname_where_Loki_run:3100/loki/api/v1/push

scrape_configs:
- job_name: system
pipeline_stages:
static_configs:
- labels:
job: varlogs # A `job` label is fairly standard in prometheus and useful for linking metrics and logs.
host: yourhost # A `host` label will help identify logs from this machine vs others
__path__: /var/log/*.log # The path matching uses a third party library: https://github.com/bmatcuk/doublestar
```

## Example Journal Config

This example reads entries from a systemd journal:
Expand Down
8 changes: 7 additions & 1 deletion pkg/promtail/targets/filetargetmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,15 @@ func NewFileTargetManager(
}

// Add Source value to the static config target groups for unique identification
// within scrape pool.
// within scrape pool. Also, set dummy target if target is not defined in promtail config.
// Just to make sure prometheus target group sync works fine.
for i, tg := range cfg.ServiceDiscoveryConfig.StaticConfigs {
tg.Source = fmt.Sprintf("%d", i)
if len(tg.Targets) == 0 {
tg.Targets = []model.LabelSet{
{model.AddressLabel: "dummy"},
}
}
}

s := &targetSyncer{
Expand Down