1 Star 0 Fork 0

sqos/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
data.go 1.63 KB
一键复制 编辑 原始数据 按行查看 历史
package healthcheck
import (
"strings"
dc "github.com/fsouza/go-dockerclient"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/metricbeat/mb"
"github.com/elastic/beats/metricbeat/module/docker"
)
func eventsMapping(containers []dc.APIContainers, m *MetricSet) []common.MapStr {
var events []common.MapStr
for _, container := range containers {
event := eventMapping(&container, m)
if event != nil {
events = append(events, event)
}
}
return events
}
func eventMapping(cont *dc.APIContainers, m *MetricSet) common.MapStr {
if !hasHealthCheck(cont.Status) {
return nil
}
container, err := m.dockerClient.InspectContainer(cont.ID)
if err != nil {
logp.Err("Error inpsecting container %v: %v", cont.ID, err)
return nil
}
lastEvent := len(container.State.Health.Log) - 1
// Checks if a healthcheck already happened
if lastEvent < 0 {
return nil
}
return common.MapStr{
mb.ModuleDataKey: common.MapStr{
"container": docker.NewContainer(cont).ToMapStr(),
},
"status": container.State.Health.Status,
"failingstreak": container.State.Health.FailingStreak,
"event": common.MapStr{
"start_date": common.Time(container.State.Health.Log[lastEvent].Start),
"end_date": common.Time(container.State.Health.Log[lastEvent].End),
"exit_code": container.State.Health.Log[lastEvent].ExitCode,
"output": container.State.Health.Log[lastEvent].Output,
},
}
}
// hasHealthCheck detects if healthcheck is available for container
func hasHealthCheck(status string) bool {
return strings.Contains(status, "(") && strings.Contains(status, ")")
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sqos/beats.git
git@gitee.com:sqos/beats.git
sqos
beats
beats
v6.2.4

搜索帮助

0d507c66 1850385 C8b1a773 1850385