forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 1
/
data.go
75 lines (65 loc) · 1.63 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
package self
import (
"encoding/json"
"github.com/elastic/beats/libbeat/common"
)
type LeaderInfo struct {
Leader string `json:"leader"`
StartTime string `json:"startTime"`
Uptime string `json:"uptime"`
}
type AppendRequest struct {
Count int64 `json:"recvAppendRequestCnt"`
}
type Recv struct {
Appendrequest AppendRequest
Bandwithrate float64 `json:"recvBandwithRate"`
Pkgrate float64 `json:"recvPkgRate"`
}
type sendAppendRequest struct {
Cnt int64 `json:"sendAppendRequestCnt"`
}
type Send struct {
AppendRequest sendAppendRequest
BandwithRate float64 `json:"sendBandwidthRate"`
PkgRate float64 `json:"sendPkgRate"`
}
type Self struct {
ID string `json:"id"`
LeaderInfo LeaderInfo
Name string `json:"name"`
Recv Recv
Send Send
StartTime string `json:"startTime"`
State string `json:"state"`
}
func eventMapping(content []byte) common.MapStr {
var data Self
json.Unmarshal(content, &data)
event := common.MapStr{
"id": data.ID,
"leaderinfo": common.MapStr{
"leader": data.LeaderInfo.Leader,
"starttime": data.LeaderInfo.StartTime,
"uptime": data.LeaderInfo.Uptime,
},
"name": data.Name,
"recv": common.MapStr{
"appendrequest": common.MapStr{
"count": data.Recv.Appendrequest.Count,
},
"bandwithrate": data.Recv.Bandwithrate,
"pkgrate": data.Recv.Pkgrate,
},
"send": common.MapStr{
"appendrequest": common.MapStr{
"count": data.Send.AppendRequest.Cnt,
},
"bandwithrate": data.Send.BandwithRate,
"pkgrate": data.Send.PkgRate,
},
"starttime": data.StartTime,
"state": data.State,
}
return event
}