利用pprof分析filebeat的cpu使用率过高
通过pprof调试filebeat因为filebeat是用go语言实现的,而go语言本身的基础库里面就包含pprof这个功能极其强大的性能分析工具,因此,在7.x版本中,beats家族的工具,都提供了以下参数,方便用户在出现问题的时候,对应用进行调试 12345678--cpuprofile FILEWrites CPU profile data to the specified file. This option is useful for troubleshooting Filebeat.-h, --helpShows help for the run command.--httpprof [HOST]:PORTStarts an http server for profiling. This option is useful for troubleshooting and profiling Filebeat.--memprofile FILEWrites memory profile data to the specified output file. This...
pprof调优学习
Go性能优化 测试代码: https://github.com/behappy-project/behappy-url-shortener Go语言项目中的性能优化主要有以下几个方面: CPU profile:报告程序的 CPU 使用情况,按照一定频率去采集应用程序在 CPU 和寄存器上面的数据 Memory Profile(Heap Profile):报告程序的内存使用情况 Block Profiling:报告 goroutines 不在运行状态的情况,可以用来分析和查找死锁等性能瓶颈 Goroutine Profiling:报告 goroutines 的使用情况,有哪些...
结合泛型和reflect写一个groupBy转map的工具类
1.18出来了,把之前一堆groupBy的代码拿出来用泛型改一下,效率可能略有下降,但是小频率使用,效果还行 **注:**这里的T必须是struct,而且key必须是string 123456789101112131415161718192021222324252627282930313233343536373839404142434445// GroupByMap 切片按key(字段)分组转mapfunc GroupByMap[T interface{}](values []*T, key string) map[string][]*T { mapObj := make(map[string][]*T) // 先去重 for _, groupKey := range removeRepeatedElement(values, key) { // 再过滤 arr := filter(values, key, groupKey) mapObj[groupKey] = arr } ...
结合gin配置统一结果响应,统一异常处理
定义统一响应体(包含code,msg,data和WithData/WithMsg方法)1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859package configimport ( "encoding/json" "net/http")var ( // OK OK = response(http.StatusOK, "ok"))type Response struct { Code int `json:"code"` // 错误码 Msg string `json:"msg"` // 错误描述 Data interface{} `json:"data"` // 返回数据}// 自定义响应信息func (res...
go指令大全
go指令大全
golang建立项目以及go-module和vendor的区别
windows下, $GOPATH默认安装位置为: c:\Users<user>\go 建立项目not a valid zip filegithub.com/shirou/gopsutil/process: zip: not a valid zip file 此类问题多是因为GOPROXY所导致。 使用https://mirrors.aliyun.com/goproxy/,direct的时候,在进行go build/go mod tidy等指令时就会出现此错误。 换成https://goproxy.cn,direct即可。 123456789101112131415161718192021$ mkdir go-example && cd go-example#GO111MODULE=on,使用go module,不使用GOPATH#GO111MODULE=off,使用GOPATH,不使用go...
robfig_cron_v3,cron工具类
包: https://github.com/robfig/cron123go get github.com/robfig/cron/v3@v3.0.0import "github.com/robfig/cron/v3" util123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104package utilimport ( "github.com/pkg/errors" cron "github.com/robfig/cron/v3" "sync")// Crontab crontab managertype Crontab struct...
记录解决golang操作es时证书安全验证问题
注: go-es包使用的是https://github.com/olivere/elastic当es配置了ssl,但是证书是自签证书,那可能在操作初始化es-client时候会报这样错误 certificate signed by unknown authority 这个问题我在issue中找到了答案 可以通过配置httpclient来忽略ssl验证 最终改造结果如下 1234var client *elastic.Clientvar host = "https://192.168.56.103:9200"var userName = "elastic"var passWord = "xiaowu" 12345678910111213141516171819202122var err errorhttpClient := &http.Client{Transport: &http.Transport{ TLSClientConfig:...
