当前位置:网站首页>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
边栏推荐
- Simple use and precautions of kotlin's array array and set list
- 2022-01-27 research on the minimum number of redis partitions
- 最新版抽奖盲盒运营版
- [combinatorics] permutation and combination (multiple set permutation | multiple set full permutation | multiple set incomplete permutation all elements have a repetition greater than the permutation
- Deeply understand the mvcc mechanism of MySQL
- sitesCMS v3.0.2发布,升级JFinal等依赖
- 我的创作纪念日:五周年
- Sword finger offer 12 Path in matrix
- Ten workplace rules
- C graphical tutorial (Fourth Edition)_ Chapter 17 generic: genericsamplep315
猜你喜欢
基于同步坐标变换的谐波电流检测
有限状态机FSM
Sword finger offer 14- ii Cut rope II
对业务的一些思考
【数据库原理及应用教程(第4版|微课版)陈志泊】【第四章习题】
Node.js: express + MySQL的使用
低代码平台国际化多语言(i18n)技术方案
01 three solutions to knapsack problem (greedy dynamic programming branch gauge)
高效能人士的七个习惯
Seven second order ladrc-pll structure design of active disturbance rejection controller
随机推荐
Sword finger offer 14- ii Cut rope II
[Exercice 5] [principe de la base de données]
Ali & ant self developed IDE
有限状态机FSM
对业务的一些思考
[data mining review questions]
SLF4J 日志门面
[problem exploration and solution of one or more filters or listeners failing to start]
How to convert a decimal number to binary in swift
十條職場規則
Harmonic current detection based on synchronous coordinate transformation
【数据库原理复习题】
Gan totem column bridgeless boost PFC (single phase) seven PFC duty cycle feedforward
Everything comes to him who waits
[exercise 6] [Database Principle]
Exploration of sqoop1.4.4 native incremental import feature
Mysqlbetween implementation selects the data range between two values
【数据挖掘复习题】
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
Sword finger offer 15 Number of 1 in binary