mirror of
https://github.com/replicatedhq/troubleshoot.git
synced 2026-02-14 18:29:53 +00:00
55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
package collect
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
|
|
"github.com/pkg/errors"
|
|
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
|
|
"github.com/shirou/gopsutil/v4/mem"
|
|
)
|
|
|
|
type MemoryInfo struct {
|
|
Total uint64 `json:"total"`
|
|
}
|
|
|
|
const HostMemoryPath = `host-collectors/system/memory.json`
|
|
const HostMemoryFileName = `memory.json`
|
|
|
|
type CollectHostMemory struct {
|
|
hostCollector *troubleshootv1beta2.Memory
|
|
BundlePath string
|
|
}
|
|
|
|
func (c *CollectHostMemory) Title() string {
|
|
return hostCollectorTitleOrDefault(c.hostCollector.HostCollectorMeta, "Amount of Memory")
|
|
}
|
|
|
|
func (c *CollectHostMemory) IsExcluded() (bool, error) {
|
|
return isExcluded(c.hostCollector.Exclude)
|
|
}
|
|
|
|
func (c *CollectHostMemory) Collect(progressChan chan<- interface{}) (map[string][]byte, error) {
|
|
memoryInfo := MemoryInfo{}
|
|
|
|
vmstat, err := mem.VirtualMemory()
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "failed to read virtual memory")
|
|
}
|
|
memoryInfo.Total = vmstat.Total
|
|
|
|
b, err := json.Marshal(memoryInfo)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "failed to marshal memory info")
|
|
}
|
|
|
|
output := NewResult()
|
|
output.SaveResult(c.BundlePath, HostMemoryPath, bytes.NewBuffer(b))
|
|
|
|
return output, nil
|
|
}
|
|
|
|
func (c *CollectHostMemory) RemoteCollect(progressChan chan<- interface{}) (map[string][]byte, error) {
|
|
return nil, ErrRemoteCollectorNotImplemented
|
|
}
|