配置 Grafana 以可视化从 Managed Instance 群集发出的指标

部署 Azure 托管实例 for Apache Cassandra 群集时,该服务会在每个数据节点上预配 Metrics Collector for Apache Cassandra 代理软件。 Prometheus 采集指标,并通过 Grafana 进行可视化。 本文介绍如何配置 Prometheus 和 Grafana,以可视化从 Managed Instance 群集发出的指标。

需要执行以下任务才能可视化指标:

  • 在 Managed Instance 所在的Azure虚拟网络中部署 Ubuntu 虚拟机(VM)。
  • 将 Prometheus 仪表板 安装到 VM 上。

警告

Prometheus 和 Grafana 是开源软件,不属于 Azure 托管实例 for Apache Cassandra 的支持范围。 按照本文中所述的方式可视化指标,需要您托管并维护一台 VM,将其用作 Prometheus 和 Grafana 的服务器。 本文中的说明仅针对 Ubuntu Server 18.04 进行了测试。 不能保证它们与其他 Linux 分发版一起使用。

遵循此方法意味着必须支持可能出现的任何问题,例如空间不足或服务器的可用性不足。 对于完全受支持的托管指标体验,请考虑使用Azure Monitor指标或Azure Monitor合作伙伴集成。

部署 Ubuntu 服务器

  1. 登录到 Azure 门户。

  2. 转到 Managed Instance 群集所在的资源组。 选择 “添加” 并搜索 Ubuntu Server 18.04 LTS 映像。

    显示从 Azure 门户查找 Ubuntu 服务器映像的屏幕截图。

  3. 选择映像,然后选择“ 创建”。

  4. 在“ 创建虚拟机 ”窗格中,输入以下字段的值。 可以保留其他字段的默认值:

    • 虚拟机名称:输入 VM 的名称。
    • 区域:选择部署虚拟网络的同一区域。

    显示填写表单以使用 Ubuntu 服务器映像创建 VM 的屏幕截图。

  5. 在“网络”选项卡上,选择部署 Managed Instance 的虚拟网络。

    显示配置 Ubuntu 服务器网络设置的屏幕截图。

  6. 最后,选择“查看并创建”以创建指标服务器。

安装 Prometheus 仪表板

  1. 首先,确保新部署的 Ubuntu 服务器的网络设置具有允许端口 3000 和 9090 入站访问的规则。 Prometheus 和 Grafana 稍后需要这些端口。

    显示允许的端口的屏幕截图。

  2. 使用 Azure CLI 或首选客户端工具通过 Secure Shell 进行连接,连接到 Ubuntu 服务器。

  3. 连接到 VM 后,安装指标收集器软件。 首先,下载并解压缩文件:

     #install unzip utility (if not already installed)
     sudo apt install unzip
    
     #get dashboards
     wget https://github.com/datastax/metric-collector-for-apache-cassandra/releases/download/v0.3.0/datastax-mcac-dashboards-0.3.0.zip -O temp.zip
     unzip temp.zip
    
  4. 接下来,转到 Prometheus 目录并使用 vi 编辑 tg_mcac.json 文件:

     cd */prometheus
     vi tg_mcac.json    
    
  5. 在 targets 中添加群集中每个节点的 IP 地址,每个地址都使用 9443 端口。 文件 tg_mcac.json 应如以下示例所示:

     [
       {
         "targets": [
           "10.9.0.6:9443","10.9.0.7:9443","10.9.0.8:9443"
         ],
         "labels": {
    
         }
       }
     ]  
    
  6. 保存文件。 接下来,在同一目录中编辑 prometheus.yaml 该文件。 找到以下部分:

     file_sd_configs:
       - files:
         - 'tg_mcac.json'
    
  7. 在本部分的正下方,添加以下代码片段。 此步骤是必需的,因为指标是通过 HTTPS 公开的。

     scheme: https
     tls_config:
             insecure_skip_verify: true
    
  8. 该文件现在应如以下示例所示。 确保每行中的制表符与示例匹配:

     file_sd_configs:
       - files:
         - 'tg_mcac.json'
     scheme: https
     tls_config:
             insecure_skip_verify: true
    
  9. 保存文件。 现在,你可以启动 Prometheus 和 Grafana。 首先,安装 Docker:

    sudo apt install apt-transport-https ca-certificates curl software-properties-common
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu `lsb_release -cs` test"
    sudo apt update
    sudo apt install docker-ce
    
  10. 然后安装 docker-compose:

    sudo apt install docker-compose
    
  11. 现在,转到 docker-compose.yaml 所在的顶级目录,并启动应用程序:

    cd ..
    sudo docker-compose up
    
  12. Prometheus 应该可通过指标服务器上的端口 9090 访问,Grafana 仪表板可通过端口 3000 访问。

    在仪表板中查看 Cassandra Managed Instance 指标。

本文介绍了如何使用 Grafana 配置仪表板以可视化 Prometheus 中的指标。 通过以下文章详细了解适用于 Apache Cassandra 的 Azure 托管实例: