-
Notifications
You must be signed in to change notification settings - Fork 1
/
data.go
92 lines (83 loc) · 2.01 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package node
import (
"encoding/json"
"fmt"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/metricbeat/module/kubernetes"
)
func eventMapping(content []byte) (common.MapStr, error) {
var summary kubernetes.Summary
err := json.Unmarshal(content, &summary)
if err != nil {
return nil, fmt.Errorf("Cannot unmarshal json response: %s", err)
}
node := summary.Node
nodeEvent := common.MapStr{
"name": node.NodeName,
"start_time": node.StartTime,
"cpu": common.MapStr{
"usage": common.MapStr{
"nanocores": node.CPU.UsageNanoCores,
"core": common.MapStr{
"ns": node.CPU.UsageCoreNanoSeconds,
},
},
},
"memory": common.MapStr{
"available": common.MapStr{
"bytes": node.Memory.AvailableBytes,
},
"usage": common.MapStr{
"bytes": node.Memory.UsageBytes,
},
"workingset": common.MapStr{
"bytes": node.Memory.WorkingSetBytes,
},
"rss": common.MapStr{
"bytes": node.Memory.RssBytes,
},
"pagefaults": node.Memory.PageFaults,
"majorpagefaults": node.Memory.MajorPageFaults,
},
"network": common.MapStr{
"rx": common.MapStr{
"bytes": node.Network.RxBytes,
"errors": node.Network.RxErrors,
},
"tx": common.MapStr{
"bytes": node.Network.TxBytes,
"errors": node.Network.TxErrors,
},
},
"fs": common.MapStr{
"available": common.MapStr{
"bytes": node.Fs.AvailableBytes,
},
"capacity": common.MapStr{
"bytes": node.Fs.CapacityBytes,
},
"used": common.MapStr{
"bytes": node.Fs.UsedBytes,
},
"inodes": common.MapStr{
"used": node.Fs.InodesUsed,
"free": node.Fs.InodesFree,
"count": node.Fs.Inodes,
},
},
"runtime": common.MapStr{
"imagefs": common.MapStr{
"available": common.MapStr{
"bytes": node.Runtime.ImageFs.AvailableBytes,
},
"capacity": common.MapStr{
"bytes": node.Runtime.ImageFs.CapacityBytes,
},
"used": common.MapStr{
"bytes": node.Runtime.ImageFs.UsedBytes,
},
},
},
}
return nodeEvent, nil
}