1 Star 0 Fork 0

sqos/beats

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
network.go 1.37 KB
Copy Edit Raw Blame History
package network
import (
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/common/cfgwarn"
"github.com/elastic/beats/metricbeat/mb"
"github.com/elastic/beats/metricbeat/module/docker"
dc "github.com/fsouza/go-dockerclient"
)
func init() {
if err := mb.Registry.AddMetricSet("docker", "network", New, docker.HostParser); err != nil {
panic(err)
}
}
type MetricSet struct {
mb.BaseMetricSet
netService *NetService
dockerClient *dc.Client
}
// New creates a new instance of the docker network MetricSet.
func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
cfgwarn.Beta("The docker network metricset is beta")
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,
netService: &NetService{
NetworkStatPerContainer: make(map[string]map[string]NetRaw),
},
}, nil
}
// Fetch methods creates a list of network events for each container.
func (m *MetricSet) Fetch() ([]common.MapStr, error) {
stats, err := docker.FetchStats(m.dockerClient, m.Module().Config().Timeout)
if err != nil {
return nil, err
}
formattedStats := m.netService.getNetworkStatsPerContainer(stats)
return eventsMapping(formattedStats), nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sqos/beats.git
git@gitee.com:sqos/beats.git
sqos
beats
beats
v6.0.0-beta1

Search