integrations/Exec/markdown/README.md
应用于input插件库exec目录之外的特殊或自定义实现指定业务的监控。
监控脚本采集到监控数据之后通过相应的格式输出到stdout,categraf截获stdout内容,解析之后传给服务端,
脚本的输出格式支持3种:influx、falcon、prometheus,通过 exec.toml 的 `data_format` 配置告诉 Categraf。
data_format有3个值,其用法为:
influx 格式的内容规范:
measurement,labelkey1=labelval1,labelkey2=labelval2 field1=1.2,field2=2.3
Open-Falcon的格式如下,举例:
[
{
"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 的格式数据:
#!/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 官方文档
一般在复合型用途或独立的虚拟机启用此插件。
1.需使用人解读每个脚本或程序的逻辑,其脚本或程序顶部有大概作用的描述。
本配置启用或数据定义如下功能: 增加自定义标签,可通过自定义标签筛选数据及更加精确的告警推送。 响应超时时间为5秒。 commands字段正确应用脚本所在位置。
[root@aliyun input.exec]# vi exec.toml
# # collect interval
# interval = 15
[[instances]]
# # commands, support glob
commands = [
"/opt/categraf/scripts/*/collect_*.sh"
#"/opt/categraf/scripts/*/collect_*.py"
#"/opt/categraf/scripts/*/collect_*.go"
#"/opt/categraf/scripts/*/collect_*.lua"
#"/opt/categraf/scripts/*/collect_*.java"
#"/opt/categraf/scripts/*/collect_*.bat"
#"/opt/categraf/scripts/*/collect_*.cmd"
#"/opt/categraf/scripts/*/collect_*.ps1"
]
# # timeout for each command to complete
# timeout = 5
# # interval = global.interval * interval_times
# interval_times = 1
# # measurement,labelkey1=labelval1,labelkey2=labelval2 field1=1.2,field2=2.3
data_format = "influx"
以cert/collect_cert_expiretime.sh为例:
sh /opt/categraf/cert/collect_cert_expiretime.sh 出现:
cert,cloud=huaweicloud,region=huabei-beijing-4,azone=az1,product=cert,domain_name=www.baidu.com expire_days=163
cert,cloud=huaweicloud,region=huabei-beijing-4,azone=az1,product=cert,domain_name=www.weibo.com expire_days=85
cert,cloud=huaweicloud,region=huabei-beijing-4,azone=az1,product=cert,domain_name=www.csdn.net expire_days=281
重启categraf服务生效
systemctl daemon-reload && systemctl restart categraf && systemctl status categraf
查看启动日志是否有错误
journalctl -f -n 500 -u categraf | grep "E\!" | grep "W\!"
如图: