Sometimes people don't need advice, they just need someone to listen and care.
Toggle navigation
Home
Archives
Tags
About
Filebeat优化实践(二)
2018-07-25 06:53:27
1674
0
0
william
在上一篇[Filebeat优化实践](https://wilhelmguo.tk/blog/post/william/Filebeat%E4%BC%98%E5%8C%96%E5%AE%9E%E8%B7%B5)中谈到了自己开发Processor来获取Pod Name以及Deployment Name等信息,但由于使用的是正则解析日志文件名称的方式,获取到信息有限且有如果Kubernetes日志命名规则改变则无法正确获取日志信息的风险。 本次基于Filebeat v6.3.1版本重新设计了Filebeat的使用方式。 ## 使用官方的 add_kubernetes_metadata Process 在Filebeat配置文件中添加add_kubernetes_metadata相关配置如下 ```yaml - add_kubernetes_metadata: in_cluster: true include_labels: - app - k8s-app - k8s-ns include_annotations: - k8s.cloud/controller-kind matchers: - logs_path: logs_path: /var/log/containers ``` 输出日志结果如下 ```json { "@timestamp": "2018-07-23T07:18:59.712Z", "@metadata": { "beat": "filebeat", "type": "doc", "version": "6.3.0" }, "source": "/var/log/containers/infra-wayne-7b6786958f-tcsxk_default_wayne-a5113b31cd75d50fc93ae48ecf7c790e100c91f5fbe12850e465dd2de3d2282c.log", "offset": 74902, "log": "\u001b[0m\n", "stream": "stdout", "type": "k8s-log", "cluster": "shbt", "hostname": "docker4081", "prospector": { "type": "log" }, "input": { "type": "log" }, "kubernetes": { "container": { "name": "wayne" }, "pod": { "name": "infra-wayne-7b6786958f-tcsxk" }, "node": { "name": "docker4081" }, "namespace": "default", "labels": { "k8s-app": "infra", "k8s-ns": "infra", "app": "infra-wayne" }, "annotations": { "k8s": { "cloud/controller-kind": "deployment" } } }, "host": { "name": "kube-filebeat-wn2w6" }, "time": "2018-07-23T07:18:58.099250606Z" } ``` 其中k8s.cloud/controller-kind 是在Pod Template的annotation中添加的。由于公司内部统一使用Wayne管理平台发布应用,所以在每个Pod中添加相应的annotaion比较方便。 这样我们可以得到以下信息,PodName、ContainerName、AppName、Namespace、和ControllerKind,以便于日志分析。 ## 性能测试 上一篇中我们提到了对Filebeat做了一些性能改进,在新版中我们仍然使用相同的方法做一些性能测试。由于很多人问详细测试方法,这一篇我们对性能分析步骤详细讲解一下: - 设置Go进程数为1 ``` bash # 启动Filebeat时环境变量设置 GOMAXPROCS=1 ``` - filebeat启动参数设置开启调试模式 ``` bash filebeat -e --path.config=/data/usr --httpprof=:6060 ``` - 开启监控filebeat处理速率工具 ``` bash git clone https://github.com/urso/ljtest.git cd scripts && python ./expvar_rates.py url=http://127.0.0.1:6060/debug/vars ``` 在当前命令行窗口可以实时看到filebeat处理速率。  可以看到当前的处理速度已经达到 23000条/s ,跟之前优化后的性能接近。 - 使用go-torch分析性能 ``` bash go get github.com/uber/go-torch cd ${GOPATH}/src/github.com/uber/go-torch && git clone https://github.com/brendangregg/FlameGraph.git go-torch -u http://127.0.0.1:6060 ```  可以看到已经没有之前的common.MapStr.Clone() 性能消耗问题。官方已经改进了这个问题,相关代码如下: ``` go // Clone returns a copy of the MapStr. It recursively makes copies of inner // maps. func (m MapStr) Clone() MapStr { result := MapStr{} for k, v := range m { if innerMap, ok := tryToMapStr(v); ok { v = innerMap.Clone() } result[k] = v } return result } ... func tryToMapStr(v interface{}) (MapStr, bool) { switch m := v.(type) { case MapStr: return m, true case map[string]interface{}: return MapStr(m), true default: return nil, false } } ``` > 开启性能分析工具时一定要在filebteat正在处理文件时进行 ## 总结 v6.3.1版本官方已经改进了相关的性能问题,因此我们可以直接使用官方版本。如果官方版本提供的工具仍然无法满足自己的需求,可以自己开发相关个的Processor进行处理,相关步骤可以移步官网文档。
Pre:
Kubernetes最佳实践:优雅的终止
Next:
Kubernetes 1.11:集群内负载平衡和CoreDNS插件已经GA
0
likes
1674
Weibo
Wechat
Tencent Weibo
QQ Zone
RenRen
Please enable JavaScript to view the
comments powered by Disqus.
comments powered by
Disqus
Table of content