From 94f71cec5f5a6e6f08b69143b57b998bcec86f3a Mon Sep 17 00:00:00 2001 From: Aditya C S Date: Fri, 1 May 2020 12:36:45 +0530 Subject: [PATCH] Targets not required in promtail config --- docs/clients/promtail/configuration.md | 28 ++++++++++++++++++++++- pkg/promtail/targets/filetargetmanager.go | 8 ++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/docs/clients/promtail/configuration.md b/docs/clients/promtail/configuration.md index 8d94af299550..abdf11ebec81 100644 --- a/docs/clients/promtail/configuration.md +++ b/docs/clients/promtail/configuration.md @@ -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 @@ -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: diff --git a/pkg/promtail/targets/filetargetmanager.go b/pkg/promtail/targets/filetargetmanager.go index 09272c418932..e93d95a6480e 100644 --- a/pkg/promtail/targets/filetargetmanager.go +++ b/pkg/promtail/targets/filetargetmanager.go @@ -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{