当前位置:网站首页>elk笔记24--用gohangout替代logstash消费日志
elk笔记24--用gohangout替代logstash消费日志
2022-07-03 12:21:00 【昕光xg】
elk笔记24--用gohangout替代logstash消费日志
介绍
gohangout 是 childe 大佬使用 golang 模仿的 Logstash 开源项目。用于消费 Kafka 数据,处理后写入 ES、Clickhouse 等。 相对于elk 中官方提供的 logstash, 其可以更加高效的利用 cpu 资源、降低内存,提高 IO 吞吐量。
笔者最近使用 logstash 处理项目中多个 k8s 集群的日志,发现随着业务量的增加,需要的 logstash 占用了较多资源,为了降低资源提高日志写入es 的效率,决定将logstash 替换为 hangout。将使用的效果、实施方法、注意事项记录在此处,以供有需要的小伙伴学习。
使用gohangout
此处使用gohangout消费kafka日志,然后将其写入到es中,gohangout部署在 k8s 集群。
Dockerfile
FROM alpine:3.15.4
RUN mkdir -p /home/
COPY . /home/
WORKDIR /home
RUN wget https://github.com/childe/gohangout/releases/download/v1.8.1/gohangout-linux-x64-91feead -O /home/gohangout && chmod u+x /home/gohangout
CMD sleep infinity
通过 docker build -t hangout:v1 . 打包镜像,并将其推送到镜像仓库(笔者为本地测试k8s, 直接在节点上打包镜像)。
启动配置文件 k8s-log.yaml
inputs:
- Kafka:
topic:
k8s-log: 1
codec: 'json'
consumer_settings:
bootstrap.servers: "192.168.2.11:9092"
group.id: 'logstash-k8s-log'
from.beginning: 'false'
auto.commit.interval.ms: '5000'
#auto.commit: 'false'
filters:
- Date:
src: time
target: "@timestamp"
formats:
- 'ISO8601'
- 'RFC3339'
remove_fields: ["time"]
outputs:
- Elasticsearch:
es_version: 7
hosts:
- 'http://es_user:[email protected]_ip:9200'
index: 'k8s_log_write' #golang里面的渲染方式就是用数字, 而不是用YYMM.
index_type: 'logs'
concurrent: 2
bulk_actions: 36000
bulk_size: 30
flush_interval: 30
k8s deployment hangout-k8s-log.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: hangout-k8s-log
name: hangout-k8s-log
namespace: default
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app: hangout-k8s-log
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
app: hangout-k8s-log
spec:
containers:
- command:
- /home/gohangout
- '-logtostderr'
- '-v'
- '5'
- '--config'
- k8s-log.yaml
image: hangout:v1
imagePullPolicy: IfNotPresent
name: hangout-k8s-log
resources:
limits:
cpu: '1'
memory: 2000Mi
requests:
cpu: 100m
memory: 200Mi
通过 kubectl apply -f hangout-k8s-log.yaml 把hangout势力拉起, 如下:
使用gohangout前后对比
第二节 使用gohangout 是笔者精简出来的一个案例,为了进一步凸显出使用效果,此处贴一部分实际项目中的数据,方便做对比。
hangout 和 logstash 对比,很明显 hangout 在稳定状态400MB左右内存即可稳定运行,而logstash 至少1GB起步; CPU 方面,hangout 利用率也比logstash 高。
| hangout | logstash |
|---|---|
![]() | ![]() |
ES集群QPS: 调整为 hangout 后,集群QPS从95K 快速上升到 160K。
kafka topic:topic 消费流量从 6M 提升到 12.5M左右,消费能力提高了一倍。
综上 CPU、内存、ES QPS、kafka 消费速率,很明显 hangout 性能比 logstash 优越。
当然 hangout 也有不足之处,即其支持的 插件比较少,logstash 中较复杂的 grok 匹配不一定容易快速转换为 hangout 支持的语法。
因此,实际项目中建议将一些量大,解析规则单一的索引调整为hangout(例如纯json类的日志)。
注意事项
- 实际生产环境中会有多个topic 和 多个index, 因此需要准备多个配置,打包的时候尽量打到一个镜像中,然后在 deployment 的command 中通过--config 来指定不同的实例。
/home/gohangout -logtostderr -v 5 --config k8s-log.yaml` - 部署hangout或者logstash 的时候可以考虑用deployment来部署,再配合HPA 动态伸缩就可以更加高效的消费 kafka 中的日志了。
说明
软件环境:
kafka_2.12-3.1.1
k8s 1.23.6
gohangout v1.8.1
elk 7.15
参考文档:
github gohangout
边栏推荐
- [exercise 6] [Database Principle]
- 2022-02-10 introduction to the design of incluxdb storage engine TSM
- Analysis of the influence of voltage loop on PFC system performance
- Kotlin notes - popular knowledge points asterisk (*)
- It feels great to know you learned something, isn‘t it?
- 如何在微信小程序中获取用户位置?
- 【習題七】【數據庫原理】
- (latest version) WiFi distribution multi format + installation framework
- Enter the length of three sides of the triangle through the user, and calculate the area of the triangle, where the length is a real number
- C graphical tutorial (Fourth Edition)_ Chapter 20 asynchronous programming: examples - cases without asynchronous
猜你喜欢

【Colab】【使用外部数据的7种方法】

Idea full text search shortcut ctr+shift+f failure problem

Xctf mobile--app2 problem solving

studio All flavors must now belong to a named flavor dimension. Learn more

Image component in ETS development mode of openharmony application development

ncnn神经网络计算框架在香橙派OrangePi 3 LTS开发板中的使用介绍

Node.js: express + MySQL的使用

GaN图腾柱无桥 Boost PFC(单相)七-PFC占空比前馈

Cache penetration and bloom filter

Analysis of a music player Login Protocol
随机推荐
[exercise 7] [Database Principle]
IDEA 全文搜索快捷键Ctr+Shift+F失效问题
Brief introduction to mvcc
Detailed explanation of the most complete constraintlayout in history
[data mining review questions]
ncnn神經網絡計算框架在香柳丁派OrangePi 3 LTS開發板中的使用介紹
2022-02-11 practice of using freetsdb to build an influxdb cluster
CVPR 2022 图像恢复论文
4. Wireless in vivo nano network: electromagnetic propagation model and key points of sensor deployment
Glide question you cannot start a load for a destroyed activity
sitesCMS v3.1.0发布,上线微信小程序
studio All flavors must now belong to a named flavor dimension. Learn more
C graphical tutorial (Fourth Edition)_ Chapter 13 entrustment: delegatesamplep245
Two solutions of leetcode101 symmetric binary tree (recursion and iteration)
有限状态机FSM
Seven second order ladrc-pll structure design of active disturbance rejection controller
Sword finger offer 16 Integer power of numeric value
mysqlbetween实现选取介于两个值之间的数据范围
[exercise 6] [Database Principle]
【数据库原理及应用教程(第4版|微课版)陈志泊】【第六章习题】

