AliyunContainerService / log-pilot

Collect logs for docker containers
https://yq.aliyun.com/articles/674327
Apache License 2.0
1.43k stars 401 forks source link

log-pilot如何处理tomcat多行日志 #121

Open amoyx opened 6 years ago

amoyx commented 6 years ago

在kibana上显示的信息,发现catalina.out本来是一行的,变成多行显示,很不方便,要如何处理?

amoyx commented 6 years ago

labels:

chenquanzhao commented 6 years ago

@amoyx 采集日志时默认就是按行来采集的,您使用的是filebeat plugin吗?

amoyx commented 6 years ago

嗯,是 filebeat ,要如何把 catalina.out的多行日志合并成一行 @chenqz1987

crystonesc commented 6 years ago

希望有种办法能把filebeat的multiline给配置进filebeat才行

chenquanzhao commented 6 years ago

目前还不支持,后续我们考虑加入进去

amoyx commented 6 years ago

@chenqz1987 那Fluentd Plugin可以支持多行合并吗?

amoyx commented 6 years ago

@chenqz1987 你好,要怎样才可以把 tomcat多行日志合并成一行?

chenquanzhao commented 6 years ago

目前还不支持哈

Hewei6765 commented 6 years ago

把filebeat.tpl 配置 新增 multiline 即可 重新生成一个镜像 tomcat多行日志即可合并 vim filebeat.tpl {{range .configList}} ... multiline.pattern: '^[[:space:]]+(at|.{3})\b|^Caused by:' multiline.negate: false multiline.match: after multiline.max_lines: 10000 scan_frequency: 10s

amoyx commented 6 years ago

@qq676596084 是要把log-poilt镜像里面的 filebeat.tpl文件添加你上面的内容,对吧?

Hewei6765 commented 6 years ago

是的

amoyx commented 6 years ago

@qq676596084 你好大神,是改成图中的样子不? image

amoyx commented 6 years ago

@qq676596084 你好,按照上图的操作还是不能处理多行日志, 多行日志依然一行一行显示, 麻烦把你的 filebeat.tpl 贴出来看看,多谢!

Hewei6765 commented 6 years ago

@amoyx tim 20180905113722

效果:

tim 20180905114003

amoyx commented 6 years ago

@qq676596084 我的改完后,查询时如图所示: image

amoyx commented 6 years ago

没有你的好看, 全是json

major-jay commented 5 years ago

@amoyx 可以问下你什么版本的吗? 为什么我改了不生效 只需要重启Tomcat镜像吧 ?

Linuxbody commented 5 years ago

@qq676596084 @JDalready 这添加完那些 还是没生效,log-pilot:0.9.7-filebeat 镜像 启动的时候多了一行 image

但是下面看日志也收取到了,但是es里面完全没数据,不添加那几行就正常写入es image

dessler commented 5 years ago

@amoyx 蒂姆20180905113722

效果:

蒂姆20180905114003

我这里显示可以合并多行,但是好像at就只有几行 和真在的比at的行数要小很多

chenquanzhao commented 5 years ago

@qq676596084 欢迎提PR

nieqibest commented 4 years ago

@dessler 不是少了,你需要展开那条日志才能看到所有的at

currycan commented 4 years ago

你们用的什么版本?0.9.7吗? 我刚配置了一下:

{{range .configList}}
- type: log
  enabled: true
  paths:
      - {{ .HostDir }}/{{ .File }}
  multiline.pattern: '^[[:space:]]+(at|\.{3})[[:space:]]+\b|^Caused by:'
  multiline.negate: false
  multiline.match: after
  scan_frequency: 10s
  fields_under_root: true
  {{if .Stdout}}
  docker-json: true
  {{end}}
  {{if eq .Format "json"}}
  json.keys_under_root: true
  {{end}}
  fields:
      {{range $key, $value := .CustomFields}}
      {{ $key }}: {{ $value }}
      {{end}}
      {{range $key, $value := .Tags}}
      {{ $key }}: {{ $value }}
      {{end}}
      {{range $key, $value := $.container}}
      {{ $key }}: {{ $value }}
      {{end}}
  {{range $key, $value := .CustomConfigs}}
  {{ $key }}: {{ $value }}
  {{end}}
  tail_files: false
  close_inactive: 2h
  close_eof: false
  close_removed: true
  clean_removed: true
  close_renamed: false

{{end}}

错误日志如下: error-log

omegazeng commented 4 years ago

你们用的什么版本?0.9.7吗? 我刚配置了一下:

{{range .configList}}
- type: log
  enabled: true
  paths:
      - {{ .HostDir }}/{{ .File }}
  multiline.pattern: '^[[:space:]]+(at|\.{3})[[:space:]]+\b|^Caused by:'
  multiline.negate: false
  multiline.match: after
  scan_frequency: 10s
  fields_under_root: true
  {{if .Stdout}}
  docker-json: true
  {{end}}
  {{if eq .Format "json"}}
  json.keys_under_root: true
  {{end}}
  fields:
      {{range $key, $value := .CustomFields}}
      {{ $key }}: {{ $value }}
      {{end}}
      {{range $key, $value := .Tags}}
      {{ $key }}: {{ $value }}
      {{end}}
      {{range $key, $value := $.container}}
      {{ $key }}: {{ $value }}
      {{end}}
  {{range $key, $value := .CustomConfigs}}
  {{ $key }}: {{ $value }}
  {{end}}
  tail_files: false
  close_inactive: 2h
  close_eof: false
  close_removed: true
  clean_removed: true
  close_renamed: false

{{end}}

错误日志如下: error-log

