代码拉取完成,页面将自动刷新
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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。