config.yaml 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # Promtail — file-based docker log discovery.
  2. #
  3. # Per DOCKER.md §1 we DO NOT touch the Docker daemon for log discovery
  4. # or tailing. No docker_sd_configs, no docker.sock mount. Instead we
  5. # read the json-file driver's output directly from
  6. # /var/lib/docker/containers/*/*-json.log — same data, zero daemon load.
  7. #
  8. # Filtering to "only briven containers" can't be done off the container
  9. # label (that would require asking the daemon). Instead we filter by
  10. # the JSON `service` label that briven services emit on every log line
  11. # via @briven/shared/observability. Non-briven containers don't produce
  12. # that JSON shape, so their lines flow through with `service` absent and
  13. # Loki queries naturally exclude them via the standard
  14. # `{service=~"api|runtime|realtime|web|docs"}` selector.
  15. server:
  16. http_listen_port: 9080
  17. grpc_listen_port: 0
  18. positions:
  19. filename: /tmp/positions.yaml
  20. clients:
  21. - url: http://briven-loki:3100/loki/api/v1/push
  22. scrape_configs:
  23. - job_name: docker-files
  24. # Static targets + __path__ glob is the Promtail idiom for file-based
  25. # discovery. No daemon involvement; Promtail tails the json files
  26. # directly via inotify on the host bind-mount.
  27. static_configs:
  28. - targets:
  29. - localhost
  30. labels:
  31. job: docker
  32. __path__: /var/lib/docker/containers/*/*-json.log
  33. pipeline_stages:
  34. # Each line in *-json.log is wrapped by the docker json-file
  35. # driver as: {"log":"<raw stdout line>\n","stream":"stdout","time":"..."}.
  36. # First parse unwraps the docker envelope.
  37. - json:
  38. expressions:
  39. output: log
  40. stream: stream
  41. time: time
  42. - timestamp:
  43. source: time
  44. format: RFC3339Nano
  45. - output:
  46. source: output
  47. - labels:
  48. stream:
  49. # Extract the container id from the file path so an operator can
  50. # at least correlate a line back to a specific container without
  51. # asking the daemon.
  52. - regex:
  53. source: filename
  54. expression: '/var/lib/docker/containers/(?P<container_id>[a-f0-9]{12})'
  55. - labels:
  56. container_id:
  57. # Now the wrapped `output` field holds the application's raw stdout.
  58. # For briven services that's our @briven/shared/observability JSON
  59. # shape; parse it to lift level/msg/service/env into labels.
  60. - json:
  61. expressions:
  62. level: level
  63. msg: msg
  64. service: service
  65. env: env
  66. - labels:
  67. level:
  68. service:
  69. env: