腾讯云国际站代理商:‌如何搭建Grafana可视化监控?

简介:TG@luotuoemo

本文由腾讯云代理商【聚搜云】撰写

1. 安装Prometheus

  1. 下载并解压Prometheus:

    bash

    cd /opt
    wget https://github.com/prometheus/prometheus/releases/download/v3.2.0/prometheus-3.2.0.linux-amd64.tar.gz
    tar -xvzf prometheus-3.2.0.linux-amd64.tar.gz
    mv prometheus-3.2.0.linux-amd64 prometheus
    
  2. 配置Prometheus的prometheus.yml文件,添加监控目标:

    yaml

    scrape_configs:
      - job_name: 'node'
        static_configs:
          - targets: ['localhost:9100']
    
  3. 启动Prometheus服务:

    bash

    ./prometheus --config.file=prometheus.yml
    
  4. 验证Prometheus是否运行正常,访问http://localhost:9090

2. 安装Node Exporter

  1. 下载并解压Node Exporter:

    bash

    cd /opt
    wget https://github.com/prometheus/node_exporter/releases/download/v1.9.0/node_exporter-1.9.0.linux-amd64.tar.gz
    tar -xvzf node_exporter-1.9.0.linux-amd64.tar.gz
    mv node_exporter-1.9.0.linux-amd64 node_exporter
    
  2. 启动Node Exporter服务:

    bash

    ./node_exporter
    
  3. 验证Node Exporter是否运行正常,访问http://localhost:9100/metrics

3. 安装Grafana

  1. 安装Grafana:

    bash

    sudo yum install -y https://dl.grafana.com/oss/release/grafana-10.4.16-1.x86_64.rpm
    
  2. 启动Grafana服务:

    bash

    sudo systemctl start grafana-server
    sudo systemctl enable grafana-server
    
  3. 验证Grafana是否运行正常,访问http://localhost:3000,默认用户名和密码均为admin

4. 配置Grafana

  1. 登录Grafana后,添加Prometheus作为数据源:

    • 进入“配置”->“数据源”。
    • 选择“添加数据源”,选择Prometheus
    • 填写Prometheus的URL。
  2. 保存并测试数据源,确保连接正常。

5. 创建仪表盘

  1. 进入仪表盘->新建
  2. 选择Prometheus作为数据源。
  3. 输入PromQL语句,如node_cpu_seconds_total,点击运行查看数据。
  4. 可以通过导入模板快速创建仪表盘,选择一个模板ID并导入。