fix output file for diskUsage collector

This commit is contained in:
diamonwiggins
2022-05-12 04:20:24 +00:00
parent 3b1ba08a6b
commit e7f2685ed8
2 changed files with 13 additions and 13 deletions

View File

@@ -3,6 +3,7 @@ package analyzer
import (
"encoding/json"
"fmt"
"path/filepath"
"strconv"
"strings"
@@ -27,15 +28,18 @@ func (a *AnalyzeHostDiskUsage) IsExcluded() (bool, error) {
func (a *AnalyzeHostDiskUsage) Analyze(getCollectedFileContents func(string) ([]byte, error)) ([]*AnalyzeResult, error) {
hostAnalyzer := a.hostAnalyzer
key := collect.HostDiskUsageKey(hostAnalyzer.CollectorName)
contents, err := getCollectedFileContents(key)
name := filepath.Join("diskUsage", "diskUsage.json")
if hostAnalyzer.CollectorName != "" {
name = filepath.Join("diskUsage", hostAnalyzer.CollectorName+".json")
}
contents, err := getCollectedFileContents(name)
if err != nil {
return nil, errors.Wrapf(err, "failed to get collected file %s", key)
return nil, errors.Wrapf(err, "failed to get collected file %s", name)
}
diskUsageInfo := collect.DiskUsageInfo{}
if err := json.Unmarshal(contents, &diskUsageInfo); err != nil {
return nil, errors.Wrapf(err, "failed to unmarshal disk usage info from %s", key)
return nil, errors.Wrapf(err, "failed to unmarshal disk usage info from %s", name)
}
result := AnalyzeResult{

View File

@@ -34,7 +34,7 @@ func (c *CollectHostDiskUsage) Collect(progressChan chan<- interface{}) (map[str
result := map[string][]byte{}
if c.hostCollector == nil {
return result, nil
return map[string][]byte{}, nil
}
pathExists, err := traverseFiletreeDirExists(c.hostCollector.Path)
@@ -54,14 +54,14 @@ func (c *CollectHostDiskUsage) Collect(progressChan chan<- interface{}) (map[str
if err != nil {
return nil, errors.Wrap(err, "failed to marshal disk space info")
}
key := HostDiskUsageKey(c.hostCollector.CollectorName)
result[key] = b
collectorName := c.hostCollector.CollectorName
if collectorName == "" {
collectorName = "disk_usage"
collectorName = "diskUsage"
}
name := filepath.Join("system", collectorName+".json")
name := filepath.Join("diskUsage", collectorName+".json")
result[name] = b
output := NewResult()
output.SaveResult(c.BundlePath, name, bytes.NewBuffer(b))
@@ -69,10 +69,6 @@ func (c *CollectHostDiskUsage) Collect(progressChan chan<- interface{}) (map[str
return result, nil
}
func HostDiskUsageKey(name string) string {
return fmt.Sprintf("diskUsage/%s.json", name)
}
func traverseFiletreeDirExists(filename string) (string, error) {
filename = filepath.Clean(filename)
for i := 0; i < 50; i++ {