当前位置:网站首页>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
边栏推荐
- GaN图腾柱无桥 Boost PFC(单相)七-PFC占空比前馈
- 关于CPU缓冲行的理解
- Xctf mobile--rememberother problem solving
- alright alright alright
- 2022-02-11 practice of using freetsdb to build an influxdb cluster
- Xctf mobile--app2 problem solving
- 剑指 Offer 16. 数值的整数次方
- Sword finger offer 15 Number of 1 in binary
- Mysqlbetween implementation selects the data range between two values
- 2022-01-27 redis cluster cluster proxy predixy analysis
猜你喜欢

Low code platform international multilingual (I18N) technical solution

(latest version) WiFi distribution multi format + installation framework

Drop down refresh conflicts with recyclerview sliding (swiperefreshlayout conflicts with recyclerview sliding)

Brief introduction to mvcc

Glide question you cannot start a load for a destroyed activity
![[comprehensive question] [Database Principle]](/img/d7/8c51306bb390e0383a017d9097e1e5.png)
[comprehensive question] [Database Principle]

高效能人士的七个习惯

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

我的创作纪念日:五周年

Idea full text search shortcut ctr+shift+f failure problem
随机推荐
关于CPU缓冲行的理解
Create a dojo progress bar programmatically: Dojo ProgressBar
context. Getexternalfilesdir() is compared with the returned path
Xctf mobile--app1 problem solving
Loan calculator my pressure is high
IDEA 全文搜索快捷键Ctr+Shift+F失效问题
Differences between initial, inherit, unset, revert and all
Method overloading and rewriting
Xctf mobile--app2 problem solving
Dojo tutorials:getting started with deferrals source code and example execution summary
[exercise 5] [Database Principle]
mysqlbetween实现选取介于两个值之间的数据范围
[exercise 6] [Database Principle]
OpenHarmony应用开发之ETS开发方式中的Image组件
Express abstract classes and methods
Differences and connections between final and static
【数据库原理及应用教程(第4版|微课版)陈志泊】【SQLServer2012综合练习】
【R】【密度聚类、层次聚类、期望最大化聚类】
Enable SASL authentication for memcached
【習題五】【數據庫原理】

