代码拉取完成,页面将自动刷新
// +build darwin freebsd linux openbsd windows
package filesystem
import (
"path/filepath"
"time"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/metricbeat/module/system"
sigar "github.com/elastic/gosigar"
)
type Config struct {
IgnoreTypes []string `config:"filesystem.ignore_types"`
}
type FileSystemStat struct {
sigar.FileSystemUsage
DevName string `json:"device_name"`
Mount string `json:"mount_point"`
UsedPercent float64 `json:"used_p"`
ctime time.Time
}
func GetFileSystemList() ([]sigar.FileSystem, error) {
fss := sigar.FileSystemList{}
if err := fss.Get(); err != nil {
return nil, err
}
// Ignore relative mount points, which are present for example
// in /proc/mounts on Linux with network namespaces.
filtered := fss.List[:0]
for _, fs := range fss.List {
if filepath.IsAbs(fs.DirName) {
filtered = append(filtered, fs)
continue
}
debugf("Filtering filesystem with relative mountpoint %+v", fs)
}
fss.List = filtered
return fss.List, nil
}
func GetFileSystemStat(fs sigar.FileSystem) (*FileSystemStat, error) {
stat := sigar.FileSystemUsage{}
if err := stat.Get(fs.DirName); err != nil {
return nil, err
}
filesystem := FileSystemStat{
FileSystemUsage: stat,
DevName: fs.DevName,
Mount: fs.DirName,
}
return &filesystem, nil
}
func AddFileSystemUsedPercentage(f *FileSystemStat) {
if f.Total == 0 {
return
}
perc := float64(f.Used) / float64(f.Total)
f.UsedPercent = system.Round(perc, .5, 4)
}
func GetFilesystemEvent(fsStat *FileSystemStat) common.MapStr {
return common.MapStr{
"device_name": fsStat.DevName,
"mount_point": fsStat.Mount,
"total": fsStat.Total,
"free": fsStat.Free,
"available": fsStat.Avail,
"files": fsStat.Files,
"free_files": fsStat.FreeFiles,
"used": common.MapStr{
"pct": fsStat.UsedPercent,
"bytes": fsStat.Used,
},
}
}
// Predicate is a function predicate for use with filesystems. It returns true
// if the argument matches the predicate.
type Predicate func(*sigar.FileSystem) bool
// Filter returns a filtered list of filesystems. The in parameter
// is used as the backing storage for the returned slice and is therefore
// modified in this operation.
func Filter(in []sigar.FileSystem, p Predicate) []sigar.FileSystem {
out := in[:0]
for _, fs := range in {
if p(&fs) {
out = append(out, fs)
}
}
return out
}
// BuildTypeFilter returns a predicate that returns false if the given
// filesystem has a type that matches one of the ignoreType values.
func BuildTypeFilter(ignoreType ...string) Predicate {
return func(fs *sigar.FileSystem) bool {
for _, fsType := range ignoreType {
// XXX (andrewkroh): SysTypeName appears to be used for non-Windows
// and TypeName is used exclusively for Windows.
if fs.SysTypeName == fsType || fs.TypeName == fsType {
return false
}
}
return true
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。