Transfer: Grafana Prometheus monitoring MySQL +
Chart
surroundings
IP | surroundings | Software to be installed |
---|---|---|
192.168.0.237 | mysql-5.7.20 | node_exporter-0.15.2.linux-amd64.tar.gz mysqld_exporter-0.10.0.linux-amd64.tar.gz |
192.168.0.248 | grafana + Prometheus | amd64targz-210linux-prometheus nodeexporter-0152linux-amd64targz grafana-463linux-x64targz |
192.168.0.248 in the installation grafana prometheus
Installation prometheus
# 创建保存软件的目录
mkdir /data/software/ -p
cd /data/software/
# 解压 prometheus
tar xvf prometheus-2.1.0.linux-amd64.tar.gz -C /iba/
cd /iba/
mv prometheus-2.1.0.linux-amd64 prometheus
cd prometheus/
cp prometheus.yml /tmp/prometheus.yml.20181203
# 配置 prometheus.yml
cat prometheus.yml
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
- job_name: 'Host'
file_sd_configs:
- files:
- host.yml
metrics_path: /metrics
relabel_configs:
- source_labels: [__address__]
regex: (.*)
target_label: instance
replacement: $1
- source_labels: [__address__]
regex: (.*)
target_label: __address__
replacement: $1:9100
- job_name: 'MySQL'
file_sd_configs:
- files:
- mysql.yml
metrics_path: /metrics
relabel_configs:
- source_labels: [__address__]
regex: (.*)
target_label: instance
replacement: $1
- source_labels: [__address__]
regex: (.*)
target_label: __address__
replacement: $1:9104
- job_name: 'prometheus'
static_configs:
- targets:
- localhost:9090
cat host.yml
- labels:
service: test
targets:
- 192.168.0.248
- 192.168.0.237
cat mysql.yml
- labels:
service: test
targets:
- 192.168.0.237
# 测试 prometheus 是否可以正常启动
/iba/prometheus/prometheus --storage.tsdb.retention=30d &
ps -ef|grep prometh
kill -9 14650
# 配置 prometheus.service 文件
vi /usr/lib/systemd/system/prometheus.service
# 内容为
[Unit]
Description=Prometheus instance
Wants=network-online.target
After=network-online.target
[Service]
User=root
Group=root
Type=simple
Restart=on-failure
WorkingDirectory=/iba/prometheus/
RuntimeDirectory=prometheus
RuntimeDirectoryMode=0750
ExecStart=/iba/prometheus/prometheus --storage.tsdb.retention=30d --config.file=/iba/prometheus/prometheus.yml
LimitNOFILE=10000
TimeoutStopSec=20
[Install]
WantedBy=multi-user.target
# 启动 prometheus
systemctl start prometheus
systemctl status prometheus -l
# 开放防火墙
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.0.0/16" accept"
firewall-cmd --reload
Browser access to input http://192.168.0.248:9090
prometheus.yml File Reference:
https://prometheus.io/docs/prometheus/latest/configuration/configuration/
https://prometheus.io/docs/prometheus/latest/configuration/configuration/#%3Crelabel_config%3E
HTTPS: / /prometheus.io/docs/prometheus/latest/configuration/configuration/#%3Cfile_sd_config%3E
Installation node_exporter obtain host information
# 解压 node_exporter
cd /data/software/
tar xf node_exporter-0.15.2.linux-amd64.tar.gz -C /usr/local
mv node_exporter-0.15.2.linux-amd64 node_exporter
nohup ./node_exporter &
Installation grafana
cd /iba/software
# 解压
tar xf grafana-4.6.3.linux-x64.tar.gz -C /iba/prometheus/
cd /iba/prometheus/
mv grafana-4.6.3 grafana
cd grafana/
# 测试
./bin/grafana-server
# 停止
ctrl+c
cat /usr/lib/systemd/system/grafana-server.service
[Unit]
Description=Grafana instance
Documentation=http://docs.grafana.org
Wants=network-online.target
After=network-online.target
[Service]
User=root
Group=root
Type=simple
Restart=on-failure
WorkingDirectory=/iba/prometheus/grafana
RuntimeDirectory=grafana
RuntimeDirectoryMode=0750
ExecStart=/iba/prometheus/grafana/bin/grafana-server
LimitNOFILE=10000
TimeoutStopSec=20
[Install]
WantedBy=multi-user.target
# 启动
systemctl start grafana-server
systemctl status grafana-server -l
Access http://192.168.0.248:3000, the default user and password is admin / admin
Configuration data source
Download grafana-dashboards-1.6.1.tar.gz, decompression, use the browser to import dashboard, download address: https: //github.com/percona/grafana-dashboards/archive/v1.6.1.tar.gz
In 192.168.0.237 installation node_exporter and mysqld_exporter
cd /iba/software/
tar zxf node_exporter-0.15.2.linux-amd64.tar.gz -C /usr/local/
cd /usr/local/
mv node_exporter-0.15.2.linux-amd64 node_exporter
# 启动
cd node_exporter/
nohup ./node_exporter &
After a few minutes grafana the emergence of new server's information
Configuring monitoring used in the mysql user
GRANT REPLICATION CLIENT, PROCESS, SELECT ON *.* TO 'mysql_monitor'@'%' IDENTIFIED BY 'mysql_monitor';
FLUSH PRIVILEGES;
cd /iba/software/
tar zxf mysqld_exporter-0.10.0.linux-amd64.tar.gz -C /usr/local/
cd /usr/local/
mv mysqld_exporter-0.10.0.linux-amd64/ mysqld_exporter
cd mysqld_exporter/
# 在 mysql 上创建一个专门用于监控的用户,
cat .my.cnf
[client]
user=mysql_monitor
password=mysql_monitor
# 启动
nohup /usr/local/mysqld_exporter/mysqld_exporter -config.my-cnf="/usr/local/mysqld_exporter/.my.cnf" &
Importing dashboard: MySQL_Overview.json
Chart
surroundings
IP | surroundings | Software to be installed |
---|---|---|
192.168.0.237 | mysql-5.7.20 | node_exporter-0.15.2.linux-amd64.tar.gz mysqld_exporter-0.10.0.linux-amd64.tar.gz |
192.168.0.248 | grafana + Prometheus | amd64targz-210linux-prometheus nodeexporter-0152linux-amd64targz grafana-463linux-x64targz |
192.168.0.248 in the installation grafana prometheus
Installation prometheus
# 创建保存软件的目录
mkdir /data/software/ -p
cd /data/software/
# 解压 prometheus
tar xvf prometheus-2.1.0.linux-amd64.tar.gz -C /iba/
cd /iba/
mv prometheus-2.1.0.linux-amd64 prometheus
cd prometheus/
cp prometheus.yml /tmp/prometheus.yml.20181203
# 配置 prometheus.yml
cat prometheus.yml
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
- job_name: 'Host'
file_sd_configs:
- files:
- host.yml
metrics_path: /metrics
relabel_configs:
- source_labels: [__address__]
regex: (.*)
target_label: instance
replacement: $1
- source_labels: [__address__]
regex: (.*)
target_label: __address__
replacement: $1:9100
- job_name: 'MySQL'
file_sd_configs:
- files:
- mysql.yml
metrics_path: /metrics
relabel_configs:
- source_labels: [__address__]
regex: (.*)
target_label: instance
replacement: $1
- source_labels: [__address__]
regex: (.*)
target_label: __address__
replacement: $1:9104
- job_name: 'prometheus'
static_configs:
- targets:
- localhost:9090
cat host.yml
- labels:
service: test
targets:
- 192.168.0.248
- 192.168.0.237
cat mysql.yml
- labels:
service: test
targets:
- 192.168.0.237
# 测试 prometheus 是否可以正常启动
/iba/prometheus/prometheus --storage.tsdb.retention=30d &
ps -ef|grep prometh
kill -9 14650
# 配置 prometheus.service 文件
vi /usr/lib/systemd/system/prometheus.service
# 内容为
[Unit]
Description=Prometheus instance
Wants=network-online.target
After=network-online.target
[Service]
User=root
Group=root
Type=simple
Restart=on-failure
WorkingDirectory=/iba/prometheus/
RuntimeDirectory=prometheus
RuntimeDirectoryMode=0750
ExecStart=/iba/prometheus/prometheus --storage.tsdb.retention=30d --config.file=/iba/prometheus/prometheus.yml
LimitNOFILE=10000
TimeoutStopSec=20
[Install]
WantedBy=multi-user.target
# 启动 prometheus
systemctl start prometheus
systemctl status prometheus -l
# 开放防火墙
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.0.0/16" accept"
firewall-cmd --reload
Browser access to input http://192.168.0.248:9090
prometheus.yml File Reference:
https://prometheus.io/docs/prometheus/latest/configuration/configuration/
https://prometheus.io/docs/prometheus/latest/configuration/configuration/#%3Crelabel_config%3E
HTTPS: / /prometheus.io/docs/prometheus/latest/configuration/configuration/#%3Cfile_sd_config%3E
Installation node_exporter obtain host information
# 解压 node_exporter
cd /data/software/
tar xf node_exporter-0.15.2.linux-amd64.tar.gz -C /usr/local
mv node_exporter-0.15.2.linux-amd64 node_exporter
nohup ./node_exporter &
Installation grafana
cd /iba/software
# 解压
tar xf grafana-4.6.3.linux-x64.tar.gz -C /iba/prometheus/
cd /iba/prometheus/
mv grafana-4.6.3 grafana
cd grafana/
# 测试
./bin/grafana-server
# 停止
ctrl+c
cat /usr/lib/systemd/system/grafana-server.service
[Unit]
Description=Grafana instance
Documentation=http://docs.grafana.org
Wants=network-online.target
After=network-online.target
[Service]
User=root
Group=root
Type=simple
Restart=on-failure
WorkingDirectory=/iba/prometheus/grafana
RuntimeDirectory=grafana
RuntimeDirectoryMode=0750
ExecStart=/iba/prometheus/grafana/bin/grafana-server
LimitNOFILE=10000
TimeoutStopSec=20
[Install]
WantedBy=multi-user.target
# 启动
systemctl start grafana-server
systemctl status grafana-server -l
Access http://192.168.0.248:3000, the default user and password is admin / admin
Configuration data source
Download grafana-dashboards-1.6.1.tar.gz, decompression, use the browser to import dashboard, download address: https: //github.com/percona/grafana-dashboards/archive/v1.6.1.tar.gz
In 192.168.0.237 installation node_exporter and mysqld_exporter
cd /iba/software/
tar zxf node_exporter-0.15.2.linux-amd64.tar.gz -C /usr/local/
cd /usr/local/
mv node_exporter-0.15.2.linux-amd64 node_exporter
# 启动
cd node_exporter/
nohup ./node_exporter &
After a few minutes grafana the emergence of new server's information
Configuring monitoring used in the mysql user
GRANT REPLICATION CLIENT, PROCESS, SELECT ON *.* TO 'mysql_monitor'@'%' IDENTIFIED BY 'mysql_monitor';
FLUSH PRIVILEGES;
cd /iba/software/
tar zxf mysqld_exporter-0.10.0.linux-amd64.tar.gz -C /usr/local/
cd /usr/local/
mv mysqld_exporter-0.10.0.linux-amd64/ mysqld_exporter
cd mysqld_exporter/
# 在 mysql 上创建一个专门用于监控的用户,
cat .my.cnf
[client]
user=mysql_monitor
password=mysql_monitor
# 启动
nohup /usr/local/mysqld_exporter/mysqld_exporter -config.my-cnf="/usr/local/mysqld_exporter/.my.cnf" &
Importing dashboard: MySQL_Overview.json