mirror of
https://github.com/replicatedhq/troubleshoot.git
synced 2026-04-15 07:16:34 +00:00
* Add HostPreflight v1beta2 * Work on TCP Load Balancer * Host disk usage collector and analyzer * Host memory analyzer * TCP port status * TCP load balancer * Review changes Co-authored-by: Marc Campbell <marc.e.campbell@gmail.com>
44 lines
943 B
Go
44 lines
943 B
Go
package collect
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"github.com/pkg/errors"
|
|
"github.com/shirou/gopsutil/disk"
|
|
)
|
|
|
|
type DiskUsageInfo struct {
|
|
TotalBytes uint64 `json:"total_bytes"`
|
|
UsedBytes uint64 `json:"used_bytes"`
|
|
}
|
|
|
|
func HostDiskUsage(c *HostCollector) (map[string][]byte, error) {
|
|
result := map[string][]byte{}
|
|
|
|
if c.Collect.DiskUsage == nil {
|
|
return result, nil
|
|
}
|
|
|
|
du, err := disk.Usage(c.Collect.DiskUsage.Path)
|
|
if err != nil {
|
|
return result, errors.Wrapf(err, "collect disk usage for %s", c.Collect.DiskUsage.Path)
|
|
}
|
|
diskSpaceInfo := DiskUsageInfo{
|
|
TotalBytes: du.Total,
|
|
UsedBytes: du.Used,
|
|
}
|
|
b, err := json.Marshal(diskSpaceInfo)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "failed to marshal disk space info")
|
|
}
|
|
key := HostDiskUsageKey(c.Collect.DiskUsage.CollectorName)
|
|
result[key] = b
|
|
|
|
return result, nil
|
|
}
|
|
|
|
func HostDiskUsageKey(name string) string {
|
|
return fmt.Sprintf("diskUsage/%s.json", name)
|
|
}
|