首页 > 其他分享 >filebeat篇章——解析 json 日志

filebeat篇章——解析 json 日志

时间:2023-04-24 11:57:28浏览次数:42  
标签:filebeat container logs kubernetes json 日志 log

解析 json 日志(Parsing json logs)

https://www.elastic.co/guide/en/beats/filebeat/8.7/running-on-kubernetes.html#_parsing_json_logs

  It is common case when collecting logs from workloads running on Kubernetes that these applications are logging in json format. In these case, special handling can be applied so as to parse these json logs properly and decode them into fields. Bellow there are provided 2 different ways of configuring filebeat’s autodiscover so as to identify and parse json logs. We will use an example of one Pod with 2 containers where only one of these logs in json format.

  在从运行在Kubernetes上的工作负载收集日志时,这些应用程序记录的内容通常都是json格式。在这种情况下,可以应用特殊处理,以正确解析这些json日志并将其解码为字段。下面提供了两种不同的方法来配置Filebeat的自动发现,以识别和解析json日志。我们将使用一个Pod示例,其中有2个容器,仅一个以json格式记录日志。 示例日志(选自 elastic.co)
{"type":"log","@timestamp":"2020-11-16T14:30:13+00:00","tags":["warning","plugins","licensing"],"pid":7,"message":"License information could not be obtained from Elasticsearch due to Error: No Living connections error"}

1、Using json.* options with templates.(使用带模版的 json.* 选项)

filebeat.autodiscover:
  providers:
      - type: kubernetes
        node: ${NODE_NAME}
        templates:
          - condition:
              contains:
                kubernetes.container.name: "no-json-logging"
            config:
              - type: container
                paths:
                  - "/var/log/containers/*-${data.kubernetes.container.id}.log"
          - condition:
              contains:
                kubernetes.container.name: "json-logging"
            config:
              - type: container
                paths:
                  - "/var/log/containers/*-${data.kubernetes.container.id}.log"
                json.keys_under_root: true
                json.add_error_key: true
                json.message_key: message

2、Using json.* options with hints.(使用带提示的 json.* 选项)

Key part here is to properly annotate the Pod to only parse logs of the correct container as json logs. In this, annotation should be constructed like this:

这里的关键部分是正确注释Pod,以仅解析正确容器的JSON日志。在此方面,注释应该像这样构建:
co.elastic.logs.<container_name>/json.keys_under_root: "true"

自动发现配置:

filebeat.autodiscover:
  providers:
    - type: kubernetes
      node: ${NODE_NAME}
      hints.enabled: true
      hints.default_config:
        type: container
        paths:
          - /var/log/containers/*${data.kubernetes.container.id}.log

然后正确注解 Pod:

annotations:
    co.elastic.logs.json-logging/json.keys_under_root: "true"
    co.elastic.logs.json-logging/json.add_error_key: "true"
    co.elastic.logs.json-logging/json.message_key: "message"

标签:filebeat,container,logs,kubernetes,json,日志,log
From: https://www.cnblogs.com/zuoyang/p/17348987.html

相关文章

  • sqlsever收缩数据库日志操作
    1、备份事务日志--->备份到其他盘;备份类型->事务日志 2、数据库---->数据库收缩---->文件类型:日志 ......
  • 在docker中查看对应k8s容器日志
    个人博客地址:https://note.raokun.top拥抱ChatGPT,国内访问网站:https://www.playchat.top最近遇到在不知道k8s环境只知道k8s部署的docker地址时,需要查看服务日志。dockerinspect容器id|greplog可查看对应的log地址......
  • filebeat篇章——QuitStart in K8S
    QuitStartinK8S---apiVersion:v1kind:ConfigMapmetadata:name:filebeat-script-confignamespace:ops-departmentlabels:k8s-app:filebeatdata:set-kafka-topic.js:|functionprocess(event){if(event.Get("kubernetes.name......
  • nginx 按天生成日志
    月小升记得以前nginx没有办法读取日期,今天找到个办法居然可以。server{location~\.php${fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;include/etc/nginx/fastcgi_params;fastcgi_pass......
  • elasticsearch+filebeat+kafka+kibana——filbeat篇章——overview
    filbeat篇章——overviewhttps://www.elastic.co/guide/en/beats/filebeat/8.7/filebeat-overview.html#filebeat-overview Filebeatisalightweightshipperforforwardingandcentralizinglogdata.Installedasanagentonyourservers,Filebeatmonitorsthelog......
  • SQLServer备份、完整备份,差异备份、日志备份
    1、https://blog.51cto.com/u_15907770/5926159https://product.pconline.com.cn/itbk/software/dnwt/1702/8821700.html全备份(FullBackup):就是对整个系统进行完全备份,包括系统和数据。这种备份方式的好处就是很直观,容易被人理解,当数据丢失时容易恢复。然而它也有不足之处:首先由......
  • .NET CORE开源 DDD微服务 支持 多租户 单点登录 多级缓存、自动任务、分布式、日志、
    源代码地址https://github.com/junkai-li/NetCoreKevin基于NET6搭建跨平台DDD思想WebApi架构、IDS4单点登录、多缓存、自动任务、分布式、多租户、日志、授权和鉴权、CAP、SignalR、docker部署 如需简约项目可直接去除项目引用解耦设计都可以单独引用架构默认全部引用并启动......
  • nginx日志中出现proxy_pass代理地址timeout
    背景:  开发发现测试环境业务异常,影响新需求上线,排查日志中发现nginx日志中出现proxy_pass代理地址timeout报错,直接使用代理地址curl没问题,重启nginx就好了。由于是开发自建自运维的nginx服务器,且出问题当天运维有对服务器进行审计操作,开发便把这口锅甩给我们运维人员!!!排查问题: ......
  • Idea日志中文乱码的解决办法
    背景:之前用的Idea的社区版,没有出现日志中文乱码的问题后来因为UI自动化的原因,安装了专业版,专业版出现了日志中文乱码的问题 使用了各种方法,在所有需要配置成UTF-8的地方都配置完成了依然无效对我来说无效或者不全面的方法见下列链接,应该是大家常能百度出来的方法IDEA控制......
  • PHP Warning: json_encode(): Invalid UTF-8 sequence in argument
    今天调试代码的时候发现json_encode()报错问题如下描述:问题代码:$requestData=json_encode(array('wechat_group_name'=>$wechat_group_name,'text_message'=>$text_message,//该值是中文一个拼接字符串));能后报错PHPWarning:json_encode():Inv......