forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 1
/
data.go
58 lines (51 loc) · 1.38 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
package system
import (
"encoding/json"
"fmt"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/metricbeat/mb"
"github.com/elastic/beats/metricbeat/module/kubernetes"
)
func eventMapping(content []byte) ([]common.MapStr, error) {
events := []common.MapStr{}
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
for _, syscontainer := range node.SystemContainers {
containerEvent := common.MapStr{
mb.ModuleDataKey: common.MapStr{
"node": common.MapStr{
"name": node.NodeName,
},
},
"container": syscontainer.Name,
"start_time": syscontainer.StartTime,
"cpu": common.MapStr{
"usage": common.MapStr{
"nanocores": syscontainer.CPU.UsageNanoCores,
"core": common.MapStr{
"ns": syscontainer.CPU.UsageCoreNanoSeconds,
},
},
},
"memory": common.MapStr{
"usage": common.MapStr{
"bytes": syscontainer.Memory.UsageBytes,
},
"workingset": common.MapStr{
"bytes": syscontainer.Memory.WorkingSetBytes,
},
"rss": common.MapStr{
"bytes": syscontainer.Memory.RssBytes,
},
"pagefaults": syscontainer.Memory.PageFaults,
"majorpagefaults": syscontainer.Memory.MajorPageFaults,
},
}
events = append(events, containerEvent)
}
return events, nil
}