1 Star 0 Fork 0

zhangjungang/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
data.go 1.65 KB
一键复制 编辑 原始数据 按行查看 历史
package node
import (
"encoding/json"
"github.com/elastic/beats/libbeat/common"
s "github.com/elastic/beats/libbeat/common/schema"
c "github.com/elastic/beats/libbeat/common/schema/mapstriface"
"github.com/elastic/beats/metricbeat/mb"
)
var (
schema = s.Schema{
"name": c.Str("name"),
"version": c.Str("version"),
"jvm": c.Dict("jvm", s.Schema{
"version": c.Str("version"),
"memory": c.Dict("mem", s.Schema{
"heap": s.Object{
"init": s.Object{
"bytes": c.Int("heap_init_in_bytes"),
},
"max": s.Object{
"bytes": c.Int("heap_max_in_bytes"),
},
},
"nonheap": s.Object{
"init": s.Object{
"bytes": c.Int("non_heap_init_in_bytes"),
},
"max": s.Object{
"bytes": c.Int("non_heap_max_in_bytes"),
},
},
}),
}),
"process": c.Dict("process", s.Schema{
"mlockall": c.Bool("mlockall"),
}),
}
)
func eventsMapping(content []byte) ([]common.MapStr, error) {
nodesStruct := struct {
ClusterName string `json:"cluster_name"`
Nodes map[string]map[string]interface{} `json:"nodes"`
}{}
json.Unmarshal(content, &nodesStruct)
var events []common.MapStr
errors := s.NewErrors()
for name, node := range nodesStruct.Nodes {
event, errs := eventMapping(node)
// Write name here as full name only available as key
event["name"] = name
event[mb.ModuleDataKey] = common.MapStr{
"cluster": common.MapStr{
"name": nodesStruct.ClusterName,
},
}
events = append(events, event)
errors.AddErrors(errs)
}
return events, errors
}
func eventMapping(node map[string]interface{}) (common.MapStr, *s.Errors) {
return schema.Apply(node)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhangjungang/beats.git
git@gitee.com:zhangjungang/beats.git
zhangjungang
beats
beats
v6.1.2

搜索帮助