0

我正在尝试使用 Prometheus 从 MariaDB 获取数据。尤其是 Userstat 表。

我有三台机器。在第一个上,我安装了 MariaDB 数据库,在第二个上我安装了 Prometheus,第三个上安装了 Grafana。

我在 MariaDB 上设置了用户状态功能SET GLOBAL userstat=1; 并创建了 mysql_exporter 用户

MariaDB [(none)]> CREATE USER 'exporter'@'444.333.22.111' IDENTIFIED BY 'password';
MariaDB [(none)]> GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'444.333.22.111';
MariaDB [(none)]> FLUSH PRIVILEGES;

接下来我在第二台机器上安装了 Prometheus 和 mysql exporter。我也从存储库和 mysql_exporter 获得了 Prometheus。

我的出口商的路径是:/etc/default/prometheus-mysqld-exporter并且看起来像:

# By default the connection string will be read from
# $HOME/my.cnf or -config.my-cnf.
# To set a connection string from the environment instead, uncomment the
# following line.

 export DATA_SOURCE_NAME="exporter:password@(444.333.22.111:3306)/mysql"
# Set the command-line arguments to pass to the exporter.
# ARGS='-config.my-cnf /etc/mysql/debian.cnf'

    -collect.auto_increment.columns
    -collect.binlog_size
    -collect.info_schema.userstats
    -config.my-cnf string
    -web.listen-address=0.0.0.0:9104

普罗米修斯.yml:

# Sample config for Prometheus.

global:
  scrape_interval:     1s # By default, scrape targets every 15 seconds.
  evaluation_interval: 15s # By default, scrape targets every 15 seconds.
  # scrape_timeout is set to the global default (10s).

  # Attach these labels to any time series or alerts when communicating with
  # external systems (federation, remote storage, Alertmanager).
  external_labels:
      monitor: 'example'

# Load and evaluate rules in this file every 'evaluation_interval' seconds.
rule_files:
  # - "first.rules"
  # - "second.rules"

# 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'

    # Override the global default and scrape targets from this job every 5 seconds.
    scrape_interval: 5s
    scrape_timeout: 5s

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

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

  - job_name: node
    # If prometheus-node-exporter is installed, grab stats about the local
    # machine by default.
    static_configs:
      - targets: ['localhost:9100']

不幸的是,它没有做我想做的事,并继续监控我安装了 Prometheus 的机器。任何想法可能是问题所在?提前致谢!

4

1 回答 1

1

让我们首先尝试理解这一点,Exporter需要监控来自远程服务器的指标,因此 exporter 的配置应该是正确的,因为它正在尝试请求MariaDB服务器的 IP 即444.333.22.111(远程服务器 IP)。

MariaDB服务器应该将Exporter服务器的 IP 列入白名单,以允许来自那里的任何请求。

解决方案: 当您在MariaDB中创建用户时,在您的情况下是'exporter'@'444.333.22.111',因此这意味着您将444.333.22.111用户列入白名单exporter

但是,您应该将服务器的 IP 列入白名单,在哪里prometheus-mysqld-exporter设置。但在你的情况下,它是不同的服务器。所以应该是这样的

MariaDB [(none)]> CREATE USER ' exporter '@'出口服务器的 IP ' IDENTIFIED BY 'password'; MariaDB [(none)]> GRANT PROCESS, REPLICATION CLIENT, SELECT ON TO '出口商'@'出口商服务器IP '; MariaDB [(none)]> 刷新权限;

试试这个,如果您遇到任何错误,请告诉我,同时尝试查看prometheus-mysqld-exporter日志。

于 2021-07-09T17:06:54.010 回答