filebeat+elasticsearch+kibana日志分析

1 默认配置

1.1 filebeat

filebeat-7.17.yml,从网关中下载k8s的配置,指定es和kibana的配置

        通过kibana查询可以查询到日志了,但此时还不知道具体怎么用。 

       

1.2 kibana

在Discover中创建索引格式:filebeat-*,得到如下图,可以看出acc-statement-server的日志最多。但里面的字段太多了,下面应该怎么看呢?

        再跟进查看日志,filebeat应该是每一样记录一次,这个浪费了很多存储空间。另外排查问题也并不好查。

  2 多行合并输出

如果使用默认的配置,每一行日志,就会产生一条记录。

2.1 filebeat

        增加多行规则匹配

        设置索引,符合条件走自己的索引,否则则为默认索引

output.elasticsearch:hosts: ['10.101.10.2:9200','10.101.10.3:9200','10.101.10.4:9200']username: ${ELASTICSEARCH_USERNAME}password: ${ELASTICSEARCH_PASSWORD}indices:- index: acc-accountbook-server-%{+yyyy.MM.dd}when.contains:kubernetes.container.name: acc-accountbook-server- index: acc-analysis-server-%{+yyyy.MM.dd}when.contains:kubernetes.container.name: acc-analysis-serverindex: filebeat-7.17.25-%{+yyyy.MM.dd}

        在kibana中跟进日志,发现少部分日志输出成功,大多失败,这是什么原因呢?

         为什么有些可以添加数据,有些不能呢

        调试发现,我在索引前面加上了eayc就可以了,看来问题就出现在索引策略

2.2 logback

        上面的时间分割,是需要logback配置与之对应。如我的系统日志打印出来的是这个,那么filebeat中就无法实现多行合并了。

        如下图修改logback配置。

2.3 pipeline

        在elasticsearch中创建pipeline,参考了【ELK】到【EFK】,【Filebeat】收集【SpringBoot】日志,但最终还是放弃了,还是按照k8s自带的格式,这样便于处理,不需要非得自定义格式。

PUT _ingest/pipeline/eayc_log_pipeline
{"description": "岁月云日志管道","processors": [{"remove": {"field": "agent.name","ignore_missing": true}},{"remove": {"field": "agent.ephemeral_id","ignore_missing": true}},{"remove": {"field": "log.file.path","ignore_missing": true}},{"remove": {"field": "input.type","ignore_missing": true}},{"remove": {"field": "kubernetes.node.labels.kubernetes_io/hostname","ignore_missing": true}},{"remove": {"field": "kubernetes.labels.k8s_kuboard_cn/layer","ignore_missing": true}},{"remove": {"field": "kubernetes.deployment.name","ignore_missing": true}},{"remove": {"field": "container.runtime","ignore_missing": true}},{"remove": {"field": "ecs.version","ignore_missing": true}},{"remove": {"field": "host.architecture","ignore_missing": true}},{"remove": {"field": "host.containerized","ignore_missing": true}},{"remove": {"field": "host.mac","ignore_missing": true}},{"remove": {"field": "host.os.codename","ignore_missing": true}},{"remove": {"field": "host.os.name","ignore_missing": true}},{"remove": {"field": "host.os.platform","ignore_missing": true}},{"remove": {"field": "kubernetes.labels.k8s_kuboard_cn/name","ignore_missing": true}},{"remove": {"field": "kubernetes.labels.pod-template-hash","ignore_missing": true}},{"remove": {"field": "kubernetes.namespace_uid","ignore_missing": true}},{"remove": {"field": "kubernetes.node.labels.beta_kubernetes_io/arch","ignore_missing": true}},{"remove": {"field": "kubernetes.node.labels.beta_kubernetes_io/os","ignore_missing": true}},{"remove": {"field": "log.flags","ignore_missing": true}},{"remove": {"field": "log.offset","ignore_missing": true}},{"remove": {"field": "kubernetes.container.id","ignore_missing": true}},{"remove": {"field": "kubernetes.pod.uid","ignore_missing": true}}]
}

        创建索引策略

PUT _ilm/policy/eayc_log_policy
{"policy": {"phases": {"hot": {"min_age": "0ms","actions": {"rollover": {"max_size": "50gb","max_age": "30d"}}},"delete": {"min_age": "90d","actions": {"delete": {}}}}}
}

2.4 elasticsearch     

  在k8s中启动filebeat中,查看filebeat的日志发现

