Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for huge pages on Linux #6436

Merged
merged 2 commits into from
Mar 26, 2018
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
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ https://github.com/elastic/beats/compare/v6.0.0-beta2...master[Check the HEAD di
- Fix dealing with new process status codes in Linux kernel 4.14+. {pull}6306[6306]
- Add config option for windows/perfmon metricset to ignore non existent counters. {pull}6432[6432]
- Support apache status pages for versions older than 2.4.16. {pull}6450[6450]
- Add support for huge pages on Linux. {pull}6436[6436]

*Packetbeat*

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

--------------------------------------------------------------------
Dependency: github.com/elastic/gosigar
Version: v0.8.0
Revision: 16df19fe5efee4ea2938bde5f56c02d9929dc054
Version: v0.9.0
Revision: 237dff72b4ba95da2cd985f96a9c0ede4aefc760
License type (autodetected): Apache-2.0
./vendor/github.com/elastic/gosigar/LICENSE:
--------------------------------------------------------------------
Expand Down
32 changes: 32 additions & 0 deletions libbeat/metric/system/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,35 @@ func AddSwapPercentage(s *SwapStat) {
perc := float64(s.Swap.Used) / float64(s.Swap.Total)
s.UsedPercent = common.Round(perc, common.DefaultDecimalPlacesCount)
}

// HugeTLBPagesStat includes metrics about huge pages usage
type HugeTLBPagesStat struct {
sigar.HugeTLBPages
UsedPercent float64 `json:"used_p"`
}

// GetHugeTLBPages returns huge pages usage metrics
func GetHugeTLBPages() (*HugeTLBPagesStat, error) {
pages := sigar.HugeTLBPages{}
err := pages.Get()

if err == nil {
return &HugeTLBPagesStat{HugeTLBPages: pages}, nil
}

if sigar.IsNotImplemented(err) {
return nil, nil
}

return nil, err
}

// AddHugeTLBPagesPercentage calculates ratio of used huge pages
func AddHugeTLBPagesPercentage(s *HugeTLBPagesStat) {
if s.Total == 0 {
return
}

perc := float64(s.Total-s.Free+s.Reserved) / float64(s.Total)
s.UsedPercent = common.Round(perc, common.DefaultDecimalPlacesCount)
}
76 changes: 76 additions & 0 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -10882,6 +10882,82 @@ format: percent
The percentage of used swap memory.


[float]
== hugepages fields

This group contains statistics related to huge pages usage on the system.


[float]
=== `system.memory.hugepages.total`

type: long

format: number

Number of huge pages in the pool.


[float]
=== `system.memory.hugepages.used.bytes`

type: long

format: bytes

Memory used in allocated huge pages.


[float]
=== `system.memory.hugepages.used.pct`

type: long

format: percent

Percentage of huge pages used.


[float]
=== `system.memory.hugepages.free`

type: long

format: number

Number of available huge pages in the pool.


[float]
=== `system.memory.hugepages.reserved`

type: long

format: number

Number of reserved but not allocated huge pages in the pool.


[float]
=== `system.memory.hugepages.surplus`

type: long

format: number

Number of overcommited huge pages.


[float]
=== `system.memory.hugepages.default_size`

type: long

format: bytes

Default size for huge pages.


[float]
== network fields

Expand Down
47 changes: 47 additions & 0 deletions metricbeat/module/system/memory/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,50 @@
format: percent
description: >
The percentage of used swap memory.

- name: hugepages
type: group
prefix: "[float]"
description: This group contains statistics related to huge pages usage on the system.
fields:
- name: total
type: long
format: number
description: >
Number of huge pages in the pool.

- name: used.bytes
type: long
format: bytes
description: >
Memory used in allocated huge pages.

- name: used.pct
type: long
format: percent
description: >
Percentage of huge pages used.

- name: free
type: long
format: number
description: >
Number of available huge pages in the pool.

- name: reserved
type: long
format: number
description: >
Number of reserved but not allocated huge pages in the pool.

- name: surplus
type: long
format: number
description: >
Number of overcommited huge pages.

- name: default_size
type: long
format: bytes
description: >
Default size for huge pages.
21 changes: 20 additions & 1 deletion metricbeat/module/system/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,26 @@ func (m *MetricSet) Fetch() (event common.MapStr, err error) {
},
"free": swapStat.Free,
}

memory["swap"] = swap

hugePagesStat, err := mem.GetHugeTLBPages()
if err != nil {
return nil, errors.Wrap(err, "hugepages")
}
if hugePagesStat != nil {
mem.AddHugeTLBPagesPercentage(hugePagesStat)
memory["hugepages"] = common.MapStr{
"total": hugePagesStat.Total,
"used": common.MapStr{
"bytes": hugePagesStat.TotalAllocatedSize,
"pct": hugePagesStat.UsedPercent,
},
"free": hugePagesStat.Free,
"reserved": hugePagesStat.Reserved,
"surplus": hugePagesStat.Surplus,
"default_size": hugePagesStat.DefaultSize,
}
}

return memory, nil
}
5 changes: 4 additions & 1 deletion metricbeat/tests/system/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
SYSTEM_FSSTAT_FIELDS = ["count", "total_files", "total_size"]

SYSTEM_MEMORY_FIELDS = ["swap", "actual.free", "free", "total", "used.bytes", "used.pct", "actual.used.bytes",
"actual.used.pct"]
"actual.used.pct", "hugepages"]

SYSTEM_NETWORK_FIELDS = ["name", "out.bytes", "in.bytes", "out.packets",
"in.packets", "in.error", "out.error", "in.dropped", "out.dropped"]
Expand Down Expand Up @@ -288,6 +288,9 @@ def test_memory(self):
self.assert_fields_are_documented(evt)

memory = evt["system"]["memory"]
if not re.match("(?i)linux", sys.platform) and not "hugepages" in memory:
# Ensure presence of hugepages only in Linux
memory["hugepages"] = None
self.assertItemsEqual(self.de_dot(SYSTEM_MEMORY_FIELDS), memory.keys())

# Check that percentages are calculated.
Expand Down
9 changes: 9 additions & 0 deletions vendor/github.com/elastic/gosigar/CHANGELOG.md

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/gosigar/README.md

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

21 changes: 21 additions & 0 deletions vendor/github.com/elastic/gosigar/codecov.yml

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

6 changes: 6 additions & 0 deletions vendor/github.com/elastic/gosigar/concrete_sigar.go

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

4 changes: 4 additions & 0 deletions vendor/github.com/elastic/gosigar/sigar_darwin.go

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

4 changes: 4 additions & 0 deletions vendor/github.com/elastic/gosigar/sigar_freebsd.go

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

10 changes: 10 additions & 0 deletions vendor/github.com/elastic/gosigar/sigar_interface.go

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

24 changes: 24 additions & 0 deletions vendor/github.com/elastic/gosigar/sigar_linux.go

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

10 changes: 7 additions & 3 deletions vendor/github.com/elastic/gosigar/sigar_linux_common.go

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

Loading