1 Star 0 Fork 0

zhangjungang/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
config.go 1.27 KB
一键复制 编辑 原始数据 按行查看 历史
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{}
var 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
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhangjungang/beats.git
git@gitee.com:zhangjungang/beats.git
zhangjungang
beats
beats
v6.0.0

搜索帮助