1 Star 0 Fork 0

sqos/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
healthcheck.go 1.22 KB
一键复制 编辑 原始数据 按行查看 历史
package healthcheck
import (
dc "github.com/fsouza/go-dockerclient"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/metricbeat/mb"
"github.com/elastic/beats/metricbeat/module/docker"
)
func init() {
if err := mb.Registry.AddMetricSet("docker", "healthcheck", New, docker.HostParser); err != nil {
panic(err)
}
}
type MetricSet struct {
mb.BaseMetricSet
dockerClient *dc.Client
}
// New creates a new instance of the docker healthcheck MetricSet.
func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
config := docker.Config{}
if err := base.Module().UnpackConfig(&config); err != nil {
return nil, err
}
client, err := docker.NewDockerClient(base.HostData().URI, config)
if err != nil {
return nil, err
}
return &MetricSet{
BaseMetricSet: base,
dockerClient: client,
}, nil
}
// Fetch returns a list of all containers as events.
// This is based on https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/list-containers.
func (m *MetricSet) Fetch() ([]common.MapStr, error) {
// Fetch a list of all containers.
containers, err := m.dockerClient.ListContainers(dc.ListContainersOptions{})
if err != nil {
return nil, err
}
return eventsMapping(containers, m), nil
}
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