Skip to content

Commit

Permalink
Targets not required in promtail config
Browse files Browse the repository at this point in the history
  • Loading branch information
adityacs committed May 1, 2020
1 parent 272a89c commit 94f71ce
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
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

0 comments on commit 94f71ce

Please sign in to comment.