2024-10-29T07:55:33.935Z        ERROR   [elasticsearch] elasticsearch/client.go:226     failed to perform any bulk index operations: 500 Internal Server Error: {"error":{"root_cause":[{"type":"illegal_state_exception","reason":"There are no ingest nodes in this cluster, unable to forward request to an ingest node."}],"type":"illegal_state_exception","reason":"There are no ingest nodes in this cluster, unable to forward request to an ingest node."},"status":500}

         则需要在elasticsearch.yml中增加配置

node.roles: [ingest]

        创建组合模板

PUT _component_template/filebeat_settings
{"template": {"settings": {"number_of_shards": 1,"number_of_replicas": 1}}
}PUT _component_template/filebeat_mappings
{"template": {"mappings": {"properties": {"@timestamp": {"type": "date"},"message": {"type": "text"}}}}
}PUT _component_template/eayc_mappings
{"template": {"mappings": {"properties": {"@timestamp": {"type": "date"},"message": {"type": "text"},"custom_field": {"type": "keyword"}}}}
}PUT _component_template/acc_mappings
{"template": {"mappings": {"properties": {"@timestamp": {"type": "date"},"message": {"type": "text"},"custom_field": {"type": "keyword"}}}}
}PUT _index_template/filebeat
{"index_patterns": ["filebeat-*"],"composed_of": ["filebeat_settings", "filebeat_mappings"],"priority": 100,"template": {"settings": {"index.lifecycle.name": "eayc_log_policy","index.lifecycle.rollover_alias": "filebeat-write"}}
}PUT _index_template/eayc
{"index_patterns": ["eayc-*"],"composed_of": ["filebeat_settings", "eayc_mappings"],"priority": 100,"template": {"settings": {"index.lifecycle.name": "eayc_log_policy","index.lifecycle.rollover_alias": "filebeat-write"}}
}PUT _index_template/acc
{"index_patterns": ["acc-*"],"composed_of": ["filebeat_settings", "acc_mappings"],"priority": 100,"template": {"settings": {"index.lifecycle.name": "eayc_log_policy","index.lifecycle.rollover_alias": "filebeat-write"}}
}

        接着再看acc添加进去了

        再看日志数据出来了

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/59159.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

XGBoost Regressor --- 论文实战

一、前言 在《机器学习论文复现实战---linear regression》中通过Pearson 相关性分析,去除了2个高相关性特征 "PN" 和 "AN" ,数据维度变为890*25。(数据集地址) 这里我们不做任何前期处理,直接就将数据放入 XGBRegressor 模型中进行训练了。 二、模型…

MySQL表的增删改查(CRUD1)

好兄弟们,有没有忘了咱们上节说的知识点呢?忘了也没关系,让我们开始复习吧!!! 上期我们介绍了数据类型,还有一些表的操作,我们常用的数据类型有:1.数值类型 tinyint …

C/C++ 知识点:声明与定义

文章目录 一、声明与定义1、声明(Declaration)2、定义(Definition)3、声明与定义的区别 前言: 在C编程中,声明(declaration)和定义(definition)是两个重要的概…

express搭建ts(TypeScript)运行环境

要在使用 TypeScript 的环境下运行一个简单的 Express 应用,可以使用 ts-node 直接运行 TypeScript 文件,而无需先将其编译为 JavaScript。以下是一个简单的示例,展示了如何设置和运行一个基本的 Express 应用。 步骤 1. 初始化项目&#x…

C++和OpenGL实现3D游戏编程【连载17】——着色器进阶(附源码)

🔥C++和OpenGL实现3D游戏编程【目录】 1、本节要实现的内容 在前面着色器初步一节我们了解了着色器的一些初步知识,通过顶点着色器和片段着色器显示出了一个彩色的立方体。我们这节课就来了解一些在着色器中显示纹理等一系列实用操作,同时了解一些进阶的图像渲染技术,比如…

【缓存与加速技术实践】Web缓存代理与CDN内容分发网络

文章目录 Web缓存代理Nginx配置缓存代理详细说明 CDN内容分发网络CDN的作用CDN的工作原理CDN内容的获取方式解决缓存集中过期的问题 Web缓存代理 作用: 缓存之前访问过的静态网页资源,以便在再次访问时能够直接从缓存代理服务器获取,减少源…

C++ | Leetcode C++题解之第520题检测大写字母

