Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
424 changes: 212 additions & 212 deletions NOTICE.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ require (
github.com/elastic/go-sysinfo v1.7.0
github.com/elastic/go-txfile v0.0.7
github.com/elastic/go-ucfg v0.8.3
github.com/elastic/go-windows v1.0.1 // indirect
github.com/elastic/go-windows v1.0.1
github.com/elastic/gosigar v0.14.1
github.com/fatih/color v1.9.0
github.com/fsnotify/fsevents v0.1.1
Expand Down
171 changes: 0 additions & 171 deletions libbeat/metric/system/memory/memory.go

This file was deleted.

96 changes: 0 additions & 96 deletions libbeat/metric/system/memory/memory_test.go

This file was deleted.

29 changes: 21 additions & 8 deletions libbeat/metric/system/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"github.com/elastic/beats/v7/libbeat/common"
"github.com/elastic/beats/v7/libbeat/common/match"
"github.com/elastic/beats/v7/libbeat/logp"
"github.com/elastic/beats/v7/libbeat/metric/system/memory"
sysinfo "github.com/elastic/go-sysinfo"
sigar "github.com/elastic/gosigar"
"github.com/elastic/gosigar/cgroup"
)
Expand Down Expand Up @@ -234,22 +234,19 @@ func getProcEnv(pid int, out common.MapStr, filter func(v string) bool) error {
return nil
}

// GetProcMemPercentage returns process memory usage as a percent of total memory usage
func GetProcMemPercentage(proc *Process, totalPhyMem uint64) float64 {
// in unit tests, total_phymem is set to a value greater than zero
if totalPhyMem == 0 {
memStat, err := memory.Get()
if err != nil {
logp.Warn("Getting memory details: %v", err)
return 0
}
totalPhyMem = memStat.Mem.Total
return 0
}

perc := (float64(proc.Mem.Resident) / float64(totalPhyMem))

return common.Round(perc, 4)
}

// Pids returns a list of PIDs
func Pids() ([]int, error) {
pids := sigar.ProcList{}
err := pids.Get()
Expand Down Expand Up @@ -290,6 +287,22 @@ func GetOwnResourceUsageTimeInMillis() (int64, int64, error) {
}

func (procStats *Stats) getProcessEvent(process *Process) common.MapStr {
// This is a holdover until we migrate this library to metricbeat/internal
// At which point we'll use the memory code there.
var totalPhyMem uint64
host, err := sysinfo.Host()
if err != nil {
logp.Warn("Getting host details: %v", err)
} else {
memStats, err := host.Memory()
if err != nil {
logp.Warn("Getting memory details: %v", err)
} else {
totalPhyMem = memStats.Total
}

}

proc := common.MapStr{
"pid": process.Pid,
"ppid": process.Ppid,
Expand All @@ -301,7 +314,7 @@ func (procStats *Stats) getProcessEvent(process *Process) common.MapStr {
"size": process.Mem.Size,
"rss": common.MapStr{
"bytes": process.Mem.Resident,
"pct": GetProcMemPercentage(process, 0 /* read total mem usage */),
"pct": GetProcMemPercentage(process, totalPhyMem),
},
"share": process.Mem.Share,
},
Expand Down
12 changes: 12 additions & 0 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -44241,6 +44241,18 @@ format: bytes
The total amount of free memory in bytes. This value does not include memory consumed by system caches and buffers (see system.memory.actual.free).


type: long

format: bytes

--

*`system.memory.cached`*::
+
--
Total Cached memory on system.


type: long

format: bytes
Expand Down
Loading