https://github.com/prometheus/mysqld_exporter

    1. tar xvf mysqld_exporter-0.12.1.linux-amd64.tar.gz
    2. ln -s mysqld_exporter-0.12.1.linux-amd64 mysqld_exporter
    vim /opt/mysqld_exporter/.my.cnf  
    [client]
    host=127.0.0.1
    user=root
    password=rootpasswd
    
    cat > /usr/lib/systemd/system/mysqld_exporter.service <<EOF
    [Unit]
    Description=mysqld_exporter
    Documentation=
    After=network.target
    
    [Service]
    Type=simple
    WorkingDirectory=/opt/mysqld_exporter
    ExecStart=/opt/mysqld_exporter/mysqld_exporter --config.my-cnf=.my.cnf
    ExecStop=/bin/kill -KILL \$MAINPID
    ExecReload=/bin/kill -HUP \$MAINPID
    KillMode=control-group
    Restart=on-failure
    RestartSec=3s
    
    [Install]
    WantedBy=multi-user.target
    EOF
    
    [root@kafka1 mysqld_exporter]# systemctl enable mysqld_exporter
    Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld_exporter.service to /usr/lib/systemd/system/mysqld_exporter.service.
    [root@kafka1 mysqld_exporter]# systemctl start mysqld_exporter 
    [root@kafka1 mysqld_exporter]# systemctl status mysqld_exporter
    

    测试查看metrics
    http://192.168.0.15:9104/metrics

    prometheus.yml新增job

      - job_name: 'mysqld_exporter'
        file_sd_configs:
          - files: ['/opt/prometheus/targets/mysql_sd_configs/*.json']
            refresh_interval: 5s
    

    新增target

    mkdir -p /opt/prometheus/targets/mysql_sd_configs/
    vim /opt/prometheus/targets/mysql_sd_configs/mysqls.json
    [{
            "labels": {
                    "ip": "192.168.0.15",
                    "hostname": "test-wk",
                    "env": "test"
            },
            "targets": ["192.168.0.15:9104"]
    }]
    
    systemctl reload prometheus
    

    http://192.168.0.15:9090/targets
    image.png
    granfa导入图形模板
    ID:7362

    image.png