题目: 题解: class Solution { public:bool detectCapitalUse(string word) {// 若第 1 个字母为小写,则需额外判断第 2 个字母是否为小写if (word.size() > 2 && islower(word[0]) && isupper(word[1])) {return false;…

教育技术革新:SpringBoot在线试题库系统开发

2 相关技术 2.1 Spring Boot框架简介 Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程。该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置。通过这种方式,Sprin…

React + Vite + TypeScript + React router项目搭建教程

一、创建项目 运行项目 二、目录结构 项目目录: ├─node_modules //第三方依赖 ├─public //静态资源(不参与打包) └─src├─assets //静态资源├─components //组件├─config //配置├─http //请求方法封装├─layout //页面…

Android笔记(三十一):FrameLayout遇到的坑

背景 当FrameLayout里面是match_parent的时候,如果FrameLayout是wrap_content,则里面的view也会被当作wrap_content处理 原因 FrameLayout内的measureChildWithMargins -> getChildMeasureSpec的子类的MeasureSpec确定规则由父类的MeasureSpec和子类的LayoutP…

爬虫学习3

防盗链 #1.拿到conyId #2.拿到videoStatus返回的json.->srURL #srcURL里面的内容进行整理 #下载视频import requestsurl "https://www.pearvideo.com/video_1797054" contId url.split("_")[1]videoStatusUrl f"https://www.pearvideo.com/vi…

字典学习python

字典中的健可以添加,删除,但是不可以修改,只可以改后面的值 修改 字典名称[] value 若不存在健,那就添加,否则修改 pop删除,根据key实现对键值对,返回值是对应的value popitem返回值是一整个键…

QT-C++ 西门子snap7通讯库接口

QT-C 西门子snap7通讯库接口 一、核心程序1.头文件2.源文件 二、下载连接 一、核心程序 1.头文件 #pragma once #include <QObject> #include <QMutex> #include <QThread> #include "ToolSnapGlobal.h" #include "snap7.h" /* 特别说…

【设计模式】结构型模式(一):适配器模式、装饰器模式

结构型模式&#xff08;一&#xff09;&#xff1a;适配器模式、装饰器模式 1.适配器模式&#xff08;Adapter&#xff09;2.装饰器模式&#xff08;Decorator&#xff09;2.1 主要特点2.2 组成部分2.3 示例代码2.3.1 Component 组件2.3.2 ConcreteComponent 具体组件2.3.3 Dec…

认识物联网

新一代信息技术 物联网 物物相连的互联网&#xff0c;即物联网&#xff0c;又称传感器常见的传感器 • 温度传感器 • 压力传感器 • 声音传感器 • 02 • */08521 物联网概念 • 通过射频识别&#xff0c;红外传感器&#xff0c;全球定位系统GPS&#xff0c;激光扫描…

iOS 再谈KVC、 KVO

故事背景&#xff1a;大厂面试&#xff0c;又问道了基本的kvc kvo的原理和使用&#xff0c;由于转了前端&#xff0c;除了个setter和getter&#xff0c;我全忘记了&#xff0c;其实还是没有理解记忆&#xff0c;下面再看一下kvc 和kvo ,总结一个让人通过理解而无法忘记的方法&a…

07.适配器模式设计思想

07.适配器模式设计思想 目录介绍 01.适配器模式基础 1.1 适配器模式由来1.2 适配器模式定义1.3 适配器模式场景1.4 适配器模式思考 02.适配器模式实现 2.1 罗列一个场景2.2 用例子理解适配器2.3 适配器基本实现2.4 如何选择适配器 03.适配器模式分析 3.1 类适配器案例3.2 对象…

C语言 | Leetcode 题解之第535题TinyURL的加密与解密

题目&#xff1a; 题解&#xff1a; typedef struct {int key;char *val;UT_hash_handle hh; } HashItem;HashItem *dataBase NULL;char* encode(char* longUrl) {srand(time(0));int key;HashItem * pEntry NULL;while (true) {key rand();pEntry NULL;HASH_FIND_INT(dat…

Linux:线程安全的单例模式

设计模式 设计模式听上去是个很高贵的名词&#xff0c;其实就是是一套 多数人知晓、被反复使用、经过分类编目的、代码设计经验的总结&#xff0c;简称&#xff1a;对于编程比较典的场景的解决方案 单例模式 单例模式就是其中一种设计模式&#xff0c;是设计模式里的创建型模…

基于qt vs下的视频播放

**在 VS 2022 和 Qt 环境下利用 FFmpeg 实现一个基础视频播放器&#xff0c;需要完成以下几个步骤&#xff1a; 准备工作&#xff1a; 下载并配置 FFmpeg。确保 FFmpeg 的库和头文件可供 VS 2022 项目使用。 配置 Qt 项目&#xff0c;并导入 FFmpeg 库。 项目结构&#xff1a…