forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 1
/
data.go
72 lines (63 loc) · 1.65 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
package node
import (
"encoding/json"
"github.com/elastic/beats/libbeat/common"
s "github.com/elastic/beats/libbeat/common/schema"
c "github.com/elastic/beats/libbeat/common/schema/mapstriface"
"github.com/elastic/beats/metricbeat/mb"
)
var (
schema = s.Schema{
"name": c.Str("name"),
"version": c.Str("version"),
"jvm": c.Dict("jvm", s.Schema{
"version": c.Str("version"),
"memory": c.Dict("mem", s.Schema{
"heap": s.Object{
"init": s.Object{
"bytes": c.Int("heap_init_in_bytes"),
},
"max": s.Object{
"bytes": c.Int("heap_max_in_bytes"),
},
},
"nonheap": s.Object{
"init": s.Object{
"bytes": c.Int("non_heap_init_in_bytes"),
},
"max": s.Object{
"bytes": c.Int("non_heap_max_in_bytes"),
},
},
}),
}),
"process": c.Dict("process", s.Schema{
"mlockall": c.Bool("mlockall"),
}),
}
)
func eventsMapping(content []byte) ([]common.MapStr, error) {
nodesStruct := struct {
ClusterName string `json:"cluster_name"`
Nodes map[string]map[string]interface{} `json:"nodes"`
}{}
json.Unmarshal(content, &nodesStruct)
var events []common.MapStr
errors := s.NewErrors()
for name, node := range nodesStruct.Nodes {
event, errs := eventMapping(node)
// Write name here as full name only available as key
event["name"] = name
event[mb.ModuleDataKey] = common.MapStr{
"cluster": common.MapStr{
"name": nodesStruct.ClusterName,
},
}
events = append(events, event)
errors.AddErrors(errs)
}
return events, errors
}
func eventMapping(node map[string]interface{}) (common.MapStr, *s.Errors) {
return schema.Apply(node)
}