Skip to content

Commit

Permalink
[metricbeat] first pass at adding vmstats to system/memory (elastic#1…
Browse files Browse the repository at this point in the history
…3322)

*  adding vmstats to system/memory
  • Loading branch information
fearful-symmetry authored Aug 29, 2019
1 parent db3ca50 commit eb5a3d7
Show file tree
Hide file tree
Showing 20 changed files with 558 additions and 81 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Add `metricset.period` field with the configured fetching period. {pull}13242[13242] {issue}12616[12616]
- Add rate metrics for ec2 metricset. {pull}13203[13203]
- Add Performance metricset to Oracle module {pull}12547[12547]
- Add proc/vmstat data to the system/memory metricset on linux {pull}13322[13322]

*Packetbeat*

Expand Down
4 changes: 2 additions & 2 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -820,8 +820,8 @@ Apache License 2.0

--------------------------------------------------------------------
Dependency: github.com/elastic/go-sysinfo
Version: v1.0.2
Revision: 06c1f463545498d8f4b378d4dcf3171794c28537
Version: v1.1.0
Revision: 51d9d1362d77a4792dfb39a7a19f056cdf1b9840
License type (autodetected): Apache-2.0
./vendor/github.com/elastic/go-sysinfo/LICENSE.txt:
--------------------------------------------------------------------
Expand Down
21 changes: 21 additions & 0 deletions libbeat/metric/system/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@
package memory

import (
"github.com/pkg/errors"

"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"
sysinfo "github.com/elastic/go-sysinfo"
sysinfotypes "github.com/elastic/go-sysinfo/types"
sigar "github.com/elastic/gosigar"
)

Expand Down Expand Up @@ -148,3 +152,20 @@ func AddHugeTLBPagesPercentage(s *HugeTLBPagesStat) {
perc := float64(s.Total-s.Free+s.Reserved) / float64(s.Total)
s.UsedPercent = common.Round(perc, common.DefaultDecimalPlacesCount)
}

// GetVMStat gets linux vmstat metrics
func GetVMStat() (*sysinfotypes.VMStatInfo, error) {
h, err := sysinfo.Host()
if err != nil {
return nil, errors.Wrap(err, "failed to read self process information")
}
if vmstatHandle, ok := h.(sysinfotypes.VMStat); ok {
info, err := vmstatHandle.VMStat()
if err != nil {
return nil, errors.Wrap(err, "error getting VMStat info")
}
return info, nil
}
return nil, nil

}
60 changes: 60 additions & 0 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -28371,6 +28371,42 @@ format: bytes
--
*`system.memory.swap.out.pages`*::
+
--
count of pages swapped out
type: long
--
*`system.memory.swap.in.pages`*::
+
--
count of pages swapped in
type: long
--
*`system.memory.swap.readahead.pages`*::
+
--
swap readahead pages
type: long
--
*`system.memory.swap.readahead.cached`*::
+
--
swap readahead cache hits
type: long
--
*`system.memory.swap.used.pct`*::
+
--
Expand Down Expand Up @@ -28473,6 +28509,30 @@ format: bytes
--
[float]
=== swap.out
huge pages swapped out
*`system.memory.hugepages.swap.out.pages`*::
+
--
pages swapped out
type: long
--
*`system.memory.hugepages.swap.out.fallback`*::
+
--
Count of huge pages that must be split before swapout
type: long
--
[float]
=== network
Expand Down
2 changes: 1 addition & 1 deletion metricbeat/module/system/fields.go

Large diffs are not rendered by default.

