forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.go
148 lines (134 loc) · 4.6 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package node
import (
"encoding/json"
"strconv"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"
)
type NodeSystemStats struct {
CPUUtilizationRate float64 `json:"cpu_utilization_rate"`
SwapTotal int64 `json:"swap_total"`
SwapUsed int64 `json:"swap_used"`
MemTotal int64 `json:"mem_total"`
MemFree int64 `json:"mem_free"`
}
type NodeInterestingStats struct {
CmdGet int64 `json:"cmd_get"`
CouchDocsActualDiskSize int64 `json:"couch_docs_actual_disk_size"`
CouchDocsDataSize int64 `json:"couch_docs_data_size"`
CouchSpatialDataSize int64 `json:"couch_spatial_data_size"`
CouchSpatialDiskSize int64 `json:"couch_spatial_disk_size"`
CouchViewsActualDiskSize int64 `json:"couch_views_actual_disk_size"`
CouchViewsDataSize int64 `json:"couch_views_data_size"`
CurrItems int64 `json:"curr_items"`
CurrItemsTot int64 `json:"curr_items_tot"`
EpBgFetched int64 `json:"ep_bg_fetched"`
GetHits int64 `json:"get_hits"`
MemUsed int64 `json:"mem_used"`
Ops int64 `json:"ops"`
VbReplicaCurrItems int64 `json:"vb_replica_curr_items"`
}
type Node struct {
SystemStats NodeSystemStats `json:"systemStats"`
InterestingStats NodeInterestingStats `json:"interestingStats"`
Uptime string `json:"uptime"`
MemoryTotal int64 `json:"memoryTotal"`
MemoryFree int64 `json:"memoryFree"`
McdMemoryReserved int64 `json:"mcdMemoryReserved"`
McdMemoryAllocated int64 `json:"mcdMemoryAllocated"`
ClusterMembership string `json:"clusterMembership"`
RecoveryType string `json:"recoveryType"`
Status string `json:"status"`
ThisNode bool `json:"thisNode"`
Hostname string `json:"hostname"`
ClusterCompatibility int64 `json:"clusterCompatibility"`
Version string `json:"version"`
Os string `json:"os"`
}
type Data struct {
Nodes []Node `json:"nodes"`
}
func eventsMapping(content []byte) []common.MapStr {
var d Data
err := json.Unmarshal(content, &d)
if err != nil {
logp.Err("Error: ", err)
}
events := []common.MapStr{}
for _, NodeItem := range d.Nodes {
uptime, _ := strconv.ParseInt(NodeItem.Uptime, 10, 64)
event := common.MapStr{
"cmd_get": NodeItem.InterestingStats.CmdGet,
"couch": common.MapStr{
"docs": common.MapStr{
"disk_size": common.MapStr{
"bytes": NodeItem.InterestingStats.CouchDocsActualDiskSize,
},
"data_size": common.MapStr{
"bytes": NodeItem.InterestingStats.CouchDocsDataSize,
},
},
"spatial": common.MapStr{
"data_size": common.MapStr{
"bytes": NodeItem.InterestingStats.CouchSpatialDataSize,
},
"disk_size": common.MapStr{
"bytes": NodeItem.InterestingStats.CouchSpatialDiskSize,
},
},
"views": common.MapStr{
"disk_size": common.MapStr{
"bytes": NodeItem.InterestingStats.CouchViewsActualDiskSize,
},
"data_size": common.MapStr{
"bytes": NodeItem.InterestingStats.CouchViewsDataSize,
},
},
},
"cpu_utilization_rate": common.MapStr{
"pct": NodeItem.SystemStats.CPUUtilizationRate,
},
"current_items": common.MapStr{
"value": NodeItem.InterestingStats.CurrItems,
"total": NodeItem.InterestingStats.CurrItemsTot,
},
"ep_bg_fetched": NodeItem.InterestingStats.EpBgFetched,
"get_hits": NodeItem.InterestingStats.GetHits,
"hostname": NodeItem.Hostname,
"mcd_memory": common.MapStr{
"reserved": common.MapStr{
"bytes": NodeItem.McdMemoryReserved,
},
"allocated": common.MapStr{
"bytes": NodeItem.McdMemoryAllocated,
},
},
"memory": common.MapStr{
"total": common.MapStr{
"bytes": NodeItem.SystemStats.MemTotal,
},
"free": common.MapStr{
"bytes": NodeItem.SystemStats.MemFree,
},
"used": common.MapStr{
"bytes": NodeItem.InterestingStats.MemUsed,
},
},
"ops": NodeItem.InterestingStats.Ops,
"swap": common.MapStr{
"total": common.MapStr{
"bytes": NodeItem.SystemStats.SwapTotal,
},
"used": common.MapStr{
"bytes": NodeItem.SystemStats.SwapUsed,
},
},
"uptime": common.MapStr{
"sec": uptime,
},
"vb_replica_curr_items": NodeItem.InterestingStats.VbReplicaCurrItems,
}
events = append(events, event)
}
return events
}