我当年用的是 0.9.6, 你用0.9.7应该是一样的。你的操作步骤是怎样的,是按下面这位同学说的操作的吗?

把filebeat.tpl 配置 新增 multiline 即可 重新生成一个镜像 tomcat多行日志即可合并 vim filebeat.tpl {{range .configList}} ... multiline.pattern: '^[[:space:]]+(at|.{3})\b|^Caused by:' multiline.negate: false multiline.match: after multiline.max_lines: 10000 scan_frequency: 10s

currycan commented 4 years ago

@omegazeng 是的,我基于registry.cn-hangzhou.aliyuncs.com/acs/log-pilot:0.9.7-filebeat版本重做了一个镜像,替换filebeat.tpl文件,但是报错了。 正则表达式是参考:https://www.elastic.co/guide/en/beats/filebeat/current/multiline-examples.html#multiline-examples

omegazeng commented 4 years ago

@omegazeng 是的,我基于registry.cn-hangzhou.aliyuncs.com/acs/log-pilot:0.9.7-filebeat版本重做了一个镜像,替换filebeat.tpl文件,但是报错了。 正则表达式是参考:https://www.elastic.co/guide/en/beats/filebeat/current/multiline-examples.html#multiline-examples

替换filebeat.tpl文件报错了,什么意思?怎么替换的。 这个文件是在重新构建log-pilot镜像时替换的。 下面简单记录了我的操作。

首先根据自己业务的日志格式,编写用于匹配多行日志的正则,你参考的filebeat正则表达式文档是中还有用于测试正则的说明,可以在线测试你的日志内容和正则表达式 https://play.golang.org/p/uAd5XHxscu

重新构建log-pilot镜像

以下是我的模板文件和Dockerfile

{{end}}

* Dockerfile
```Dockerfile
FROM registry.cn-hangzhou.aliyuncs.com/acs/log-pilot:0.9.6-filebeat
COPY filebeat.tpl /pilot/

DaemonSet,把新构建的log-pilot更新到k8s中

currycan commented 4 years ago

@omegazeng 非常感谢!问题定位了! 正则表达式有问题,每个项目的的日志格式不一样,生成不了配置文件,容器内/etc/filebeat/prospectors.d目录始终为空。 日志格式有形如: 2020-06-03 11:34:22.499 ERROR 1 --- [nio-8210-exec-3] ....[2020-06-03 13:45:08.442] [ERROR] 1 [nio-9081-exec-1] [xLD59QzKldXfRhxj5GrR] .... 等好几种,接下来就是搞得格式问题了。再次感谢!

liqilong2017 commented 4 years ago

@omegazeng 非常感谢!问题定位了! 正则表达式有问题,每个项目的的日志格式不一样,生成不了配置文件,容器内/etc/filebeat/prospectors.d目录始终为空。 日志格式有形如: 2020-06-03 11:34:22.499 ERROR 1 --- [nio-8210-exec-3] ....[2020-06-03 13:45:08.442] [ERROR] 1 [nio-9081-exec-1] [xLD59QzKldXfRhxj5GrR] .... 等好几种,接下来就是搞得格式问题了。再次感谢!

你好,我新加了多行配置的三行,然后也是 /etc/filebeat/prospectors.d目录始终为空,正则应该没有问题,,,想问下 有什么思路吗?谢谢

liqilong2017 commented 4 years ago

@currycan 你好,不再报错了?? template: pilot:18:30: executing "pilot" at <.CustomFields>: can't evaluate field CustomFields in type *pilot.LogConfig" 0.9.7 我这边还是这样啊

hulu20 commented 3 years ago

@currycan 你好,不再报错了?? template: pilot:18:30: executing "pilot" at <.CustomFields>: can't evaluate field CustomFields in type *pilot.LogConfig" 0.9.7 我这边还是这样啊

使用v0.9.6 配置没有问题,v0.9.7 配置会报错,删除filebeat.tpl 中关于CustomFields 配置即可

      {{range $key, $value := .CustomFields}}
      {{ $key }}: {{ $value }}
      {{end}}

可以直使用官方镜像,把filebeat.tpl 导入configmaps,直接挂载到/pilot/下,无需重新构建镜像

kubectl create configmap filebeat-tpl --from-file=filebeat.tpl -n efk

vim log-pilot.yaml

...
        ...
        image: registry.cn-hangzhou.aliyuncs.com/acs/log-pilot:0.9.7-filebeat
        imagePullPolicy: IfNotPresent
        ...
        volumeMounts:
        ...
        - name: filebeat-tpl
          mountPath: /pilot/filebeat.tpl
          subPath: filebeat.tpl
      volumes:
      ...
      - name: filebeat-tpl
        configMap:
          name: filebeat-tpl
ascendlin commented 2 years ago

@omegazeng 非常感谢!问题定位了! 正则表达式有问题,每个项目的的日志格式不一样,生成不了配置文件,容器内/etc/filebeat/prospectors.d目录始终为空。 日志格式有形如: 2020-06-03 11:34:22.499 ERROR 1 --- [nio-8210-exec-3] ....[2020-06-03 13:45:08.442] [ERROR] 1 [nio-9081-exec-1] [xLD59QzKldXfRhxj5GrR] .... 等好几种,接下来就是搞得格式问题了。再次感谢!

每个项目日志格式不一致的时候,怎么配置的呢?

omegazeng commented 2 years ago

@ascendlin 每个项目不一致就不好处理了。还是推动改日志输出方式和日志格式吧。

polaris-gxf commented 2 years ago

针对k8s,应该把配置文件单独拿出来推荐一个configmap,不修改官方镜像就能配置。做到镜像和配置分离。