42 changes: 27 additions & 15 deletions metricbeat/module/system/memory/_meta/data.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
{
"@timestamp": "2017-10-12T08:05:34.853Z",
"agent": {
"hostname": "host.example.com",
"name": "host.example.com"
},
"event": {
"dataset": "system.memory",
"duration": 115000,
Expand All @@ -18,36 +14,52 @@
"system": {
"memory": {
"actual": {
"free": 4974256128,
"free": 671084544,
"used": {
"bytes": 11597463552,
"pct": 0.6998
"bytes": 362037248,
"pct": 0.3504
}
},
"free": 1320112128,
"free": 340848640,
"hugepages": {
"default_size": 2097152,
"free": 0,
"reserved": 0,
"surplus": 0,
"swap": {
"out": {
"fallback": 0,
"pages": 0
}
},
"total": 0,
"used": {
"bytes": 0,
"pct": 0
}
},
"swap": {
"free": 3482378240,
"total": 8589930496,
"free": 0,
"in": {
"pages": 0
},
"out": {
"pages": 0
},
"readahead": {
"cached": 0,
"pages": 0
},
"total": 0,
"used": {
"bytes": 5107552256,
"pct": 0.5946
"bytes": 0,
"pct": 0
}
},
"total": 16571719680,
"total": 1033121792,
"used": {
"bytes": 15251607552,
"pct": 0.9203
"bytes": 692273152,
"pct": 0.6701
}
}
}
Expand Down
27 changes: 27 additions & 0 deletions metricbeat/module/system/memory/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@
description: >
Available swap memory.
- name: out.pages
type: long
description: count of pages swapped out

- name: in.pages
type: long
description: count of pages swapped in

- name: readahead.pages
type: long
description: swap readahead pages

- name: readahead.cached
type: long
description: swap readahead cache hits

- name: used.pct
type: scaled_float
format: percent
Expand Down Expand Up @@ -131,3 +147,14 @@
format: bytes
description: >
Default size for huge pages.
- name: swap.out
type: group
description: huge pages swapped out
fields:
- name: pages
type: long
description: pages swapped out
- name: fallback
type: long
description: Count of huge pages that must be split before swapout
34 changes: 33 additions & 1 deletion metricbeat/module/system/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) error {
},
}

vmstat, err := mem.GetVMStat()
if err != nil {
return errors.Wrap(err, "VMStat")
}

swap := common.MapStr{
"total": swapStat.Total,
"used": common.MapStr{
Expand All @@ -83,6 +88,24 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) error {
},
"free": swapStat.Free,
}

if vmstat != nil {
// Swap in and swap out numbers
swap["in"] = common.MapStr{
"pages": vmstat.Pswpin,
}
swap["out"] = common.MapStr{
"pages": vmstat.Pswpout,
}
//Swap readahead
//See https://www.kernel.org/doc/ols/2007/ols2007v2-pages-273-284.pdf
swap["readahead"] = common.MapStr{
"pages": vmstat.SwapRa,
"cached": vmstat.SwapRaHit,
}

}

memory["swap"] = swap

hugePagesStat, err := mem.GetHugeTLBPages()
Expand All @@ -91,7 +114,7 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) error {
}
if hugePagesStat != nil {
mem.AddHugeTLBPagesPercentage(hugePagesStat)
memory["hugepages"] = common.MapStr{
thp := common.MapStr{
"total": hugePagesStat.Total,
"used": common.MapStr{
"bytes": hugePagesStat.TotalAllocatedSize,
Expand All @@ -102,6 +125,15 @@ func (m *MetricSet) Fetch(r mb.ReporterV2) error {
"surplus": hugePagesStat.Surplus,
"default_size": hugePagesStat.DefaultSize,
}
if vmstat != nil {
thp["swap"] = common.MapStr{
"out": common.MapStr{
"pages": vmstat.ThpSwpout,
"fallback": vmstat.ThpSwpoutFallback,
},
}
}
memory["hugepages"] = thp
}

r.Event(mb.Event{
Expand Down
10 changes: 9 additions & 1 deletion vendor/github.com/elastic/go-sysinfo/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions vendor/github.com/elastic/go-sysinfo/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/elastic/go-sysinfo/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit eb5a3d7

Please sign in to comment.