sudo mysql -e "create user 'datadog'@'localhost' identified by '<MYSQL_PASSWORD>';"sudo mysql -e "grant select on cacti.* to 'datadog'@'localhost';"
ユーザーと権限をチェックします。
mysql -u datadog --password=<MYSQL_PASSWORD> -e "show status"|\
grep Uptime &&echo -e "\033[0;32mMySQL user - OK\033[0m"||\
echo -e "\033[0;31mCannot connect to MySQL\033[0m"mysql -u datadog --password=<MYSQL_PASSWORD> -D cacti -e "select * from data_template_data limit 1"&&\
echo -e "\033[0;32mMySQL grant - OK\033[0m"||\
echo -e "\033[0;31mMissing SELECT grant\033[0m"
datadog-agent ユーザーに RRD ファイルへのアクセス権を付与します。
sudo gpasswd -a dd-agent www-data
sudo chmod -R g+rx /var/lib/cacti/rra/
sudo su - datadog-agent -c 'if [ -r /var/lib/cacti/rra/ ];
then echo -e "\033[0;31mdatadog-agent can read the RRD files\033[0m";
else echo -e "\033[0;31mdatadog-agent can not read the RRD files\033[0m";
fi'
Agent の構成
Agent が MySQL に接続するように構成し、cacti.d/conf.yaml ファイルを編集します。使用可能なすべてのコンフィギュレーションオプションの詳細については、cacti.d/conf.yaml のサンプルを参照してください。
init_config:instances:## @param mysql_host - string - required## url of your MySQL database#- mysql_host:"localhost"## @param mysql_port - integer - optional - default: 3306## port of your MySQL database## mysql_port: 3306## @param mysql_user - string - required## User to use to connect to MySQL in order to gather metrics#mysql_user:"datadog"## @param mysql_password - string - required## Password to use to connect to MySQL in order to gather metrics#mysql_password:"<MYSQL_PASSWORD>"## @param rrd_path - string - required## The Cacti checks requires access to the Cacti DB in MySQL and to the RRD## files that contain the metrics tracked in Cacti.## In almost all cases, you'll only need one instance pointing to the Cacti## database.## The `rrd_path` will probably be `/var/lib/cacti/rra` on Ubuntu## or `/var/www/html/cacti/rra` on any other machines.#rrd_path:"<CACTI_RRA_PATH>"