普罗米修斯MySQL监控

1.下载MySQL的exporter

下载地址:https://prometheus.io/download/

 2.上传到需要监控的MySQL的机器上进行解压

 解压安装

 tar -xzvf mysqld_exporter-0.14.0.linux-amd64.tar.gz 

 为了后续使用方便将名称修改为:mysqld_exporter

在mysql中创建用户并授权!!

CREATE USER  'mysqld_exporter'@'%'  IDENTIFIED BY  'mysqld_exporter';
GRANT REPLICATION CLIENT,PROCESS ON *.* TO 'mysqld_exporter'@'%' identified by 'mysqld_exporter';
GRANT SELECT ON *.* TO 'mysqld_exporter'@'%';

 

启动方式1:环境变量方式,不推荐

 export DATA_SOURCE_NAME='root:123456@@(127.0.0.1:3306)/'

查看9104端口(mysqld_exporter默认)

 启动方式2:配置文件

在mysqld_exporter文件夹下创建配置文件mysqld_exporter.cnf

 内容参考如下:

复制代码
[client]
# mysql用户名
user=mysqld_exporter
# mysql的密码
password=mysqld_exporter
# 主机地址
host=127.0.0.1
# mysql端口号
port=3306
复制代码

 启动服务

./mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/mysqld_exporter.cnf

nohup /usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/mysqld_exporter.cnf

 

启动方式3:配置systemd启动mysqld_exporter

复制代码
[Unit]
Description=mysqld_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/mysqld_exporter.cnf
Restart=on-failure
[Install]
WantedBy=multi-user.target
复制代码
复制代码
#重新载入
systemctl daemon-reload
#启动服务
systemctl start mysqld_exporter
#重启服务
systemctl restart mysqld_exporter
#查看服务运行状态
systemctl status mysqld_exporter.service
#查看端口
ss -lnpt|grep 9104
复制代码

 

修改普罗米修斯web的配置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=<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: "mysql114"
    static_configs:
      - targets: ["10.0.0.13:9104"]
复制代码

修改后重新启动

 查看web界面:

 这是为什么呢?是因为13的服务器开着防火墙呢。

 关闭防火墙后再看状态

 再次查看web界面就正常了。

 

 如果想收集Windows版本的mysql

1.下载

https://prometheus.io/download/

2.添加my.cnf配置,默认是没有my.cnf的需要自己建立

复制代码

[client]


user=mysqld_exporter
password=mysqld_exporter
host=127.0.0.1
port=3306

 
复制代码

 

3.cmd管理员权限进入路径

 

 

参考地址:https://www.likecs.com/show-205181945.html

posted @   创客未来  阅读(172)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示