You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置Prometheus采集数据以解决Grafana监控面板无数据问题

问题:Prometheus监控面板无数据,仅MySQL数据源正常

已在服务器上安装Grafana和Prometheus搭建监控面板,添加若干面板后发现几乎所有面板均处于无数据状态。但配置的MySQL数据源可正常查询并展示面板数据。现将当前prometheus.yml配置附上,请教如何让Prometheus开始采集监控数据?

当前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=<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"]
解决方法
  • 部署对应监控目标的Exporter:Prometheus无法直接采集服务器、MySQL等第三方服务的指标,必须依赖专用Exporter(比如node_exporter用于采集服务器系统指标,mysqld_exporter用于采集MySQL数据库指标)。先确认需要监控的目标已部署对应Exporter并正常运行。
  • 在prometheus.yml中添加采集配置:当前配置仅开启了Prometheus自身的采集任务,需要为每个监控目标新增scrape配置:
    1. 采集服务器指标(以node_exporter为例):
      - job_name: "node_exporter"
        static_configs:
          - targets: ["localhost:9100"] # 替换为node_exporter实际的地址和端口
      
    2. 采集MySQL指标(以mysqld_exporter为例):
      - job_name: "mysql_exporter"
        static_configs:
          - targets: ["localhost:9104"] # 替换为mysqld_exporter实际的地址和端口
        # 若MySQL需要认证,添加以下参数配置
        params:
          user: ["exporter_user"]
          password: ["exporter_password"]
      
  • 重启Prometheus服务:修改配置后,执行命令重启服务使配置生效:
    sudo systemctl restart prometheus
    
  • 验证采集状态:访问Prometheus Web界面(默认地址http://你的服务器IP:9090),进入「Status」→「Targets」页面,查看新增的采集任务是否处于UP状态。如果显示UP,说明采集正常,等待1-2分钟后Grafana面板即可加载到数据。
  • 匹配面板指标名称:确保Grafana面板使用的指标名称与Prometheus采集的指标一致,比如node_exporter的CPU使用率指标为node_cpu_seconds_total,内存总量指标为node_memory_MemTotal_bytes。

内容的提问来源于stack exchange,提问作者Martin AJ

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 21:40:29