1 Star 0 Fork 0

zhangjungang/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
data.go 2.41 KB
一键复制 编辑 原始数据 按行查看 历史
package container
import (
"encoding/json"
"fmt"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/metricbeat/mb"
"github.com/elastic/beats/metricbeat/module/kubernetes"
)
func eventMapping(content []byte) ([]common.MapStr, error) {
events := []common.MapStr{}
var summary kubernetes.Summary
err := json.Unmarshal(content, &summary)
if err != nil {
return nil, fmt.Errorf("Cannot unmarshal json response: %s", err)
}
node := summary.Node
for _, pod := range summary.Pods {
for _, container := range pod.Containers {
containerEvent := common.MapStr{
mb.ModuleDataKey: common.MapStr{
"namespace": pod.PodRef.Namespace,
"node": common.MapStr{
"name": node.NodeName,
},
"pod": common.MapStr{
"name": pod.PodRef.Name,
},
},
"name": container.Name,
"start_time": container.StartTime,
"cpu": common.MapStr{
"usage": common.MapStr{
"nanocores": container.CPU.UsageNanoCores,
"core": common.MapStr{
"ns": container.CPU.UsageCoreNanoSeconds,
},
},
},
"memory": common.MapStr{
"available": common.MapStr{
"bytes": container.Memory.AvailableBytes,
},
"usage": common.MapStr{
"bytes": container.Memory.UsageBytes,
},
"workingset": common.MapStr{
"bytes": container.Memory.WorkingSetBytes,
},
"rss": common.MapStr{
"bytes": container.Memory.RssBytes,
},
"pagefaults": container.Memory.PageFaults,
"majorpagefaults": container.Memory.MajorPageFaults,
},
"rootfs": common.MapStr{
"available": common.MapStr{
"bytes": container.Rootfs.AvailableBytes,
},
"capacity": common.MapStr{
"bytes": container.Rootfs.CapacityBytes,
},
"used": common.MapStr{
"bytes": container.Rootfs.UsedBytes,
},
"inodes": common.MapStr{
"used": container.Rootfs.InodesUsed,
},
},
"logs": common.MapStr{
"available": common.MapStr{
"bytes": container.Logs.AvailableBytes,
},
"capacity": common.MapStr{
"bytes": container.Logs.CapacityBytes,
},
"used": common.MapStr{
"bytes": container.Logs.UsedBytes,
},
"inodes": common.MapStr{
"used": container.Logs.InodesUsed,
"free": container.Logs.InodesFree,
"count": container.Logs.Inodes,
},
},
}
events = append(events, containerEvent)
}
}
return events, nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhangjungang/beats.git
git@gitee.com:zhangjungang/beats.git
zhangjungang
beats
beats
v6.1.4

搜索帮助