forked from premendrasingh/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.go
42 lines (37 loc) · 987 Bytes
/
data.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package host
import (
"github.com/elastic/beats/libbeat/common"
"github.com/vmware/govmomi/vim25/mo"
)
func eventMapping(hs mo.HostSystem) 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{
"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
}