1 Star 0 Fork 0

zhangjungang/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
diskio.go 1.42 KB
一键复制 编辑 原始数据 按行查看 历史
// +build darwin,cgo freebsd linux windows
package diskio
import (
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/metricbeat/mb"
"github.com/elastic/beats/metricbeat/mb/parse"
"github.com/pkg/errors"
"github.com/shirou/gopsutil/disk"
)
func init() {
if err := mb.Registry.AddMetricSet("system", "diskio", New, parse.EmptyHostParser); err != nil {
panic(err)
}
}
// MetricSet for fetching system disk IO metrics.
type MetricSet struct {
mb.BaseMetricSet
}
// New is a mb.MetricSetFactory that returns a new MetricSet.
func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
return &MetricSet{base}, nil
}
// Fetch fetches disk IO metrics from the OS.
func (m *MetricSet) Fetch() ([]common.MapStr, error) {
stats, err := disk.IOCounters()
if err != nil {
return nil, errors.Wrap(err, "disk io counters")
}
events := make([]common.MapStr, 0, len(stats))
for _, counters := range stats {
event := common.MapStr{
"name": counters.Name,
"read": common.MapStr{
"count": counters.ReadCount,
"time": counters.ReadTime,
"bytes": counters.ReadBytes,
},
"write": common.MapStr{
"count": counters.WriteCount,
"time": counters.WriteTime,
"bytes": counters.WriteBytes,
},
"io": common.MapStr{
"time": counters.IoTime,
},
}
events = append(events, event)
if counters.SerialNumber != "" {
event["serial_number"] = counters.SerialNumber
}
}
return events, nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhangjungang/beats.git
git@gitee.com:zhangjungang/beats.git
zhangjungang
beats
beats
v6.0.0-rc2

搜索帮助

0d507c66 1850385 C8b1a773 1850385