integrations/Exec/markdown/README.en_US.md
Used for special or custom monitoring of specific business scenarios not covered by the scripts in the exec directory of the input plugin library.
After the monitoring script collects data, it prints the data to stdout in the corresponding format. categraf captures the stdout content, parses it, and sends it to the server.
Three script output formats are supported: influx, falcon, and prometheus. Tell Categraf which one to use via the `data_format` setting in exec.toml.
data_format has 3 possible values, used as follows:
Specification for the influx format:
measurement,labelkey1=labelval1,labelkey2=labelval2 field1=1.2,field2=2.3
The Open-Falcon format looks like this, for example:
[
{
"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",
}
]
The timestamp, step, and counterType fields are simply ignored when categraf processes the data; endpoint is reported as part of the labels.
Everyone is familiar with the prometheus format. For example, here is a monitoring script that outputs data in prometheus format:
#!/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'
The lines starting with # are comments and are actually ignored by categraf, so they can be omitted. For details on the prometheus protocol data format, please refer to the official prometheus documentation.
This plugin is generally enabled on multi-purpose or standalone virtual machines.
1. The user needs to understand the logic of each script or program; a brief description of its purpose is provided at the top of each script or program.
This configuration enables or defines the following: Add custom labels, which can be used to filter data and enable more precise alert delivery. The response timeout is 5 seconds. The commands field should correctly point to the location of the scripts.
[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"
Taking cert/collect_cert_expiretime.sh as an example:
running sh /opt/categraf/cert/collect_cert_expiretime.sh prints:
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
Restart the categraf service to apply the changes
systemctl daemon-reload && systemctl restart categraf && systemctl status categraf
Check the startup log for errors
journalctl -f -n 500 -u categraf | grep "E\!" | grep "W\!"
As shown below: