〇MySQL Server ExporterのデータをPrometheusで表示した画面
〇構築方法
以下のVagrantfileを使用して、MySQL Server Exporter(Prometheus)とMariaDBをインストールした仮想マシン(CentOS7.5)を構築します
Vagrantfile
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "bento/centos-7.5"
config.vm.hostname = "co75mariadbmysqlexporter"
config.vm.provider :virtualbox do |vbox|
vbox.name = "co75mariadbmysqlexporter"
vbox.cpus = 2
vbox.memory = 2048
vbox.customize ["modifyvm", :id, "--nicpromisc2","allow-all"]
end
config.vm.network "private_network", ip: "192.168.55.106", :netmask => "255.255.255.0"
config.vm.network "public_network", ip:"192.168.1.106", :netmask => "255.255.255.0"
config.vm.provision "shell", inline: <<-SHELL
localectl set-locale LANG=ja_JP.UTF-8
timedatectl set-timezone Asia/Tokyo
# install mariadb
yum -y install mariadb mariadb-server
sudo systemctl enable mariadb.service
sudo systemctl start mariadb.service
mysql -uroot -e "SET PASSWORD = PASSWORD('root'); FLUSH PRIVILEGES;"
mysql -uroot -proot -e "CREATE USER prometheus@localhost IDENTIFIED BY 'prometheus';"
mysql -uroot -proot -e "GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'prometheus'@'localhost';"
mysql -uroot -proot -e "FLUSH PRIVILEGES;"
# install prometheus mysql exporter
groupadd prometheus
useradd -g prometheus -s /bin/bash -d /home/prometheus -m prometheus
mkdir -p /opt/prometheus
cd /opt/prometheus
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.11.0/mysqld_exporter-0.11.0.linux-amd64.tar.gz
tar xvfz mysqld_exporter-0.11.0.linux-amd64.tar.gz
ln -s /opt/prometheus/mysqld_exporter-0.11.0.linux-amd64/mysqld_exporter /bin/mysqld_exporter
cat << EOF > /etc/systemd/system/mysqld-exporter.service
[Unit]
Description=Prometheus MySQL Server Exporter
Requires=network.target
[Service]
Restart=always
WorkingDirectory=/opt/prometheus/mysqld_exporter-0.11.0.linux-amd64
Environment=DATA_SOURCE_NAME=prometheus:prometheus@(localhost:3306)/
ExecStart=/bin/mysqld_exporter
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
EOF
systemctl enable mysqld-exporter.service
systemctl start mysqld-exporter.service
echo 'port 9104'
SHELL
end
0 件のコメント:
コメントを投稿