docker + grafana + prometheus + Mysql

1、prometheus 部署,系统架构图

2、prometheus 部署过程

1. docker pull  prom/prometheus
2. docker run -p 9090:9090 -v /prometheus-data \
       prom/prometheus --config.file=/prometheus-data/prometheus.yml
3. prometheus.yml
global:
  scrape_interval:     15s
  evaluation_interval: 15s

scrape_configs:
  - job_name: linux
    static_configs:
      - targets: ['host:9100']
        labels:
          instance: db1

  - job_name: mysql
    static_configs:
      - targets: ['host:9104']
        labels:
          instance: db1

 - job_name: 'consul-knowledge'
    metrics_path: '/actuator/prometheus'
    consul_sd_configs:
      - server: '10.1.204.114:8500'
        services: ['knowledge-service']

3、部署exporter

$ wget https://github.com/prometheus/node_exporter/releases/download/v0.16.0/node_exporter-0.16.0.linux-amd64.tar.gz
$ wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.10.0/mysqld_exporter-0.10.0.linux-amd64.tar.gz -O mysqld_exporter-0.10.0.linux-amd64.tar.gz
$ mkdir /usr/local/services/prometheus_exporters
$ tar zxf node_exporter-0.14.0.linux-amd64.tar.gz -C /usr/local/services/prometheus_exporters --strip-components=1
$ tar zxf mysqld_exporter-0.10.0.linux-amd64.tar.gz -C /usr/local/services/prometheus_exporters --strip-components=1


运行node_exporter
$ cd /usr/local/services/prometheus_exporters
$ ./node_exporter

 

4、mysqld_exporter需要连接到Mysql,所以需要Mysql的权限,我们先为它创建用户并赋予所需的权限:

mysql> GRANT REPLICATION CLIENT, PROCESS ON *.* TO 'prom'@'localhost' identified by 'abc123';
mysql> GRANT SELECT ON performance_schema.* TO 'prom'@'localhost';


cd /usr/local/services/prometheus_exporters
$ cat << EOF > .my.cnf
[client]
user=prom
password=abc123
EOF
$ ./mysqld_exporter -config.my-cnf=".my.cnf"  

5、部署grafana

docker pull grafana/grafana

docker run -d --name=grafana -p 3000:3000 grafana/grafana

server:
https://grafana.com/dashboards/8919
mysql:
https://grafana.com/dashboards/6239

 

6、访问地址:

http://10.1.204.108:3000/d/9CWBz0bik/1-node-exporter-0-16-jian-kong-zhan-shi-kan-ban-for-prometheus?orgId=1

 

 

 

 

 

 

你可能感兴趣的:(linux,linux,docker)