forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.go
85 lines (78 loc) · 2.04 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
package collstats
import (
"errors"
"strings"
"github.com/elastic/beats/libbeat/common"
)
func eventMapping(key string, data common.MapStr) (common.MapStr, error) {
names := strings.SplitN(key, ".", 2)
if len(names) < 2 {
return nil, errors.New("Collection name invalid")
}
event := common.MapStr{
"db": names[0],
"collection": names[1],
"name": key,
"total": common.MapStr{
"time": common.MapStr{
"us": mustGetMapStrValue(data, "total.time"),
},
"count": mustGetMapStrValue(data, "total.count"),
},
"lock": common.MapStr{
"read": common.MapStr{
"time": common.MapStr{
"us": mustGetMapStrValue(data, "readLock.time"),
},
"count": mustGetMapStrValue(data, "readLock.count"),
},
"write": common.MapStr{
"time": common.MapStr{
"us": mustGetMapStrValue(data, "writeLock.time"),
},
"count": mustGetMapStrValue(data, "writeLock.count"),
},
},
"queries": common.MapStr{
"time": common.MapStr{
"us": mustGetMapStrValue(data, "queries.time"),
},
"count": mustGetMapStrValue(data, "queries.count"),
},
"getmore": common.MapStr{
"time": common.MapStr{
"us": mustGetMapStrValue(data, "getmore.time"),
},
"count": mustGetMapStrValue(data, "getmore.count"),
},
"insert": common.MapStr{
"time": common.MapStr{
"us": mustGetMapStrValue(data, "insert.time"),
},
"count": mustGetMapStrValue(data, "insert.count"),
},
"update": common.MapStr{
"time": common.MapStr{
"us": mustGetMapStrValue(data, "update.time"),
},
"count": mustGetMapStrValue(data, "update.count"),
},
"remove": common.MapStr{
"time": common.MapStr{
"us": mustGetMapStrValue(data, "remove.time"),
},
"count": mustGetMapStrValue(data, "remove.count"),
},
"commands": common.MapStr{
"time": common.MapStr{
"us": mustGetMapStrValue(data, "commands.time"),
},
"count": mustGetMapStrValue(data, "commands.count"),
},
}
return event, nil
}
func mustGetMapStrValue(m common.MapStr, key string) interface{} {
v, _ := m.GetValue(key)
return v
}