forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cluster_template.go
318 lines (278 loc) · 9.47 KB
/
cluster_template.go
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
package generator
var ClusterTemplate = `{{ if .clusterTarget.CurrentTarget }}
{{- if eq .clusterTarget.IncludeSystemComponent true }}
<source>
@type tail
path /var/lib/rancher/rke/log/*.log
pos_file /fluentd/log/fluentd-rke-logging.pos
time_format %Y-%m-%dT%H:%M:%S.%N
tag rke.*
format json
read_from_head true
</source>
<filter rke.**>
@type record_transformer
enable_ruby true
<record>
tag ${tag}
log_type k8s_infrastructure_container
driver rke
component ${tag_suffix[6].split("_")[0]}
container_id ${tag_suffix[6].split(".")[0]}
</record>
</filter>
<filter rke.*>
@type prometheus
<metric>
name fluentd_input_status_num_records_total
type counter
desc The total number of incoming records
<labels>
tag ${tag}
hostname ${hostname}
</labels>
</metric>
</filter>
{{end }}
<source>
@type tail
path /var/log/containers/*.log
pos_file /fluentd/log/fluentd-cluster-logging.pos
time_format %Y-%m-%dT%H:%M:%S
tag cluster.*
format json
read_from_head true
</source>
<filter cluster.**>
@type kubernetes_metadata
merge_json_log true
preserve_json_log true
</filter>
<filter cluster.**>
@type record_transformer
<record>
tag ${tag}
log_type k8s_normal_container
{{- range $k, $val := .clusterTarget.OutputTags }}
{{$k}} {{$val}}
{{end }}
</record>
</filter>
<filter cluster.**>
@type prometheus
<metric>
name fluentd_input_status_num_records_total
type counter
desc The total number of incoming records
<labels>
tag ${tag}
hostname ${hostname}
</labels>
</metric>
</filter>
{{- if eq .clusterTarget.IncludeSystemComponent false }}
<filter cluster.**>
@type grep
<exclude>
key $.kubernetes.namespace_name
pattern {{.clusterTarget.ExcludeNamespace}}
</exclude>
</filter>
{{end }}
{{- if eq .clusterTarget.CurrentTarget "syslog"}}
{{- if .clusterTarget.SyslogConfig.Token}}
<filter cluster.** cluster-custom.** {{ if eq .clusterTarget.IncludeSystemComponent true }}rke.**{{end }} >
@type record_transformer
<record>
tag ${tag} {{.clusterTarget.SyslogConfig.Token}}
</record>
</filter>
{{end }}
{{end }}
<match cluster.** cluster-custom.** {{ if eq .clusterTarget.IncludeSystemComponent true }}rke.**{{end }} >
@type copy
<store>
{{- if or (eq .clusterTarget.CurrentTarget "elasticsearch") (eq .clusterTarget.CurrentTarget "splunk") (eq .clusterTarget.CurrentTarget "syslog") (eq .clusterTarget.CurrentTarget "kafka") (eq .clusterTarget.CurrentTarget "fluentforwarder")}}
{{- if eq .clusterTarget.CurrentTarget "elasticsearch"}}
@type elasticsearch
include_tag_key true
{{- if and .clusterTarget.ElasticsearchConfig.AuthUserName .clusterTarget.ElasticsearchConfig.AuthPassword}}
user {{.clusterTarget.ElasticsearchConfig.AuthUserName}}
password {{.clusterTarget.ElasticsearchConfig.AuthPassword}}
{{- end }}
hosts {{.clusterTarget.ElasticsearchConfig.Endpoint}}
logstash_format true
logstash_prefix "{{.clusterTarget.ElasticsearchConfig.IndexPrefix}}"
logstash_dateformat {{.clusterTarget.ElasticsearchTemplateWrap.DateFormat}}
type_name "container_log"
{{- if eq .clusterTarget.ElasticsearchTemplateWrap.Scheme "https"}}
ssl_verify {{ .clusterTarget.ElasticsearchConfig.SSLVerify }}
ssl_version {{ .clusterTarget.ElasticsearchConfig.SSLVersion }}
{{- if .clusterTarget.ElasticsearchConfig.Certificate }}
ca_file {{ .certDir}}/cluster_{{.clusterName}}_ca.pem
{{end }}
{{- if and .clusterTarget.ElasticsearchConfig.ClientCert .clusterTarget.ElasticsearchConfig.ClientKey}}
client_cert {{ .certDir}}/cluster_{{.clusterName}}_client-cert.pem
client_key {{ .certDir}}/cluster_{{.clusterName}}_client-key.pem
{{end }}
{{- if .clusterTarget.ElasticsearchConfig.ClientKeyPass}}
client_key_pass {{.clusterTarget.ElasticsearchConfig.ClientKeyPass}}
{{end }}
{{end }}
{{end }}
{{- if eq .clusterTarget.CurrentTarget "splunk"}}
@type splunk_hec
host {{.clusterTarget.SplunkTemplateWrap.Host}}
port {{.clusterTarget.SplunkTemplateWrap.Port}}
token {{.clusterTarget.SplunkConfig.Token}}
{{- if .clusterTarget.SplunkConfig.Source}}
sourcetype {{.clusterTarget.SplunkConfig.Source}}
{{end }}
{{- if .clusterTarget.SplunkConfig.Index}}
default_index {{ .clusterTarget.SplunkConfig.Index }}
{{end }}
{{- if eq .clusterTarget.SplunkTemplateWrap.Scheme "https"}}
use_ssl true
ssl_verify {{ .clusterTarget.SplunkConfig.SSLVerify }}
{{- if .clusterTarget.SplunkConfig.Certificate }}
ca_file {{ .certDir}}/cluster_{{.clusterName}}_ca.pem
{{end }}
{{- if and .clusterTarget.SplunkConfig.ClientCert .clusterTarget.SplunkConfig.ClientKey}}
client_cert {{ .certDir}}/cluster_{{.clusterName}}_client-cert.pem
client_key {{ .certDir}}/cluster_{{.clusterName}}_client-key.pem
{{end }}
{{- if .clusterTarget.SplunkConfig.ClientKeyPass}}
client_key_pass {{ .clusterTarget.SplunkConfig.ClientKeyPass }}
{{end }}
{{end }}
{{end }}
{{- if eq .clusterTarget.CurrentTarget "kafka"}}
@type kafka_buffered
{{- if .clusterTarget.KafkaConfig.ZookeeperEndpoint }}
zookeeper {{.clusterTarget.KafkaTemplateWrap.Zookeeper}}
{{else}}
brokers {{.clusterTarget.KafkaTemplateWrap.Brokers}}
{{end }}
default_topic {{.clusterTarget.KafkaConfig.Topic}}
output_data_type "json"
output_include_tag true
output_include_time true
max_send_retries 3
{{- if .clusterTarget.KafkaConfig.Certificate }}
ssl_ca_cert {{ .certDir}}/cluster_{{.clusterName}}_ca.pem
{{end }}
{{- if and .clusterTarget.KafkaConfig.ClientCert .clusterTarget.KafkaConfig.ClientKey}}
ssl_client_cert {{ .certDir}}/cluster_{{.clusterName}}_client-cert.pem
ssl_client_cert_key {{ .certDir}}/cluster_{{.clusterName}}_client-key.pem
{{end }}
{{- if and .clusterTarget.KafkaConfig.SaslUsername .clusterTarget.KafkaConfig.SaslPassword}}
username {{.clusterTarget.KafkaConfig.SaslUsername}}
password {{.clusterTarget.KafkaConfig.SaslPassword}}
{{end }}
{{- if and (eq .clusterTarget.KafkaConfig.SaslType "scram") .clusterTarget.KafkaConfig.SaslScramMechanism}}
scram_mechanism {{.clusterTarget.KafkaConfig.SaslScramMechanism}}
{{- if eq .clusterTarget.KafkaTemplateWrap.IsSSL false}}
sasl_over_ssl false
{{end}}
{{end }}
{{end }}
{{- if eq .clusterTarget.CurrentTarget "syslog"}}
@type remote_syslog
host {{.clusterTarget.SyslogTemplateWrap.Host}}
port {{.clusterTarget.SyslogTemplateWrap.Port}}
severity {{.clusterTarget.SyslogTemplateWrap.WrapSeverity}}
protocol {{.clusterTarget.SyslogConfig.Protocol}}
{{- if .clusterTarget.SyslogConfig.Program }}
program {{.clusterTarget.SyslogConfig.Program}}
{{end }}
packet_size 65535
{{- if eq .clusterTarget.SyslogConfig.SSLVerify true}}
verify_mode 1
{{else }}
verify_mode 0
{{end }}
{{- if .clusterTarget.SyslogConfig.EnableTLS }}
tls true
{{- if .clusterTarget.SyslogConfig.Certificate }}
ca_file {{ .certDir}}/cluster_{{.clusterName}}_ca.pem
{{end }}
{{end }}
{{- if and .clusterTarget.SyslogConfig.ClientCert .clusterTarget.SyslogConfig.ClientKey}}
client_cert {{ .certDir}}/cluster_{{.clusterName}}_client-cert.pem
client_cert_key {{ .certDir}}/cluster_{{.clusterName}}_client-key.pem
{{end }}
{{end }}
{{- if eq .clusterTarget.CurrentTarget "fluentforwarder"}}
@type forward
{{- if .clusterTarget.FluentForwarderConfig.EnableTLS }}
transport tls
tls_verify_hostname true
tls_allow_self_signed_cert true
{{end }}
{{ if .clusterTarget.FluentForwarderConfig.Certificate }}
tls_cert_path {{ .certDir}}/cluster_{{.clusterName}}_ca.pem
{{end }}
{{- if .clusterTarget.FluentForwarderConfig.Compress }}
compress gzip
{{end }}
{{- if .clusterTarget.FluentForwarderTemplateWrap.EnableShareKey }}
<security>
self_hostname "#{Socket.gethostname}"
shared_key true
</security>
{{end }}
{{range $k, $val := .clusterTarget.FluentForwarderTemplateWrap.FluentServers }}
<server>
{{if $val.Hostname}}
name {{$val.Hostname}}
{{end }}
host {{$val.Host}}
port {{$val.Port}}
{{ if $val.SharedKey}}
shared_key {{$val.SharedKey}}
{{end }}
{{ if $val.Username}}
username {{$val.Username}}
{{end }}
{{ if $val.Password}}
password {{$val.Password}}
{{end }}
weight {{$val.Weight}}
{{if $val.Standby}}
standby
{{end }}
</server>
{{end }}
{{end }}
<buffer>
@type file
path /fluentd/log/buffer/cluster.buffer
flush_interval {{.clusterTarget.OutputFlushInterval}}s
flush_mode interval
flush_thread_count 8
{{- if eq .clusterTarget.CurrentTarget "splunk"}}
chunk_limit_size 8m
queued_chunks_limit_size 200
{{end }}
</buffer>
slow_flush_log_threshold 40.0
{{end }}
{{- if eq .clusterTarget.CurrentTarget "customtarget"}}
{{.clusterTarget.CustomTargetWrap.Content}}
{{end }}
</store>
<store>
@type prometheus
<metric>
name fluentd_output_status_num_records_total
type counter
desc The total number of outgoing records
<labels>
tag ${tag}
hostname ${hostname}
</labels>
</metric>
</store>
</match>
{{end }}
`