Skip to content

Commit

Permalink
Used memory field corrected (#4461) (#4462)
Browse files Browse the repository at this point in the history
  • Loading branch information
Amanda H. L. de Andrade authored and andrewkroh committed Jul 11, 2017
1 parent 4b8d081 commit 1dfc81a
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 32 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ https://github.com/elastic/beats/compare/v6.0.0-alpha2...master[Check the HEAD d

- Fix issue affecting Windows services timing out at startup. {pull}4491[4491]
- Fix incorrect docker.diskio.total metric calculation. {pull}4507[4507]
- Vsphere module: used memory field corrected. {issue}4461[4461]

*Packetbeat*

Expand Down Expand Up @@ -183,6 +184,10 @@ https://github.com/elastic/beats/compare/v6.0.0-alpha1...v6.0.0-alpha2[View comm
- Add experimental RabbitMQ module. {pull}4394[4394]
- Add Kibana dashboard for the Kubernetes modules. {pull}4138[4138]
*Packetbeat*
*Winlogbeat*
==== Deprecated
*Affecting all Beats*
Expand Down
45 changes: 45 additions & 0 deletions metricbeat/module/vsphere/host/data.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package host

import (
"github.com/elastic/beats/libbeat/common"

"github.com/vmware/govmomi/vim25/mo"
)

func eventMapping(hs mo.HostSystem, datacenterName string) common.MapStr {

totalCpu := int64(hs.Summary.Hardware.CpuMhz) * int64(hs.Summary.Hardware.NumCpuCores)
freeCpu := int64(totalCpu) - int64(hs.Summary.QuickStats.OverallCpuUsage)
usedMemory := int64(hs.Summary.QuickStats.OverallMemoryUsage) * 1024 * 1024
freeMemory := int64(hs.Summary.Hardware.MemorySize) - usedMemory

event := common.MapStr{
"datacenter": datacenterName,
"name": hs.Summary.Config.Name,
"cpu": common.MapStr{
"used": common.MapStr{
"mhz": hs.Summary.QuickStats.OverallCpuUsage,
},
"total": common.MapStr{
"mhz": totalCpu,
},
"free": common.MapStr{
"mhz": freeCpu,
},
},
"memory": common.MapStr{
"used": common.MapStr{
"bytes": usedMemory,
},
"total": common.MapStr{
"bytes": hs.Summary.Hardware.MemorySize,
},
"free": common.MapStr{
"bytes": freeMemory,
},
},
}

return event

}
54 changes: 54 additions & 0 deletions metricbeat/module/vsphere/host/data_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package host

import (
"math"
"testing"

"github.com/stretchr/testify/assert"
"github.com/vmware/govmomi/vim25/mo"
"github.com/vmware/govmomi/vim25/types"
)

func TestEventMapping(t *testing.T) {

var HostSystemTest = mo.HostSystem{
Summary: types.HostListSummary{
Host: &types.ManagedObjectReference{Type: "HostSystem", Value: "ha-host"},
Hardware: &types.HostHardwareSummary{
MemorySize: 2251799812636672,
CpuMhz: 2294,
NumCpuCores: 2,
},
Config: types.HostConfigSummary{
Name: "localhost.localdomain",
},
QuickStats: types.HostListSummaryQuickStats{
OverallCpuUsage: 67,
OverallMemoryUsage: math.MaxInt32,
},
},
}

event := eventMapping(HostSystemTest, "test")

datacenter, _ := event.GetValue("datacenter")
assert.EqualValues(t, "test", datacenter)

cpuUsed, _ := event.GetValue("cpu.used.mhz")
assert.EqualValues(t, 67, cpuUsed)

cpuTotal, _ := event.GetValue("cpu.total.mhz")
assert.EqualValues(t, 4588, cpuTotal)

cpuFree, _ := event.GetValue("cpu.free.mhz")
assert.EqualValues(t, 4521, cpuFree)

memoryUsed, _ := event.GetValue("memory.used.bytes")
assert.EqualValues(t, 2251799812636672, memoryUsed)

memoryTotal, _ := event.GetValue("memory.total.bytes")
assert.EqualValues(t, 2251799812636672, memoryTotal)

memoryFree, _ := event.GetValue("memory.free.bytes")
assert.EqualValues(t, 0, memoryFree)
}
34 changes: 2 additions & 32 deletions metricbeat/module/vsphere/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,38 +96,8 @@ func (m *MetricSet) Fetch() ([]common.MapStr, error) {
}

for _, hs := range hst {
totalCpu := int64(hs.Summary.Hardware.CpuMhz) * int64(hs.Summary.Hardware.NumCpuCores)
freeCpu := int64(totalCpu) - int64(hs.Summary.QuickStats.OverallCpuUsage)
freeMemory := int64(hs.Summary.Hardware.MemorySize) - (int64(hs.Summary.QuickStats.OverallMemoryUsage) * 1024 * 1024)

event := common.MapStr{
"datacenter": dc.Name(),
"name": hs.Summary.Config.Name,
"cpu": common.MapStr{
"used": common.MapStr{
"mhz": hs.Summary.QuickStats.OverallCpuUsage,
},
"total": common.MapStr{
"mhz": totalCpu,
},
"free": common.MapStr{
"mhz": freeCpu,
},
},
"memory": common.MapStr{
"used": common.MapStr{
"bytes": hs.Summary.QuickStats.OverallMemoryUsage * 1024 * 1024,
},
"total": common.MapStr{
"bytes": hs.Summary.Hardware.MemorySize,
},
"free": common.MapStr{
"bytes": freeMemory,
},
},
}

events = append(events, event)

events = append(events, eventMapping(hs, dc.Name()))
}
}

Expand Down

0 comments on commit 1dfc81a

Please sign in to comment.