otel-collector-config.yml 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. receivers:
  2. filelog:
  3. include:
  4. - /var/log/pods/*/*/*.log
  5. exclude:
  6. # Exclude logs from all containers named otel-collector
  7. - /var/log/pods/*/otel-collector/*.log
  8. start_at: end
  9. include_file_path: true
  10. include_file_name: false
  11. operators:
  12. # Find out which format is used by kubernetes
  13. - type: router
  14. id: get-format
  15. routes:
  16. - output: parser-docker
  17. expr: 'body matches "^\\{"'
  18. - output: parser-crio
  19. expr: 'body matches "^[^ Z]+ "'
  20. - output: parser-containerd
  21. expr: 'body matches "^[^ Z]+Z"'
  22. # Parse CRI-O format
  23. - type: regex_parser
  24. id: parser-crio
  25. regex: '^(?P<time>[^ Z]+) (?P<stream>stdout|stderr) (?P<logtag>[^ ]*) ?(?P<log>.*)$'
  26. output: extract_metadata_from_filepath
  27. timestamp:
  28. parse_from: attributes.time
  29. layout_type: gotime
  30. layout: '2006-01-02T15:04:05.999999999Z07:00'
  31. # Parse CRI-Containerd format
  32. - type: regex_parser
  33. id: parser-containerd
  34. regex: '^(?P<time>[^ ^Z]+Z) (?P<stream>stdout|stderr) (?P<logtag>[^ ]*) ?(?P<log>.*)$'
  35. output: extract_metadata_from_filepath
  36. timestamp:
  37. parse_from: attributes.time
  38. layout: '%Y-%m-%dT%H:%M:%S.%LZ'
  39. # Parse Docker format
  40. - type: json_parser
  41. id: parser-docker
  42. output: extract_metadata_from_filepath
  43. timestamp:
  44. parse_from: attributes.time
  45. layout: '%Y-%m-%dT%H:%M:%S.%LZ'
  46. # Extract metadata from file path
  47. - type: regex_parser
  48. id: extract_metadata_from_filepath
  49. regex: '^.*\/(?P<namespace>[^_]+)_(?P<pod_name>[^_]+)_(?P<uid>[a-f0-9\-]{36})\/(?P<container_name>[^\._]+)\/(?P<restart_count>\d+)\.log$'
  50. parse_from: attributes["log.file.path"]
  51. cache:
  52. size: 128 # default maximum amount of Pods per Node is 110
  53. # Update body field after finishing all parsing
  54. - type: move
  55. from: attributes.log
  56. to: body
  57. # Rename attributes
  58. - type: move
  59. from: attributes.stream
  60. to: attributes["log.iostream"]
  61. - type: move
  62. from: attributes.container_name
  63. to: resource["k8s.container.name"]
  64. - type: move
  65. from: attributes.namespace
  66. to: resource["k8s.namespace.name"]
  67. - type: move
  68. from: attributes.pod_name
  69. to: resource["k8s.pod.name"]
  70. - type: move
  71. from: attributes.restart_count
  72. to: resource["k8s.container.restart_count"]
  73. - type: move
  74. from: attributes.uid
  75. to: resource["k8s.pod.uid"]
  76. exporters:
  77. debug:
  78. verbosity: detailed
  79. service:
  80. pipelines:
  81. logs:
  82. receivers: [filelog]
  83. exporters: [debug]