性能测试探讨

Prometheus+Grafana监控MySQL

2020-04-29  本文已影响0人  仰望_

1、先安装GO

$ yum install go
$ go version
go version go1.11.5 linux/amd64

2、下载安装Prometheus

$ wget https://github.com/prometheus/prometheus/releases/download/v1.6.2/prometheus-1.6.2.linux-amd64.tar.gz
$ tar xvf prometheus-1.6.2.linux-amd64.tar.gz -C /usr/local/
$ ln -sv /usr/local/prometheus-1.6.2.linux-amd64/ /usr/local/prometheus
$ cd /usr/local/prometheus

3、配置文件prometheus.yml (替换你要监控的IP地址)

scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ['localhost:9090']

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

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

4、启动Prometheus

$ ./prometheus -config.file=prometheus.yml

5、访问Prometheus的web界面

http://ip:9090

6、安装并运行exporter

$ wget https://github.com/prometheus/node_exporter/releases/download/v0.14.0/node_exporter-0.14.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
$ tar xvf node_exporter-0.14.0.linux-amd64.tar.gz -C /usr/local/
$ nohup /usr/local/node_exporter-0.14.0.linux-amd64/node_exporter &

7、创建MySQL用户及分配权限

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

8、使用环境变量方式启动mysqld_exporter

$ export DATA_SOURCE_NAME='exporter:password@(localhost:3306)/'
$ ./mysqld_exporter-0.10.0.linux-amd64/mysqld_exporter

9、在Grafana中配置DataSource
在设置中选择data sources-- add data source

配置DataSource
10、在https://grafana.com/grafana/dashboards/7362下载json
下载json
11、导入json到Grafana
image.png
image.png
12、在Grafana界面查看mysql监控
监控
上一篇下一篇

猜你喜欢

热点阅读