fix: Remove verbose logging from disk input plugin (#10527)
This commit is contained in:
parent
63d4a87eb1
commit
6ef39deda1
|
|
@ -64,6 +64,31 @@ func (s *SystemPS) CPUTimes(perCPU, totalCPU bool) ([]cpu.TimesStat, error) {
|
||||||
return cpuTimes, nil
|
return cpuTimes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type set struct {
|
||||||
|
m map[string]struct{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *set) empty() bool {
|
||||||
|
return len(s.m) == 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *set) add(key string) {
|
||||||
|
s.m[key] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *set) has(key string) bool {
|
||||||
|
var ok bool
|
||||||
|
_, ok = s.m[key]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
func newSet() *set {
|
||||||
|
s := &set{
|
||||||
|
m: make(map[string]struct{}),
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
func (s *SystemPS) DiskUsage(
|
func (s *SystemPS) DiskUsage(
|
||||||
mountPointFilter []string,
|
mountPointFilter []string,
|
||||||
fstypeExclude []string,
|
fstypeExclude []string,
|
||||||
|
|
@ -73,24 +98,23 @@ func (s *SystemPS) DiskUsage(
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make a "set" out of the filter slice
|
mountPointFilterSet := newSet()
|
||||||
mountPointFilterSet := make(map[string]bool)
|
|
||||||
for _, filter := range mountPointFilter {
|
for _, filter := range mountPointFilter {
|
||||||
mountPointFilterSet[filter] = true
|
mountPointFilterSet.add(filter)
|
||||||
}
|
}
|
||||||
fstypeExcludeSet := make(map[string]bool)
|
fstypeExcludeSet := newSet()
|
||||||
for _, filter := range fstypeExclude {
|
for _, filter := range fstypeExclude {
|
||||||
fstypeExcludeSet[filter] = true
|
fstypeExcludeSet.add(filter)
|
||||||
}
|
}
|
||||||
paths := make(map[string]bool)
|
paths := newSet()
|
||||||
for _, part := range parts {
|
for _, part := range parts {
|
||||||
paths[part.Mountpoint] = true
|
paths.add(part.Mountpoint)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Autofs mounts indicate a potential mount, the partition will also be
|
// Autofs mounts indicate a potential mount, the partition will also be
|
||||||
// listed with the actual filesystem when mounted. Ignore the autofs
|
// listed with the actual filesystem when mounted. Ignore the autofs
|
||||||
// partition to avoid triggering a mount.
|
// partition to avoid triggering a mount.
|
||||||
fstypeExcludeSet["autofs"] = true
|
fstypeExcludeSet.add("autofs")
|
||||||
|
|
||||||
var usage []*disk.UsageStat
|
var usage []*disk.UsageStat
|
||||||
var partitions []*disk.PartitionStat
|
var partitions []*disk.PartitionStat
|
||||||
|
|
@ -99,27 +123,15 @@ func (s *SystemPS) DiskUsage(
|
||||||
for i := range parts {
|
for i := range parts {
|
||||||
p := parts[i]
|
p := parts[i]
|
||||||
|
|
||||||
if s.Log != nil {
|
// If there is a filter set and if the mount point is not a
|
||||||
s.Log.Debugf("[SystemPS] partition %d: %v", i, p)
|
// member of the filter set, don't gather info on it.
|
||||||
}
|
if !mountPointFilterSet.empty() && !mountPointFilterSet.has(p.Mountpoint) {
|
||||||
|
continue
|
||||||
if len(mountPointFilter) > 0 {
|
|
||||||
// If the mount point is not a member of the filter set,
|
|
||||||
// don't gather info on it.
|
|
||||||
if _, ok := mountPointFilterSet[p.Mountpoint]; !ok {
|
|
||||||
if s.Log != nil {
|
|
||||||
s.Log.Debug("[SystemPS] => dropped by mount-point filter")
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the mount point is a member of the exclude set,
|
// If the mount point is a member of the exclude set,
|
||||||
// don't gather info on it.
|
// don't gather info on it.
|
||||||
if _, ok := fstypeExcludeSet[p.Fstype]; ok {
|
if fstypeExcludeSet.has(p.Fstype) {
|
||||||
if s.Log != nil {
|
|
||||||
s.Log.Debug("[SystemPS] => dropped by filesystem-type filter")
|
|
||||||
}
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -131,29 +143,22 @@ func (s *SystemPS) DiskUsage(
|
||||||
if hostMountPrefix != "" && !strings.HasPrefix(p.Mountpoint, hostMountPrefix) {
|
if hostMountPrefix != "" && !strings.HasPrefix(p.Mountpoint, hostMountPrefix) {
|
||||||
mountpoint = filepath.Join(hostMountPrefix, p.Mountpoint)
|
mountpoint = filepath.Join(hostMountPrefix, p.Mountpoint)
|
||||||
// Exclude conflicting paths
|
// Exclude conflicting paths
|
||||||
if paths[mountpoint] {
|
if paths.has(mountpoint) {
|
||||||
if s.Log != nil {
|
if s.Log != nil {
|
||||||
s.Log.Debug("[SystemPS] => dropped by mount prefix")
|
s.Log.Debugf("[SystemPS] => dropped by mount prefix (%q): %q", mountpoint, hostMountPrefix)
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if s.Log != nil {
|
|
||||||
s.Log.Debugf("[SystemPS] -> using mountpoint %q...", mountpoint)
|
|
||||||
}
|
|
||||||
|
|
||||||
du, err := s.PSDiskUsage(mountpoint)
|
du, err := s.PSDiskUsage(mountpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if s.Log != nil {
|
if s.Log != nil {
|
||||||
s.Log.Debugf("[SystemPS] => dropped by disk usage (%q): %v", mountpoint, err)
|
s.Log.Errorf("[SystemPS] => error getting disk usage (%q): %v", mountpoint, err)
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.Log != nil {
|
|
||||||
s.Log.Debug("[SystemPS] => kept...")
|
|
||||||
}
|
|
||||||
|
|
||||||
du.Path = filepath.Join("/", strings.TrimPrefix(p.Mountpoint, hostMountPrefix))
|
du.Path = filepath.Join("/", strings.TrimPrefix(p.Mountpoint, hostMountPrefix))
|
||||||
du.Fstype = p.Fstype
|
du.Fstype = p.Fstype
|
||||||
usage = append(usage, du)
|
usage = append(usage, du)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue