docker下prometheus安装mysqld-exporter

一、安装mysqld-exporter

1、下载mysqld-exporter:docker pull prom/mysqld-exporter

2、根据自己配置的数据库用户名和密码进行启动

docker run -d --name mysqld_exporter -p 9104:9104 -e DATA_SOURCE_NAME="root:newmysql(127.0.0.1:3306)/" prom/mysqld-exporter

3、查看启动过的容器实例:docker ps -a

4、自动启动:docker update --restart=always b3cfe4658581

5、切换root用户操作,修改prometheus配置文件

cd /usr/local/prometheus/data

编辑prometheus.yml文件:vim 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).

# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# 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: ['192.168.184.130:9090']

  - job_name: 'mysql'
    static_configs:
    - targets: ['192.168.184.130:9104']

6、查看启动过的容器实例:docker ps -a

7、自动启动:docker update --restart=always c12a1f682abb

8、重启prometheus:docker restart e21b260d923d

8、重启mysqld-exporter:docker restart b3cfe4658581

9、登录prometheus进行查看:http://192.168.184.130:9090/

docker下prometheus安装mysqld-exporter_第1张图片

你可能感兴趣的:(Prometheus,运维,docker,prometheus)