1 Star 0 Fork 0

sqos/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
fsstat.go 1.94 KB
一键复制 编辑 原始数据 按行查看 历史
// +build darwin freebsd linux openbsd windows
package fsstat
import (
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/metricbeat/mb"
"github.com/elastic/beats/metricbeat/mb/parse"
"github.com/elastic/beats/metricbeat/module/system/filesystem"
"github.com/pkg/errors"
)
var debugf = logp.MakeDebug("system-fsstat")
func init() {
if err := mb.Registry.AddMetricSet("system", "fsstat", New, parse.EmptyHostParser); err != nil {
panic(err)
}
}
// MetricSet for fetching a summary of filesystem stats.
type MetricSet struct {
mb.BaseMetricSet
}
// New creates and returns a new instance of MetricSet.
func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
return &MetricSet{
BaseMetricSet: base,
}, nil
}
// Fetch fetches filesystem metrics for all mounted filesystems and returns
// a single event containing aggregated data.
func (m *MetricSet) Fetch() (common.MapStr, error) {
fss, err := filesystem.GetFileSystemList()
if err != nil {
return nil, errors.Wrap(err, "filesystem list")
}
// These values are optional and could also be calculated by Kibana
var totalFiles, totalSize, totalSizeFree, totalSizeUsed uint64
dict := map[string]bool{}
for _, fs := range fss {
stat, err := filesystem.GetFileSystemStat(fs)
if err != nil {
debugf("error fetching filesystem stats for '%s': %v", fs.DirName, err)
continue
}
logp.Debug("fsstat", "filesystem: %s total=%d, used=%d, free=%d", stat.Mount, stat.Total, stat.Used, stat.Free)
if _, ok := dict[stat.Mount]; ok {
// ignore filesystem with the same mounting point
continue
}
totalFiles += stat.Files
totalSize += stat.Total
totalSizeFree += stat.Free
totalSizeUsed += stat.Used
dict[stat.Mount] = true
}
return common.MapStr{
"total_size": common.MapStr{
"free": totalSizeFree,
"used": totalSizeUsed,
"total": totalSize,
},
"count": len(dict),
"total_files": totalFiles,
}, nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sqos/beats.git
git@gitee.com:sqos/beats.git
sqos
beats
beats
v5.3.1

搜索帮助

0d507c66 1850385 C8b1a773 1850385