agent中的plugin是一种辅助的采集数据的方式。
在plugin的脚本中向stdout打印metric信息,agent会自动收集并上报给transfer。
下面介绍其使用方式。
1. 配置agent, 使能plugin
编辑agent/config/cfg.json
设置”enabled”为true,配置dir,git 等。
其中,dir 是相对于open-falcon的根目录的路径,如果根目录是/home/work/open-falcon,则此处的dir的绝对路径是/home/work/open-falcon/dir,也就是/home/work/open-falcon/git_repo
注意的一点是:此处的dir名称必须与git 拉取下来的仓库名称一致,否则,拉取时会报错。
agent配置文件如下:
{
“debug”: true,
“hostname”: “”,
“ip”: “”,
“plugin”: {
“enabled”: true,
“dir”: “./git_repo”,
“git”: “git@192.168.33.152:/home/git/git_repo”,
“logs”: “./logs”
},
“heartbeat”: {
“enabled”: true,
“addr”: “0.0.0.0:6030”,
“interval”: 60,
“timeout”: 1000
},
…
}
2. 从git仓库拉取plugin
在部署agent机器上,执行如下命令,拉取插件库:
$ curl http://127.0.0.1:1988/plugin/update
success
查看/home/work/open-falcon根目录,发现多了一个git_repo目录
$ ll
...
drwxr-xr-x 3 lanyang lang 4096 Sep 5 20:11 git_repo
drwxr-xr-x 6 langyang lanyang 4096 Jun 19 17:02 graph
...
查看其内容
$ cat git_repo/60_stats.py
#!/usr/bin/python
import time
import json
output = [{"endpoint": "monitor-test-centos", "tags": "", "timestamp": int(time.time()), "metric": "agent.cpu", "value": 1.8, "counterType": "GAUGE", "step": 60}]
print json.dumps(output)
其执行时的输出:
[{“endpoint”: “monitor-test-centos”, “tags”: “”, “timestamp”: 1504615532, “metric”: “agent.cpu”, “value”: 1.8, “counterType”: “GAUGE”, “step”: 60}]
3. portal中配置plugins
进入HostGroups界面
*创建group
如图,已经创建group”DRAGON_ARM”
配置plugin路径
配置这个group要执行的插件脚本的路径,该路径是相对路径,相对于agent的配置文件中dir 的路径, 例如本例中为git_repo,plugin dir就是相对于git_repo的路径。
配置如图,配置成了当前目录,也就是git_repo目录下的所有的插件文件:
配置hosts
对刚才创建”DRAGON_ARM”组,点击”Host”,添加host。
查看结果
完成后,稍等片刻。打开主页,针对刚才host,查看metric.
点击agent.cpu超链接,即可跳转到详情页面。