forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.go
117 lines (108 loc) · 2.88 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
package cluster
import (
"encoding/json"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"
)
type StorageTotals_Ram struct {
Total int64 `json:"total"`
QuotaTotal int64 `json:"quotaTotal"`
QuotaUsed int64 `json:"quotaUsed"`
Used int64 `json:"used"`
UsedByData int64 `json:"usedByData"`
QuotaUsedPerNode int64 `json:"quotaUsedPerNode"`
QuotaTotalPerNode int64 `json:"quotaTotalPerNode"`
}
type StorageTotals_Hdd struct {
Total int64 `json:"total"`
QuotaTotal int64 `json:"quotaTotal"`
Used int64 `json:"used"`
UsedByData int64 `json:"usedByData"`
Free int64 `json:"free"`
}
type StorageTotals struct {
RAM StorageTotals_Ram `json:"ram"`
Hdd StorageTotals_Hdd `json:"hdd"`
}
type Data struct {
StorageTotals StorageTotals `json:"storageTotals"`
IndexMemoryQuota int64 `json:"indexMemoryQuota"`
MemoryQuota int64 `json:"memoryQuota"`
RebalanceStatus string `json:"rebalanceStatus"`
RebalanceProgressURI string `json:"rebalanceProgressUri"`
StopRebalanceURI string `json:"stopRebalanceUri"`
NodeStatusesURI string `json:"nodeStatusesUri"`
MaxBucketCount int64 `json:"maxBucketCount"`
}
func eventMapping(content []byte) common.MapStr {
var d Data
err := json.Unmarshal(content, &d)
if err != nil {
logp.Err("Error: ", err)
}
logp.Info("Printing Data:")
event := common.MapStr{
"hdd": common.MapStr{
"quota": common.MapStr{
"total": common.MapStr{
"bytes": d.StorageTotals.Hdd.QuotaTotal,
},
},
"free": common.MapStr{
"bytes": d.StorageTotals.Hdd.Free,
},
"total": common.MapStr{
"bytes": d.StorageTotals.Hdd.Total,
},
"used": common.MapStr{
"value": common.MapStr{
"bytes": d.StorageTotals.Hdd.Used,
},
"by_data": common.MapStr{
"bytes": d.StorageTotals.Hdd.UsedByData,
},
},
},
"max_bucket_count": d.MaxBucketCount,
"quota": common.MapStr{
"index_memory": common.MapStr{
"mb": d.IndexMemoryQuota,
},
"memory": common.MapStr{
"mb": d.MemoryQuota,
},
},
"ram": common.MapStr{
"quota": common.MapStr{
"total": common.MapStr{
"value": common.MapStr{
"bytes": d.StorageTotals.RAM.QuotaTotal,
},
"per_node": common.MapStr{
"bytes": d.StorageTotals.RAM.QuotaTotalPerNode,
},
},
"used": common.MapStr{
"value": common.MapStr{
"bytes": d.StorageTotals.RAM.QuotaUsed,
},
"per_node": common.MapStr{
"bytes": d.StorageTotals.RAM.QuotaUsedPerNode,
},
},
},
"total": common.MapStr{
"bytes": d.StorageTotals.RAM.Total,
},
"used": common.MapStr{
"value": common.MapStr{
"bytes": d.StorageTotals.RAM.Used,
},
"by_data": common.MapStr{
"bytes": d.StorageTotals.RAM.UsedByData,
},
},
},
}
return event
}