Environment  环境

SUSE Rancher Longhorn   SUSE 牧场长角牛

Procedure  程序

Overview  概述

Longhorn integrates seamlessly with Prometheus, providing comprehensive visibility into the health and performance of your storage environment. Prometheus collects a wide range of metrics across Longhorn and related system components, enabling effective monitoring of volumes, disks, and nodes throughout the cluster.
Longhorn 与 Prometheus 无缝集成,全面了解您的存储环境健康状况和性能。Prometheus 收集了 Longhorn 及相关系统组件的广泛指标,能够有效监控集群中的卷、磁盘和节点。

Rancher integrates Prometheus and Grafana to monitor Kubernetes nodes, components, and workloads. To enable Rancher Monitoring refer the official documentation.
Rancher 集成了 Prometheus 和 Grafana,用于监控 Kubernetes 节点、组件和工作负载。 要启用牧场主监控,请参阅官方文档 

If Rancher Monitoring is already enabled, Longhorn metrics can be scraped by deploying a ServiceMonitor in the Longhorn-system namespace.
如果已经启用了牧场主监控,可以通过在 Longhorn 系统命名空间中部署 ServiceMonitor 来抓取 Longhorn 的指标。

Step 1: Deploy Longhorn ServiceMonitor
步骤 1:部署 Longhorn ServiceMonitor

Apply the following manifest:
应用以下清单:

<span style="color:#000000"><span style="background-color:#ffffff"><span style="background-color:#efefef"><code>apiVersion: <a data-cke-saved-href="http://monitoring.coreos.com/v1" href="http://monitoring.coreos.com/v1">monitoring.coreos.com/v1</a>
kind: ServiceMonitor
metadata:
  name: longhorn-prometheus-servicemonitor
  namespace: longhorn-system
  labels:
    name: longhorn-prometheus-servicemonitor
spec:
  selector:
    matchLabels:
      app: longhorn-manager
  namespaceSelector:
    matchNames:
    - longhorn-system
  endpoints:
  - port: manager</code></span></span></span>

After deployment, Prometheus will automatically discover and collect Longhorn metrics.
部署后,普罗米修斯会自动发现并收集长角牛的指标。

Validation:  验证:
Check metrics by running a query such as below in the Prometheus UI or check if the prometheus target is showing UP:
通过在 Prometheus 界面中运行查询,或检查 Prometheus 目标是否显示为 UP:

<span style="color:#000000"><span style="background-color:#ffffff"><span style="background-color:#efefef"><code>longhorn_disk_usage_bytes</code></span></span></span>

Step 2: Visualizing Metrics in Grafana
第二步:在 Grafana 中可视化度量

Accessing Grafana  访问格拉法纳

  1. In Rancher UI, navigate to your Cluster
    在 Rancher 界面中,导航到你的集群

  2. Go to Cluster Tools (or Apps depending on Rancher version)
    进入集群工具(或根据 Rancher 版本的应用)

  3. Select Monitoring

  4. Click the Grafana icon/link to open in a new tab
    点击 Grafana 图标/链接,在新标签页中打开

  5. Log in (default credentials if unchanged):
    登录(如果未更改,则使用默认凭证):

    • Username: admin  用户名:admin

    • Password: prom-operator
      密码:prom-operator

Option A — Import a Prebuilt Longhorn Dashboard
选项 A — 导入预建的 Longhorn 仪表盘

Please refer to the community Grafana dashboard library for Longhorn.
请参阅社区 Grafana 仪表盘库中的 Longhorn。

Steps:  步骤:

  1. Go to Dashboards → New → Import
    前往仪表盘→新→导入
  2. Select and import one of the available Longhorn dashboards
    选择并导入其中一个可用的 Longhorn 仪表盘
    Example: Dashboard ID 13032
    示例:仪表盘 ID 13032
  3. Select Prometheus as the data source
    选择普罗米修斯作为数据源

This provides visualization of common Longhorn storage performance metrics.
这为常见的长角牛存储性能指标提供了可视化。

Option B — Create Custom Panels
选项 B — 创建自定义面板

  1. In Grafana: From the sidebar, click → Dashboard → Add new dashboard → Add Visualization
    在 Grafana 中:从侧边栏点击→仪表盘→添加新仪表盘→添加可视化
  2. Select Prometheus as the data source
    选择普罗米修斯作为数据源
  3. You can either use the Query Builder to construct queries visually, or switch to the Code mode to write PromQL directly.
    你可以使用查询构建器来可视化构建查询,或者切换到代码模式直接编写 PromQL。

Example PromQL for node storage utilization percentage:
节点存储利用率示例 PromQL:

<span style="color:#000000"><span style="background-color:#ffffff"><span style="background-color:#efefef"><code>(longhorn_node_storage_usage_bytes / longhorn_node_storage_capacity_bytes) * 100</code></span></span></span>

  Additional recommended metrics:
  其他推荐指标:

  • longhorn_node_count_total
  • longhorn_instance_manager_cpu_usage_millicpu
  • longhorn_node_cpu_capacity_millicpu

Adjust panel type, legends, and thresholds as required
根据需要调整面板类型、图例和阈值

Step 3: Save Dashboard  步骤3:保存仪表盘

  • Provide a descriptive name in title section and save the dashboard
    在标题部分提供描述性名称并保存仪表盘

  • Optionally export as JSON for reuse across environments
    可选地导出为 JSON 以便在不同环境中重复使用

访问Rancher-K8S解决方案博主,企业合作伙伴 :
https://blog.csdn.net/lidw2009

Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