1 Star 0 Fork 0

sqos/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
data.go 1.68 KB
一键复制 编辑 原始数据 按行查看 历史
package state_deployment
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() {
deployment := util.GetLabel(metric, "deployment")
if deployment == "" {
continue
}
event, ok := eventsMap[deployment]
if !ok {
event = common.MapStr{}
eventsMap[deployment] = event
}
switch family.GetName() {
case "kube_deployment_metadata_generation":
event.Put(mb.ModuleDataKey+".namespace", util.GetLabel(metric, "namespace"))
event.Put(mb.NamespaceKey, "deployment")
event.Put("name", util.GetLabel(metric, "deployment"))
case "kube_deployment_spec_paused":
event.Put("paused", metric.GetGauge().GetValue() == 1)
case "kube_deployment_spec_replicas":
event.Put("replicas.desired", metric.GetGauge().GetValue())
case "kube_deployment_status_replicas_available":
event.Put("replicas.available", metric.GetGauge().GetValue())
case "kube_deployment_status_replicas_unavailable":
event.Put("replicas.unavailable", metric.GetGauge().GetValue())
case "kube_deployment_status_replicas_updated":
event.Put("replicas.updated", metric.GetGauge().GetValue())
default:
// Ignore unknown metric
continue
}
}
}
var events []common.MapStr
for _, event := range eventsMap {
events = append(events, event)
}
return events, nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sqos/beats.git
git@gitee.com:sqos/beats.git
sqos
beats
beats
v6.2.4

搜索帮助

0d507c66 1850385 C8b1a773 1850385