〇MySQL Server ExporterのデータをPrometheusで表示した画面
〇構築方法
以下のVagrantfileを使用して、MySQL Server Exporter(Prometheus)とMySQLをインストールした仮想マシン(Debian Stretch/9.5)を構築します
Vagrantfile
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "bento/debian-9.5"
config.vm.hostname = "db95mysqldexporter"
config.vm.provider :virtualbox do |vbox|
vbox.name = "db95mysqldexporter"
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
# update packages
apt-get update
#DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade
locale-gen ja_JP.UTF-8
localectl set-locale LANG=ja_JP.UTF-8
timedatectl set-timezone Asia/Tokyo
# install mysql
wget https://dev.mysql.com/get/mysql-apt-config_0.8.9-1_all.deb
export DEBIAN_FRONTEND=noninteractive
echo mysql-apt-config mysql-apt-config/enable-repo select mysql-5.7-dmr | sudo debconf-set-selections
dpkg -i mysql-apt-config_0.8.9-1_all.deb
apt-get update
apt-get -y install mysql-server
mysql -uroot -e "CREATE USER prometheus@localhost IDENTIFIED BY 'prometheus';"
mysql -uroot -e "GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'prometheus'@'localhost';"
mysql -uroot -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 件のコメント:
コメントを投稿