forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
61 lines (51 loc) · 1.27 KB
/
config.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
package jmx
import "encoding/json"
type JMXMapping struct {
MBean string
Attributes []Attribute
}
type Attribute struct {
Attr string
Field string
}
// RequestBlock is used to build the request blocks of the following format:
//
// [
// {
// "type":"read",
// "mbean":"java.lang:type=Runtime",
// "attribute":[
// "Uptime"
// ]
// },
// {
// "type":"read",
// "mbean":"java.lang:type=GarbageCollector,name=ConcurrentMarkSweep",
// "attribute":[
// "CollectionTime",
// "CollectionCount"
// ]
// }
// ]
type RequestBlock struct {
Type string `json:"type"`
MBean string `json:"mbean"`
Attribute []string `json:"attribute"`
}
func buildRequestBodyAndMapping(mappings []JMXMapping) ([]byte, map[string]string, error) {
responseMapping := map[string]string{}
blocks := []RequestBlock{}
for _, mapping := range mappings {
rb := RequestBlock{
Type: "read",
MBean: mapping.MBean,
}
for _, attribute := range mapping.Attributes {
rb.Attribute = append(rb.Attribute, attribute.Attr)
responseMapping[mapping.MBean+"_"+attribute.Attr] = attribute.Field
}
blocks = append(blocks, rb)
}
content, err := json.Marshal(blocks)
return content, responseMapping, err
}