代码拉取完成,页面将自动刷新
kube-state-metrics
based metricsets (#4253)
package state_container
import (
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/metricbeat/mb"
"github.com/elastic/beats/metricbeat/module/kubernetes/util"
dto "github.com/prometheus/client_model/go"
)
const (
// Nanocores conversion 10^9
nanocores = 1000000000
)
func eventMapping(families []*dto.MetricFamily) ([]common.MapStr, error) {
eventsMap := map[string]common.MapStr{}
for _, family := range families {
for _, metric := range family.GetMetric() {
container := util.GetLabel(metric, "container")
if container == "" {
continue
}
event, ok := eventsMap[container]
if !ok {
event = common.MapStr{}
eventsMap[container] = event
}
switch family.GetName() {
case "kube_pod_container_info":
event.Put(mb.ModuleDataKey+".pod.name", util.GetLabel(metric, "pod"))
event.Put(mb.ModuleDataKey+".namespace", util.GetLabel(metric, "namespace"))
event.Put(mb.NamespaceKey, "container")
event.Put("name", util.GetLabel(metric, "container"))
event.Put("id", util.GetLabel(metric, "container_id"))
event.Put("image", util.GetLabel(metric, "image"))
case "kube_pod_container_resource_limits_cpu_cores":
event.Put(mb.ModuleDataKey+".node.name", util.GetLabel(metric, "node"))
event.Put("cpu.limit.nanocores", metric.GetGauge().GetValue()*nanocores)
case "kube_pod_container_resource_requests_cpu_cores":
event.Put(mb.ModuleDataKey+".node.name", util.GetLabel(metric, "node"))
event.Put("cpu.request.nanocores", metric.GetGauge().GetValue()*nanocores)
case "kube_pod_container_resource_limits_memory_bytes":
event.Put(mb.ModuleDataKey+".node.name", util.GetLabel(metric, "node"))
event.Put("memory.limit.bytes", metric.GetGauge().GetValue())
case "kube_pod_container_resource_requests_memory_bytes":
event.Put(mb.ModuleDataKey+".node.name", util.GetLabel(metric, "node"))
event.Put("memory.request.bytes", metric.GetGauge().GetValue())
case "kube_pod_container_status_ready":
event.Put("status.ready", metric.GetGauge().GetValue() == 1)
case "kube_pod_container_status_restarts":
event.Put("status.restarts", metric.GetCounter().GetValue())
case "kube_pod_container_status_running":
if metric.GetGauge().GetValue() == 1 {
event.Put("status.phase", "running")
}
case "kube_pod_container_status_terminated":
if metric.GetGauge().GetValue() == 1 {
event.Put("status.phase", "terminate")
}
case "kube_pod_container_status_waiting":
if metric.GetGauge().GetValue() == 1 {
event.Put("status.phase", "waiting")
}
default:
// Ignore unknown metric
continue
}
}
}
var events []common.MapStr
for _, event := range eventsMap {
events = append(events, event)
}
return events, nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。