td-agent.conf 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. # This configuration file for Fluentd / td-agent is used
  2. # to watch changes to Docker log files. The kubelet creates symlinks that
  3. # capture the pod name, namespace, container name & Docker container ID
  4. # to the docker logs for pods in the /var/log/containers directory on the host.
  5. # If running this fluentd configuration in a Docker container, the /var/log
  6. # directory should be mounted in the container.
  7. #
  8. # These logs are then submitted to Elasticsearch which assumes the
  9. # installation of the fluent-plugin-elasticsearch & the
  10. # fluent-plugin-kubernetes_metadata_filter plugins.
  11. # See https://github.com/uken/fluent-plugin-elasticsearch &
  12. # https://github.com/fabric8io/fluent-plugin-kubernetes_metadata_filter for
  13. # more information about the plugins.
  14. # Maintainer: Jimmi Dyson <jimmidyson@gmail.com>
  15. #
  16. # Example
  17. # =======
  18. # A line in the Docker log file might look like this JSON:
  19. #
  20. # {"log":"2014/09/25 21:15:03 Got request with path wombat\n",
  21. # "stream":"stderr",
  22. # "time":"2014-09-25T21:15:03.499185026Z"}
  23. #
  24. # The time_format specification below makes sure we properly
  25. # parse the time format produced by Docker. This will be
  26. # submitted to Elasticsearch and should appear like:
  27. # $ curl 'http://elasticsearch-logging:9200/_search?pretty'
  28. # ...
  29. # {
  30. # "_index" : "logstash-2014.09.25",
  31. # "_type" : "fluentd",
  32. # "_id" : "VBrbor2QTuGpsQyTCdfzqA",
  33. # "_score" : 1.0,
  34. # "_source":{"log":"2014/09/25 22:45:50 Got request with path wombat\n",
  35. # "stream":"stderr","tag":"docker.container.all",
  36. # "@timestamp":"2014-09-25T22:45:50+00:00"}
  37. # },
  38. # ...
  39. #
  40. # The Kubernetes fluentd plugin is used to write the Kubernetes metadata to the log
  41. # record & add labels to the log record if properly configured. This enables users
  42. # to filter & search logs on any metadata.
  43. # For example a Docker container's logs might be in the directory:
  44. #
  45. # /var/lib/docker/containers/997599971ee6366d4a5920d25b79286ad45ff37a74494f262e3bc98d909d0a7b
  46. #
  47. # and in the file:
  48. #
  49. # 997599971ee6366d4a5920d25b79286ad45ff37a74494f262e3bc98d909d0a7b-json.log
  50. #
  51. # where 997599971ee6... is the Docker ID of the running container.
  52. # The Kubernetes kubelet makes a symbolic link to this file on the host machine
  53. # in the /var/log/containers directory which includes the pod name and the Kubernetes
  54. # container name:
  55. #
  56. # synthetic-logger-0.25lps-pod_default_synth-lgr-997599971ee6366d4a5920d25b79286ad45ff37a74494f262e3bc98d909d0a7b.log
  57. # ->
  58. # /var/lib/docker/containers/997599971ee6366d4a5920d25b79286ad45ff37a74494f262e3bc98d909d0a7b/997599971ee6366d4a5920d25b79286ad45ff37a74494f262e3bc98d909d0a7b-json.log
  59. #
  60. # The /var/log directory on the host is mapped to the /var/log directory in the container
  61. # running this instance of Fluentd and we end up collecting the file:
  62. #
  63. # /var/log/containers/synthetic-logger-0.25lps-pod_default_synth-lgr-997599971ee6366d4a5920d25b79286ad45ff37a74494f262e3bc98d909d0a7b.log
  64. #
  65. # This results in the tag:
  66. #
  67. # var.log.containers.synthetic-logger-0.25lps-pod_default_synth-lgr-997599971ee6366d4a5920d25b79286ad45ff37a74494f262e3bc98d909d0a7b.log
  68. #
  69. # The Kubernetes fluentd plugin is used to extract the namespace, pod name & container name
  70. # which are added to the log message as a kubernetes field object & the Docker container ID
  71. # is also added under the docker field object.
  72. # The final tag is:
  73. #
  74. # kubernetes.var.log.containers.synthetic-logger-0.25lps-pod_default_synth-lgr-997599971ee6366d4a5920d25b79286ad45ff37a74494f262e3bc98d909d0a7b.log
  75. #
  76. # And the final log record look like:
  77. #
  78. # {
  79. # "log":"2014/09/25 21:15:03 Got request with path wombat\n",
  80. # "stream":"stderr",
  81. # "time":"2014-09-25T21:15:03.499185026Z",
  82. # "kubernetes": {
  83. # "namespace": "default",
  84. # "pod_name": "synthetic-logger-0.25lps-pod",
  85. # "container_name": "synth-lgr"
  86. # },
  87. # "docker": {
  88. # "container_id": "997599971ee6366d4a5920d25b79286ad45ff37a74494f262e3bc98d909d0a7b"
  89. # }
  90. # }
  91. #
  92. # This makes it easier for users to search for logs by pod name or by
  93. # the name of the Kubernetes container regardless of how many times the
  94. # Kubernetes pod has been restarted (resulting in a several Docker container IDs).
  95. #
  96. # TODO: Propagate the labels associated with a container along with its logs
  97. # so users can query logs using labels as well as or instead of the pod name
  98. # and container name. This is simply done via configuration of the Kubernetes
  99. # fluentd plugin but requires secrets to be enabled in the fluent pod. This is a
  100. # problem yet to be solved as secrets are not usable in static pods which the fluentd
  101. # pod must be until a per-node controller is available in Kubernetes.
  102. # Do not directly collect fluentd's own logs to avoid infinite loops.
  103. <match fluent.**>
  104. type null
  105. </match>
  106. # Example:
  107. # {"log":"[info:2016-02-16T16:04:05.930-08:00] Some log text here\n","stream":"stdout","time":"2016-02-17T00:04:05.931087621Z"}
  108. <source>
  109. type tail
  110. path /var/log/containers/*.log
  111. pos_file /var/log/es-containers.log.pos
  112. time_format %Y-%m-%dT%H:%M:%S.%NZ
  113. tag kubernetes.*
  114. format json
  115. read_from_head true
  116. </source>
  117. # Example:
  118. # 2015-12-21 23:17:22,066 [salt.state ][INFO ] Completed state [net.ipv4.ip_forward] at time 23:17:22.066081
  119. <source>
  120. type tail
  121. format /^(?<time>[^ ]* [^ ,]*)[^\[]*\[[^\]]*\]\[(?<severity>[^ \]]*) *\] (?<message>.*)$/
  122. time_format %Y-%m-%d %H:%M:%S
  123. path /var/log/salt/minion
  124. pos_file /var/log/es-salt.pos
  125. tag salt
  126. </source>
  127. # Example:
  128. # Dec 21 23:17:22 gke-foo-1-1-4b5cbd14-node-4eoj startupscript: Finished running startup script /var/run/google.startup.script
  129. <source>
  130. type tail
  131. format syslog
  132. path /var/log/startupscript.log
  133. pos_file /var/log/es-startupscript.log.pos
  134. tag startupscript
  135. </source>
  136. # Examples:
  137. # time="2016-02-04T06:51:03.053580605Z" level=info msg="GET /containers/json"
  138. # time="2016-02-04T07:53:57.505612354Z" level=error msg="HTTP Error" err="No such image: -f" statusCode=404
  139. <source>
  140. type tail
  141. format /^time="(?<time>[^)]*)" level=(?<severity>[^ ]*) msg="(?<message>[^"]*)"( err="(?<error>[^"]*)")?( statusCode=($<status_code>\d+))?/
  142. time_format %Y-%m-%dT%H:%M:%S.%NZ
  143. path /var/log/docker.log
  144. pos_file /var/log/es-docker.log.pos
  145. tag docker
  146. </source>
  147. # Example:
  148. # 2016/02/04 06:52:38 filePurge: successfully removed file /var/etcd/data/member/wal/00000000000006d0-00000000010a23d1.wal
  149. <source>
  150. type tail
  151. # Not parsing this, because it doesn't have anything particularly useful to
  152. # parse out of it (like severities).
  153. format none
  154. path /var/log/etcd.log
  155. pos_file /var/log/es-etcd.log.pos
  156. tag etcd
  157. </source>
  158. # Multi-line parsing is required for all the kube logs because very large log
  159. # statements, such as those that include entire object bodies, get split into
  160. # multiple lines by glog.
  161. # Example:
  162. # I0204 07:32:30.020537 3368 server.go:1048] POST /stats/container/: (13.972191ms) 200 [[Go-http-client/1.1] 10.244.1.3:40537]
  163. <source>
  164. type tail
  165. format multiline
  166. format_firstline /^\w\d{4}/
  167. format1 /^(?<severity>\w)(?<time>\d{4} [^\s]*)\s+(?<pid>\d+)\s+(?<source>[^ \]]+)\] (?<message>.*)/
  168. time_format %m%d %H:%M:%S.%N
  169. path /var/log/kubelet.log
  170. pos_file /var/log/es-kubelet.log.pos
  171. tag kubelet
  172. </source>
  173. # Example:
  174. # I0204 07:00:19.604280 5 handlers.go:131] GET /api/v1/nodes: (1.624207ms) 200 [[kube-controller-manager/v1.1.3 (linux/amd64) kubernetes/6a81b50] 127.0.0.1:38266]
  175. <source>
  176. type tail
  177. format multiline
  178. format_firstline /^\w\d{4}/
  179. format1 /^(?<severity>\w)(?<time>\d{4} [^\s]*)\s+(?<pid>\d+)\s+(?<source>[^ \]]+)\] (?<message>.*)/
  180. time_format %m%d %H:%M:%S.%N
  181. path /var/log/kube-apiserver.log
  182. pos_file /var/log/es-kube-apiserver.log.pos
  183. tag kube-apiserver
  184. </source>
  185. # Example:
  186. # I0204 06:55:31.872680 5 servicecontroller.go:277] LB already exists and doesn't need update for service kube-system/kube-ui
  187. <source>
  188. type tail
  189. format multiline
  190. format_firstline /^\w\d{4}/
  191. format1 /^(?<severity>\w)(?<time>\d{4} [^\s]*)\s+(?<pid>\d+)\s+(?<source>[^ \]]+)\] (?<message>.*)/
  192. time_format %m%d %H:%M:%S.%N
  193. path /var/log/kube-controller-manager.log
  194. pos_file /var/log/es-kube-controller-manager.log.pos
  195. tag kube-controller-manager
  196. </source>
  197. # Example:
  198. # W0204 06:49:18.239674 7 reflector.go:245] pkg/scheduler/factory/factory.go:193: watch of *api.Service ended with: 401: The event in requested index is outdated and cleared (the requested history has been cleared [2578313/2577886]) [2579312]
  199. <source>
  200. type tail
  201. format multiline
  202. format_firstline /^\w\d{4}/
  203. format1 /^(?<severity>\w)(?<time>\d{4} [^\s]*)\s+(?<pid>\d+)\s+(?<source>[^ \]]+)\] (?<message>.*)/
  204. time_format %m%d %H:%M:%S.%N
  205. path /var/log/kube-scheduler.log
  206. pos_file /var/log/es-kube-scheduler.log.pos
  207. tag kube-scheduler
  208. </source>
  209. #<filter kubernetes.**>
  210. # type kubernetes_metadata
  211. #</filter>
  212. # Example:
  213. # I0603 15:31:05.793605 6 cluster_manager.go:230] Reading config from path /etc/gce.conf
  214. <source>
  215. type tail
  216. format multiline
  217. multiline_flush_interval 5s
  218. format_firstline /^\w\d{4}/
  219. format1 /^(?<severity>\w)(?<time>\d{4} [^\s]*)\s+(?<pid>\d+)\s+(?<source>[^ \]]+)\] (?<message>.*)/
  220. time_format %m%d %H:%M:%S.%N
  221. path /var/log/glbc.log
  222. pos_file /var/log/es-glbc.log.pos
  223. tag glbc
  224. </source>
  225. # Example:
  226. # I0603 15:31:05.793605 6 cluster_manager.go:230] Reading config from path /etc/gce.conf
  227. <source>
  228. type tail
  229. format multiline
  230. multiline_flush_interval 5s
  231. format_firstline /^\w\d{4}/
  232. format1 /^(?<severity>\w)(?<time>\d{4} [^\s]*)\s+(?<pid>\d+)\s+(?<source>[^ \]]+)\] (?<message>.*)/
  233. time_format %m%d %H:%M:%S.%N
  234. path /var/log/cluster-autoscaler.log
  235. pos_file /var/log/es-cluster-autoscaler.log.pos
  236. tag cluster-autoscaler
  237. </source>
  238. <match **>
  239. type elasticsearch
  240. log_level info
  241. include_tag_key true
  242. host elasticsearch-logging
  243. port 9200
  244. logstash_format true
  245. # Set the chunk limit the same as for fluentd-gcp.
  246. buffer_chunk_limit 2M
  247. # Cap buffer memory usage to 2MiB/chunk * 32 chunks = 64 MiB
  248. buffer_queue_limit 32
  249. flush_interval 5s
  250. # Never wait longer than 5 minutes between retries.
  251. max_retry_wait 30
  252. # Disable the limit on the number of retries (retry forever).
  253. disable_retry_limit
  254. # Use multiple threads for processing.
  255. num_threads 8
  256. </match>