Skip to content

Commit

Permalink
update monitoring.md (#4709)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhr123 authored Apr 19, 2024
1 parent d53f68a commit 2e1c40e
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 51 deletions.
56 changes: 36 additions & 20 deletions docs/en/administration/monitoring.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
---
title: Monitoring and Data Visualization
sidebar_position: 3
description: This article describes how to collect and visualize JuiceFS metrics with third-party tools such as Prometheus, Grafana, etc.
description: This guide will help you understand the monitoring metrics provided by JuiceFS, and how to visualize these metrics using Prometheus and Grafana.
---

The JuiceFS client exposes real-time metrics in [Prometheus](https://prometheus.io) format through the monitoring API. Users configure Prometheus to scrape metrics data, and then use tools such as [Grafana](https://grafana.com) to realize data visualization.
JuiceFS offers a suite of monitoring metrics, and this document outlines how to collect these metrics and visualize them with a monitoring system similar to the one depicted in the following image using Prometheus and Grafana.

## Add scrape config in Prometheus {#add-scrape-config}
![Monitoring Dashboard](../images/grafana_dashboard.png)

After JuiceFS is mounted on a host, you can access its metrics using `http://localhost:9567/metrics`, other types of JuiceFS Client (CSI Driver, S3 Gateway, Hadoop SDK) is slightly different in this regard, see [Collecting metrics data](#collect-metrics).
The setup process is as follows:

![Prometheus-client-data](../images/prometheus-client-data.jpg)
1. Configure Prometheus to scrape JuiceFS monitoring metrics.
2. Configure Grafana to read the monitoring data from Prometheus.
3. Use the official JuiceFS Grafana dashboard template to display the monitoring metrics.

Here, taking collect metrics of the mount point as an example, edit [`prometheus.yml`](https://prometheus.io/docs/prometheus/latest/configuration/configuration) to add a new scrape config (`scrape_configs`):
:::tip
This document uses open-source versions of Grafana and Prometheus for examples.
:::

## 1. Configuring Prometheus to Scrape JuiceFS Monitoring Metrics {#add-scrape-config}

After mounting JuiceFS, it will automatically expose Prometheus-formatted metrics at `http://localhost:9567/metrics`. To observe the state changes of various metrics over a time range, you'll need to set up Prometheus and configure it to periodically scrape and save these metrics.

![Prometheus Client Data](../images/prometheus-client-data.jpg)

The process for collecting metrics may vary slightly depending on the mount method or access type (such as FUSE mount, CSI Driver, S3 Gateway, Hadoop SDK, etc.). For detailed instructions, see [Collecting Monitoring metrics data](#collect-metrics).

For example, here's how you might configure Prometheus for a common FUSE mount: If you haven't already set up Prometheus, follow the [official documentation](https://prometheus.io/docs/prometheus/latest/installation).

Edit your `prometheus.yml` configuration file and add a new scrape configuration under `scrape_configs`. Define the JuiceFS client metrics address:

```yaml {20-22}
global:
Expand All @@ -26,8 +42,7 @@ alerting:
# - alertmanager:9093

rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# - "rules.yml"

scrape_configs:
- job_name: "prometheus"
Expand All @@ -47,25 +62,26 @@ Start the Prometheus service:

Visit `http://localhost:9090` to see the Prometheus interface.

## Visualizing metrics using Grafana {#grafana}
## 2. Configuring Grafana to Read from Prometheus {#grafana}

Once Prometheus begins scraping JuiceFS metrics, the next step is to set up Grafana to read from Prometheus.

If you haven't yet installed Grafana, follow the [official documentation](https://grafana.com/docs/grafana/latest/installation).

Create a new Prometheus-type data source in Grafana:
In Grafana, create a new data source of type Prometheus:

- **Name**: For identification purposes, you can fill it in with the name of the file system.
- **URL**: Data interface for Prometheus, which defaults to `http://localhost:9090`.
- **Name**: A name that helps you identify the data source, such as the name of the file system.
- **URL**: The Prometheus data API endpoint, typically `http://localhost:9090`.

![Grafana-data-source](../images/grafana-data-source.jpg)
![Grafana Data Source](../images/grafana-data-source.jpg)

JuiceFS provides some dashboard templates for Grafana, which can be imported to show the collected metrics in Prometheus:
## 3. Using the Official JuiceFS Grafana Dashboard Template {#grafana-dashboard}

| Name | Description |
|-----------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| [`grafana_template.json`](https://github.com/juicedata/juicefs/blob/main/docs/en/grafana_template.json) | For show metrics collected from mount point, S3 gateway (non-Kubernetes deployment) and Hadoop Java SDK |
| [`grafana_template_k8s.json`](https://github.com/juicedata/juicefs/blob/main/docs/en/grafana_template_k8s.json) | For show metrics collected from Kubernetes CSI Driver and S3 gateway (Kubernetes deployment) |
JuiceFS's official Grafana dashboard templates can be found in the Grafana Dashboard repository and can be imported directly into Grafana via the URL `https://grafana.com/grafana/dashboards/20794/` or by using the ID `20794`.

Our Grafana dashboard looks like this:
Here's what the official JuiceFS Grafana dashboard might look like:

![grafana_dashboard](../images/grafana_dashboard.png)
![Grafana Monitoring Dashboard](../images/grafana_dashboard.png)

## Collecting metrics data {#collect-metrics}

Expand Down
41 changes: 29 additions & 12 deletions docs/zh_cn/administration/monitoring.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
---
title: 监控与数据可视化
sidebar_position: 3
description: 本文介绍如何使用 Prometheus、Grafana 等第三方工具收集及可视化 JuiceFS 监控指标
description: 了解 JuiceFS 的监控指标,以及如何通过 Prometheus 和 Grafana 实现数据可视化
---

JuiceFS 客户端通过监控 API 对外暴露 [Prometheus](https://prometheus.io) 格式的实时监控指标,用户自行配置 Prometheus 抓取监控数据,然后通过 [Grafana](https://grafana.com) 等工具即可实现数据可视化
JuiceFS 提供了丰富的监控指标,本文介绍如何收集这些指标,并通过 Prometheus Grafana 实现类似下图的可视化监控系统

## 在 Prometheus 中添加抓取配置 {#add-scrape-config}
![grafana_dashboard](../images/grafana_dashboard.png)

搭建流程大致如下:

1. 配置 Prometheus 抓取 JuiceFS 监控指标
2. 让 Grafana 读取 Prometheus 中的监控数据
3. 用 JuiceFS 官方的 Grafana 仪表盘模板展现监控指标

:::tip 提示
本文使用开源版的 Grafana 和 Prometheus 作为例子,如果你想使用 Grafana Cloud 来构建可视化监控系统,可以参考这篇文章 [「如何使用 Grafana 监控文件系统状态」](https://juicefs.com/zh-cn/blog/usage-tips/use-grafana-monitor-file-system-status)
:::

在宿主机挂载 JuiceFS 后,默认可以通过 `http://localhost:9567/metrics` 地址获得客户端输出的实时指标数据。其他不同类型的 JuiceFS 客户端(CSI 驱动、S3 网关、Hadoop SDK)收集指标数据的方式略有区别,详见[「收集监控指标」](#collect-metrics)
## 1. 配置 Prometheus 抓取 JuiceFS 监控指标 {#add-scrape-config}

JuiceFS 挂载后,默认会通过 `http://localhost:9567/metrics` 地址实时输出 Prometheus 格式的指标数据。为了查看各项指标在一个时间范围内的状态变化,需要搭建 Prometheus 并配置定时抓取和保存这些指标数据。

![Prometheus-client-data](../images/prometheus-client-data.jpg)

这里以收集挂载点的监控指标为例,在 [`prometheus.yml`](https://prometheus.io/docs/prometheus/latest/configuration/configuration) 中添加抓取配置(`scrape_configs`),指向 JuiceFS 客户端的监控 API 地址:
不同挂载或访问方式(如 FUSE 挂载、CSI 驱动、S3 网关、Hadoop SDK 等)收集指标数据的方式略有区别,详见[「收集监控指标」](#collect-metrics)

这里以最常见的 FUSE 挂载方式为例介绍,如果还没安装 Prometheus,可以参考[官方文档](https://prometheus.io/docs/prometheus/latest/installation)

编辑 [`prometheus.yml`](https://prometheus.io/docs/prometheus/latest/configuration/configuration) 配置文件,在抓取配置部分(`scrape_configs`)添加新的任务,定义 JuiceFS 客户端输出监控指标的地址:

```yaml {20-22}
global:
Expand Down Expand Up @@ -47,7 +63,11 @@ scrape_configs:

访问 `http://localhost:9090` 即可看到 Prometheus 的界面。

## 通过 Grafana 进行数据可视化 {#grafana}
## 2. 让 Grafana 读取 Prometheus 中的监控数据 {#grafana}

Prometheus 开始抓取 JuiceFS 的监控指标后,接下来要配置 Grafana 读取 Prometheus 中的数据。

如果还没安装 Grafana,可以参考[官方文档](https://grafana.com/docs/grafana/latest/installation)

在 Grafana 中新建 Prometheus 类型的数据源:

Expand All @@ -56,12 +76,9 @@ scrape_configs:

![Grafana-data-source](../images/grafana-data-source.jpg)

JuiceFS 提供一些 Grafana 的仪表盘模板,将模板导入以后就可以展示收集上来的监控指标。目前提供的仪表盘模板有:
## 3. 用 JuiceFS 官方的 Grafana 仪表盘模板展现监控指标 {#grafana-dashboard}

| 模板名称 | 说明 |
|-----------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------|
| [`grafana_template.json`](https://github.com/juicedata/juicefs/blob/main/docs/en/grafana_template.json) | 用于展示自挂载点、S3 网关(非 Kubernetes 部署)及 Hadoop Java SDK 收集的指标 |
| [`grafana_template_k8s.json`](https://github.com/juicedata/juicefs/blob/main/docs/en/grafana_template_k8s.json) | 用于展示自 Kubernetes CSI 驱动、S3 网关(Kubernetes 部署)收集的指标 |
在 Grafana Dashboard 仓库中可以找到 JuiceFS 官方维护的仪表盘模板,可以直接在 Grafana 中通过 `https://grafana.com/grafana/dashboards/20794/` 链接导入,也可以通过 ID `20794` 导入。

Grafana 仪表盘如下图:

Expand All @@ -71,7 +88,7 @@ Grafana 仪表盘如下图:

根据部署 JuiceFS 方式的不同可以有不同的收集监控指标的方法,下面分别介绍。

### 宿主机挂载点 {#mount-point}
### FUSE 挂载 {#mount-point}

当通过 [`juicefs mount`](../reference/command_reference.md#mount) 命令挂载 JuiceFS 文件系统后,可以通过 `http://localhost:9567/metrics` 这个地址收集监控指标,你也可以通过 `--metrics` 选项自定义。如:

Expand Down
2 changes: 1 addition & 1 deletion docs/zh_cn/deployment/s3_gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ JuiceFS 会将文件[分块存储到底层的对象存储中](../introduction/ar

![JuiceFS S3 Gateway architecture](../images/juicefs-s3-gateway-arch.png)

JuiceFS S3 网关是通过 [MinIO S3 网关](https://github.com/minio/minio/tree/ea1803417f80a743fc6c7bb261d864c38628cf8d/docs/gateway)实现的功能,我们通过实现起来其 [object 接口](https://github.com/minio/minio/blob/d46386246fb6db5f823df54d932b6f7274d46059/cmd/object-api-interface.go#L88) 并且将 JuiceFS 文件系统作为其 server 的后端存储,获得了近乎原生 minio 的体验,继承 minio 的很多高级功能。这种架构对于 minio 来说,JuiceFS 是其运行 server 命令的一块本地盘,整体的原理类似于 `minio server /data1`
JuiceFS S3 网关是通过 [MinIO S3 网关](https://github.com/minio/minio/tree/ea1803417f80a743fc6c7bb261d864c38628cf8d/docs/gateway)实现的功能,我们通过实现起来其 [object 接口](https://github.com/minio/minio/blob/d46386246fb6db5f823df54d932b6f7274d46059/cmd/object-api-interface.go#L88) 并且将 JuiceFS 文件系统作为其 server 的后端存储,获得了近乎原生 MinIO 的体验,继承 MinIO 的很多高级功能。这种架构对于 MinIO 来说,JuiceFS 是其运行 server 命令的一块本地盘,整体的原理类似于 `minio server /data1`

JuiceFS Gateway 的常见的使用场景有:

Expand Down
2 changes: 1 addition & 1 deletion docs/zh_cn/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ uid=1201(alice) gid=500(staff) groups=500(staff)

### JuiceFS S3 网关支持多用户管理等高级功能吗?

JuiceFS 内置的 `gateway` 子命令不支持多用户管理等功能,只提供基本的 S3 网关功能。如果需要使用这些高级功能,请参考[文档](deployment/s3_gateway.md#使用功能更完整的-s3-网关)
JuiceFS 内置的 `gateway` 子命令不支持多用户管理等功能,只提供基本的 S3 网关功能。如果需要使用这些高级功能,请参考[文档](deployment/s3_gateway.md)

### JuiceFS 目前有 SDK 可以使用吗?

Expand Down
Loading

0 comments on commit 2e1c40e

Please sign in to comment.