Skip to content

Commit

Permalink
Merge pull request #466 from monicasarbu/actual_used_free_docs
Browse files Browse the repository at this point in the history
Update all actual_used and actual_free fields
  • Loading branch information
tsg committed Dec 10, 2015
2 parents 1601d90 + 7b71d60 commit 8b02749
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 33 deletions.
11 changes: 9 additions & 2 deletions topbeat/beat/sigar.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ type MemStat struct {
ActualUsedPercent float64 `json:"actual_used_p"`
}

type SwapStat struct {
Total uint64 `json:"total"`
Used uint64 `json:"used"`
Free uint64 `json:"free"`
UsedPercent float64 `json:"used_p"`
}

type ProcMemStat struct {
Size uint64 `json:"size"`
Rss uint64 `json:"rss"`
Expand Down Expand Up @@ -191,15 +198,15 @@ func GetMemory() (*MemStat, error) {
}, nil
}

func GetSwap() (*MemStat, error) {
func GetSwap() (*SwapStat, error) {

swap := sigar.Swap{}
err := swap.Get()
if err != nil {
return nil, err
}

return &MemStat{
return &SwapStat{
Total: swap.Total,
Used: swap.Used,
Free: swap.Free,
Expand Down
11 changes: 10 additions & 1 deletion topbeat/beat/topbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func (t *Topbeat) exportSystemStats() error {
logp.Warn("Getting swap details: %v", err)
return err
}
t.addMemPercentage(swap_stat)
t.addSwapPercentage(swap_stat)

event := common.MapStr{
"@timestamp": common.Time(time.Now()),
Expand Down Expand Up @@ -327,6 +327,15 @@ func (t *Topbeat) addMemPercentage(m *MemStat) {
m.ActualUsedPercent = Round(actual_perc, .5, 2)
}

func (t *Topbeat) addSwapPercentage(s *SwapStat) {
if s.Total == 0 {
return
}

perc := float64(s.Used) / float64(s.Total)
s.UsedPercent = Round(perc, .5, 2)
}

func addFileSystemUsedPercentage(f *FileSystemStat) {
if f.Total == 0 {
return
Expand Down
4 changes: 2 additions & 2 deletions topbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,14 @@ The percentage of used memory.

type: int

Actual used memory. Available only on Unix.
Actual used memory. It is defined as the "used" memory minus the memory used for disk caches and buffers. Available only on Unix.


==== mem.actual_free

type: int

Actual available memory. Available only on Unix.
Actual available memory. It is defined as the "free" memory plus the memory used for disk caches and buffers. Available only on Unix.


==== mem.actual_used_p
Expand Down
24 changes: 4 additions & 20 deletions topbeat/etc/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,15 @@ system:
path: mem.actual_used
type: int
description: >
Actual used memory. Available only on Unix.
Actual used memory. It is defined as the "used" memory minus the memory used for disk caches and buffers.
Available only on Unix.
- name: actual_free
path: mem.actual_free
type: int
description: >
Actual available memory. Available only on Unix.
Actual available memory. It is defined as the "free" memory plus the memory used for disk caches and
buffers. Available only on Unix.
- name: actual_used_p
path: mem.actual_used_p
Expand Down Expand Up @@ -218,24 +220,6 @@ system:
description: >
The percentage of used swap memory.
- name: actual_used
path: swap.actual_used
type: int
description: >
Actual used swap memory. Available only on Unix.
- name: actual_free
path: swap.actual_free
type: int
description: >
Actual available swap memory. Available only on Unix.
- name: actual_used_p
path: swap.actual_used_p
type: float
description: >
The percentage of actual used swap memory.
process:
type: group
description: >
Expand Down
6 changes: 1 addition & 5 deletions topbeat/etc/topbeat.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@
},
"swap": {
"properties": {
"actual_used_p": {
"doc_values": "true",
"type": "float"
},
"used_p": {
"doc_values": "true",
"type": "float"
Expand All @@ -111,4 +107,4 @@
"index.refresh_interval": "5s"
},
"template": "topbeat-*"
}
}
3 changes: 0 additions & 3 deletions topbeat/tests/system/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def test_system_wide(self):
"mem.used_p",
"mem.actual_used_p",
"swap.used_p",
"swap.actual_used_p",
]:
assert type(output[key]) in [float, int]

Expand All @@ -54,7 +53,5 @@ def test_system_wide(self):
"swap.total",
"swap.used",
"swap.free",
"swap.actual_used",
"swap.actual_free",
]:
assert type(output[key]) is int or type(output[key]) is long

0 comments on commit 8b02749

Please sign in to comment.