-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfluentd.conf.tmpl
54 lines (48 loc) · 2.21 KB
/
fluentd.conf.tmpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
{{range $key, $value := .}}
{{ $containerId := $value.ID }}
{{ $containerImage := $value.Image }}
{{ $usingECS := contains $value.Labels "com.amazonaws.ecs.task-definition-family" }}
{{ $usingDockerCompose := contains $value.Labels "com.docker.compose.project" }}
<source>
type tail
format json
time_format %Y-%m-%dT%H:%M:%S
path /var/lib/docker/containers/{{ $containerId }}/{{ $containerId }}-json.log
pos_file /var/lib/docker/containers/{{ $containerId }}/{{ $containerId }}-json.log.pos
tag docker.container.{{$containerId}}
refresh_interval 5
rotate_wait 5
</source>
<filter docker.container.{{$containerId}}>
type record_transformer
<record>
container_image {{$containerImage}}
container_id {{$containerId}}
environment "#{ENV['LOG_ENVIRONMENT']}"
ip_address "#{ENV['IP_ADDRESS']}"
{{ if $usingECS }}
container_project {{ index $value.Labels "com.amazonaws.ecs.task-definition-family" }}
container_service {{ index $value.Labels "com.amazonaws.ecs.container-name" }}
task_definition_version {{ index $value.Labels "com.amazonaws.ecs.task-definition-version" }}
{{ else if $usingDockerCompose }}
container_project {{ index $value.Labels "com.docker.compose.project" }}
container_service {{ index $value.Labels "com.docker.compose.service" }}
{{ end }}
</record>
</filter>
<match docker.container.{{$containerId}}>
type cloudwatch_logs
auto_create_stream true
include_time_key true
{{ if $usingECS }}
log_group_name "{{ index $value.Labels "com.amazonaws.ecs.task-definition-family" }}_#{ENV['LOG_ENVIRONMENT']}"
log_stream_name {{ index $value.Labels "com.amazonaws.ecs.container-name" }}_{{ $containerId }}
{{ else if $usingDockerCompose }}
log_group_name "{{ index $value.Labels "com.docker.compose.project" }}_#{ENV['LOG_ENVIRONMENT']}"
log_stream_name {{ index $value.Labels "com.docker.compose.service" }}_{{ $containerId }}
{{ else }}
log_group_name "ecs_host_#{ENV['LOG_ENVIRONMENT']}"
log_stream_name {{ printf "%s/%s/%s" $value.Image.Registry $value.Image.Repository $value.Image.Tag }}_{{ $containerId }}
{{ end }}
</match>
{{end}}