exec plugin support prometheus data format

This commit is contained in:
Ulric Qin 2022-07-22 19:55:12 +08:00
parent ce0a0302f9
commit c3a84d5def
2 changed files with 62 additions and 2 deletions

View File

@ -1,3 +1,63 @@
# exec
该插件用于给用户自定义监控脚本,脚本的输出格式支持两种,一种是 influx 格式,一种是 falcon 格式
该插件用于给用户自定义监控脚本监控脚本采集到监控数据之后通过相应的格式输出到stdoutcategraf截获stdout内容解析之后传给服务端脚本的输出格式支持3种influx、falcon、prometheus
## influx
influx 格式的内容规范:
```
mesurement,labelkey1=labelval1,labelkey2=labelval2 field1=1.2,field2=2.3
```
- 首先mesurement表示一个类别的监控指标比如 connections
- mesurement后面是逗号逗号后面是标签如果没有标签则mesurement后面不需要逗号
- 标签是k=v的格式多个标签用逗号分隔比如region=beijing,env=test
- 标签后面是空格
- 空格后面是属性字段,多个属性字段用逗号分隔
- 属性字段是字段名=值的格式在categraf里值只能是数字
最终mesurement和各个属性字段名称拼接成metric名字
## falcon
Open-Falcon的格式如下举例
```json
[
{
"endpoint": "test-endpoint",
"metric": "test-metric",
"timestamp": 1658490609,
"step": 60,
"value": 1,
"counterType": "GAUGE",
"tags": "idc=lg,loc=beijing",
},
{
"endpoint": "test-endpoint",
"metric": "test-metric2",
"timestamp": 1658490609,
"step": 60,
"value": 2,
"counterType": "GAUGE",
"tags": "idc=lg,loc=beijing",
}
]
```
timestamp、step、counterType这三个字段在categraf处理的时候会直接忽略掉endpoint会放到labels里上报。
## prometheus
prometheus 格式大家不陌生了,比如我这里准备一个监控脚本,输出 prometheus 的格式数据:
```shell
#!/bin/sh
echo '# HELP demo_http_requests_total Total number of http api requests'
echo '# TYPE demo_http_requests_total counter'
echo 'demo_http_requests_total{api="add_product"} 4633433'
```
其中 `#` 注释的部分,其实会被 categraf 忽略不要也罢prometheus 协议的数据具体的格式,请大家参考 prometheus 官方文档

View File

@ -67,7 +67,7 @@ func (e *Exec) Init() error {
e.Instances[i].parser = influx.NewParser()
} else if e.Instances[i].DataFormat == "falcon" {
e.Instances[i].parser = falcon.NewParser()
} else if e.Instances[i].DataFormat == "prometheus" {
} else if strings.HasPrefix(e.Instances[i].DataFormat, "prom") {
e.Instances[i].parser = prometheus.NewParser("", map[string]string{}, nil, nil, nil)
} else {
return fmt.Errorf("data_format(%s) not supported", e.Instances[i].DataFormat)