docker pull prom/prometheus
sudo mkdir /etc/prometheus/
sudo vim /etc/prometheus/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).
# Attach these labels to any time series or alerts when communicating with
# external systems (federation, remote storage, Alertmanager).
external_labels:
monitor: 'codelab-monitor'
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first.rules"
# - "second.rules"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=` to any timeseries scraped from this config.
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['172.17.0.1:9090']
- job_name: 'mysql'
static_configs:
- targets: ['172.17.0.1:9104']
labels:
instance: mysql
- job_name: 'monitor'
static_configs:
- targets: ['172.17.0.1:9100']
labels:
instance: monitor
# 因为目录/data用户组和用户是jtserver,docker执行命令是root用户,先将/data/lib/prometheus给其他组权限才能执行
sudo mkdir /data/lib/prometheus
sudo chmod 767 /data/lib/prometheus
docker run -d \
-p 9090:9090 \
--restart=always \
--name prometheus \
-v /data/lib/prometheus:/data/lib/prometheus \
-v /etc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \
prom/prometheus \
--config.file=/etc/prometheus/prometheus.yml \
--storage.tsdb.path=/data/lib/prometheus
docker pull prom/node-exporter
docker run -d \
-v "/proc:/host/proc:ro" \
-v "/sys:/host/sys:ro" \
-v "/:/rootfs:ro" \
--net="host" \
--restart=always \
prom/node-exporter \
--path.procfs /host/proc \
--path.sysfs /host/sys \
--collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)"
docker pull prom/node-exporter:v0.14.0
docker run -d -p 9100:9100 \
-v "/proc:/host/proc:ro" \
-v "/sys:/host/sys:ro" \
-v "/:/rootfs:ro" \
--net="host" \
--restart=always \
prom/node-exporter:v0.14.0 \
--collector.procfs /host/proc \
--collector.sysfs /host/sys \
--collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)"
docker pull prom/node-exporter
docker pull prom/mysqld-exporter
四、监控mysql信息
docker pull prom/mysqld-exporter
mysql> INSERT INTO mysql.user(Host,User,Password) VALUES("localhost", "mysql_monitor", password("mysql_monitor"));
mysql> GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'mysql_monitor'@'localhost' IDENTIFIED BY 'mysql_monitor';
mysql> GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'mysql_monitor'@'%' IDENTIFIED BY 'mysql_monitor';
mysql> FLUSH PRIVILEGES;
docker run -d -p 9104:9104 \
--name=mysqld-exporter \
--restart=always \
-e DATA_SOURCE_NAME="mysql_monitor:mysql_monitor@(172.17.0.1:3306)/" \
prom/mysqld-exporter
五、安装和配置grafana
wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana_5.1.4_amd64.deb
sudo apt-get install -y adduser libfontconfig
sudo dpkg -i grafana_5.1.4_amd64.deb
echo "deb https://packagecloud.io/grafana/stable/debian/ stretch main" | sudo tee sources.list.d/grafana-stable.list
curl https://packagecloud.io/gpg.key | sudo apt-key add -
sudo apt-get install -y apt-transport-https
sudo apt-get update
sudo apt-get install grafana
sudo update-rc.d grafana-server defaults
#################################### Dashboards History ##################
[dashboards]
# Number dashboard versions to keep (per dashboard). Default: 20, Minimum: 1
;versions_to_keep = 20
enabled = true
path = /var/lib/grafana/dashboards
git clone https://github.com/percona/grafana-dashboards.git
cp -r grafana-dashboards/dashboards /var/lib/grafana/
sudo service grafana-server restart
添加percona-app插件
grafana-cli plugins install percona-percona-app