|
1 | 1 | #!/bin/bash |
2 | 2 | FLUENTD_CONF="/opt/fluentd/conf/fluentd.conf" |
3 | | -FLUENTD_FLUSH_INTERVAL=${FLUENTD_FLUSH_INTERVAL:-10s} |
4 | | -FLUENTD_FLUSH_THREADS=${FLUENTD_FLUSH_THREADS:-1} |
5 | | -FLUENTD_RETRY_LIMIT=${FLUENTD_RETRY_LIMIT:-10} |
6 | | -FLUENTD_DISABLE_RETRY_LIMIT=${FLUENTD_DISABLE_RETRY_LIMIT:-true} |
7 | | -FLUENTD_RETRY_WAIT=${FLUENTD_RETRY_WAIT:-1s} |
8 | | -FLUENTD_MAX_RETRY_WAIT=${FLUENTD_MAX_RETRY_WAIT:-60s} |
9 | | -FLUENTD_BUFFER_CHUNK_LIMIT=${FLUENTD_BUFFER_CHUNK_LIMIT:-8m} |
10 | | -FLUENTD_BUFFER_QUEUE_LIMIT=${FLUENTD_BUFFER_QUEUE_LIMIT:-8192} |
11 | | -FLUENTD_BUFFER_TYPE=${FLUENTD_BUFFER_TYPE:-memory} |
12 | | -FLUENTD_BUFFER_PATH=${FLUENTD_BUFFER_PATH:-/var/fluentd/buffer} |
13 | 3 |
|
14 | | -if [ -e "/var/log/containers" ] |
15 | | -then |
16 | | -cat << EOF >> $FLUENTD_CONF |
17 | | -<source> |
18 | | - @type tail |
19 | | - path /var/log/containers/*.log |
20 | | - pos_file /var/log/containers.log.pos |
21 | | - time_format %Y-%m-%dT%H:%M:%S.%NZ |
22 | | - tag kubernetes.* |
23 | | - format json |
24 | | - read_from_head false |
25 | | -</source> |
26 | | -
|
27 | | -# Example: |
28 | | -# Dec 21 23:17:22 gke-foo-1-1-4b5cbd14-node-4eoj startupscript: Finished running startup script /var/run/google.startup.script |
29 | | -<source> |
30 | | - @type tail |
31 | | - format syslog |
32 | | - path /var/log/startupscript.log |
33 | | - pos_file /var/log/startupscript.log.pos |
34 | | - tag startupscript |
35 | | -</source> |
36 | | -
|
37 | | -# Examples: |
38 | | -# time="2016-02-04T06:51:03.053580605Z" level=info msg="GET /containers/json" |
39 | | -# time="2016-02-04T07:53:57.505612354Z" level=error msg="HTTP Error" err="No such image: -f" statusCode=404 |
40 | | -<source> |
41 | | - @type tail |
42 | | - format /^time="(?<time>[^)]*)" level=(?<severity>[^ ]*) msg="(?<message>[^"]*)"( err="(?<error>[^"]*)")?( statusCode=($<status_code>\d+))?/ |
43 | | - time_format %Y-%m-%dT%H:%M:%S.%NZ |
44 | | - path /var/log/docker.log |
45 | | - pos_file /var/log/docker.log.pos |
46 | | - tag docker |
47 | | -</source> |
48 | | -
|
49 | | -# Example: |
50 | | -# 2016/02/04 06:52:38 filePurge: successfully removed file /var/etcd/data/member/wal/00000000000006d0-00000000010a23d1.wal |
51 | | -<source> |
52 | | - @type tail |
53 | | - # Not parsing this, because it doesn't have anything particularly useful to |
54 | | - # parse out of it (like severities). |
55 | | - format none |
56 | | - path /var/log/etcd.log |
57 | | - pos_file /var/log/etcd.log.pos |
58 | | - tag etcd |
59 | | -</source> |
60 | | -
|
61 | | -# Multi-line parsing is required for all the kube logs because very large log |
62 | | -# statements, such as those that include entire object bodies, get split into |
63 | | -# multiple lines by glog. |
64 | | -
|
65 | | -# Example: |
66 | | -# 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] |
67 | | -<source> |
68 | | - @type tail |
69 | | - format multiline |
70 | | - format_firstline /^\w\d{4}/ |
71 | | - format1 /^(?<severity>\w)(?<time>\d{4} [^\s]*)\s+(?<pid>\d+)\s+(?<source>[^ \]]+)\] (?<message>.*)/ |
72 | | - time_format %m%d %H:%M:%S.%N |
73 | | - path /var/log/kubelet.log |
74 | | - pos_file /var/log/kubelet.log.pos |
75 | | - tag kubelet |
76 | | -</source> |
77 | | -
|
78 | | -# Example: |
79 | | -# 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] |
80 | | -<source> |
81 | | - @type tail |
82 | | - format multiline |
83 | | - format_firstline /^\w\d{4}/ |
84 | | - format1 /^(?<severity>\w)(?<time>\d{4} [^\s]*)\s+(?<pid>\d+)\s+(?<source>[^ \]]+)\] (?<message>.*)/ |
85 | | - time_format %m%d %H:%M:%S.%N |
86 | | - path /var/log/kube-apiserver.log |
87 | | - pos_file /var/log/kube-apiserver.log.pos |
88 | | - tag kube-apiserver |
89 | | -</source> |
90 | | -
|
91 | | -# Example: |
92 | | -# I0204 06:55:31.872680 5 servicecontroller.go:277] LB already exists and doesn't need update for service kube-system/kube-ui |
93 | | -<source> |
94 | | - @type tail |
95 | | - format multiline |
96 | | - format_firstline /^\w\d{4}/ |
97 | | - format1 /^(?<severity>\w)(?<time>\d{4} [^\s]*)\s+(?<pid>\d+)\s+(?<source>[^ \]]+)\] (?<message>.*)/ |
98 | | - time_format %m%d %H:%M:%S.%N |
99 | | - path /var/log/kube-controller-manager.log |
100 | | - pos_file /var/log/kube-controller-manager.log.pos |
101 | | - tag kube-controller-manager |
102 | | -</source> |
103 | | -
|
104 | | -# Example: |
105 | | -# 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] |
106 | | -<source> |
107 | | - @type tail |
108 | | - format multiline |
109 | | - format_firstline /^\w\d{4}/ |
110 | | - format1 /^(?<severity>\w)(?<time>\d{4} [^\s]*)\s+(?<pid>\d+)\s+(?<source>[^ \]]+)\] (?<message>.*)/ |
111 | | - time_format %m%d %H:%M:%S.%N |
112 | | - path /var/log/kube-scheduler.log |
113 | | - pos_file /var/log/kube-scheduler.log.pos |
114 | | - tag kube-scheduler |
115 | | -</source> |
116 | | -EOF |
117 | | -else |
118 | | - echo "/var/log/containers does not exist in the container." |
119 | | -fi |
120 | | - |
121 | | - |
122 | | -if [ -n "$KUBERNETES_SERVICE_HOST" ] |
123 | | -then |
124 | | -cat << EOF >> $FLUENTD_CONF |
125 | | - <filter kubernetes.**> |
126 | | - @type kubernetes_metadata |
127 | | - kubernetes_url https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT} |
128 | | - bearer_token_file /var/run/secrets/kubernetes.io/serviceaccount/token |
129 | | - verify_ssl false |
130 | | - </filter> |
131 | | -EOF |
132 | | -fi |
| 4 | +source /opt/fluentd/sbin/sources |
| 5 | +source /opt/fluentd/sbin/filters/filters |
133 | 6 |
|
134 | 7 | cat << EOF >> $FLUENTD_CONF |
135 | 8 | <match **> |
136 | 9 | @type copy |
137 | 10 | EOF |
138 | 11 |
|
139 | | -if [ -n "$ELASTICSEARCH_HOST" ] |
140 | | -then |
141 | | - echo "Starting fluentd with elastic search configuration!" |
142 | | - ELASTICSEARCH_PORT=${ELASTICSEARCH_PORT:-9200} |
143 | | - ELASTICSEARCH_SCHEME=${ELASTICSEARCH_SCHEME:-http} |
144 | | - |
145 | | -cat << EOF >> $FLUENTD_CONF |
146 | | -<store> |
147 | | - @type elasticsearch |
148 | | - log_level warn |
149 | | - include_tag_key true |
150 | | - time_key time |
151 | | - host ${ELASTICSEARCH_HOST} |
152 | | - port ${ELASTICSEARCH_PORT} |
153 | | - scheme ${ELASTICSEARCH_SCHEME} |
154 | | - $([ -n "${ELASTICSEARCH_USER}" ] && echo user ${ELASTICSEARCH_USER}) |
155 | | - $([ -n "${ELASTICSEARCH_PASSWORD}" ] && echo password ${ELASTICSEARCH_PASSWORD}) |
156 | | - buffer_type ${FLUENTD_BUFFER_TYPE} |
157 | | - $([ "${FLUENTD_BUFFER_TYPE}" == "file" ] && echo buffer_path ${FLUENTD_BUFFER_PATH}) |
158 | | - buffer_chunk_limit ${FLUENTD_BUFFER_CHUNK_LIMIT} |
159 | | - buffer_queue_limit ${FLUENTD_BUFFER_QUEUE_LIMIT} |
160 | | - flush_interval ${FLUENTD_FLUSH_INTERVAL} |
161 | | - retry_limit ${FLUENTD_RETRY_LIMIT} |
162 | | - $([ "${FLUENTD_DISABLE_RETRY_LIMIT}" == "true" ] && echo disable_retry_limit) |
163 | | - retry_wait ${FLUENTD_RETRY_WAIT} |
164 | | - max_retry_wait ${FLUENTD_MAX_RETRY_WAIT} |
165 | | - num_threads ${FLUENTD_FLUSH_THREADS} |
166 | | -</store> |
167 | | -EOF |
168 | | -fi |
169 | | - |
170 | | -NUM=$(env | grep -oE '^(SYSLOG_HOST_\d*)' | wc -l) |
171 | | -for ((i=1; i<=$NUM; i++)) do |
172 | | -host=$(eval "echo \$SYSLOG_HOST_$i") |
173 | | -port=$(eval "echo \$SYSLOG_PORT_$i") |
174 | | -if [ -n "$host" ] |
175 | | -then |
176 | | -echo "Starting fluentd with syslog configuration! -- $host:$port" |
177 | | -cat << EOF >> $FLUENTD_CONF |
178 | | -<store> |
179 | | - @type remote_syslog |
180 | | - host $host |
181 | | - port $port |
182 | | - log_level warn |
183 | | -</store> |
184 | | -EOF |
185 | | -fi |
186 | | -done |
187 | | - |
188 | | -if [ -n "$SYSLOG_HOST" ] |
189 | | -then |
190 | | -echo "Starting fluentd with syslog configuration! -- $SYSLOG_HOST:$SYSLOG_PORT" |
191 | | -cat << EOF >> $FLUENTD_CONF |
192 | | -<store> |
193 | | - @type remote_syslog |
194 | | - host $SYSLOG_HOST |
195 | | - port $SYSLOG_PORT |
196 | | - log_level warn |
197 | | -</store> |
198 | | -EOF |
199 | | -fi |
| 12 | +source /opt/fluentd/sbin/stores/stores |
200 | 13 |
|
201 | 14 | cat << EOF >> $FLUENTD_CONF |
202 | | -<store> |
203 | | - @type deis |
204 | | -</store> |
205 | 15 | </match> |
206 | 16 | EOF |
207 | 17 |
|
|
0 commit comments