JuiceFS 怎么把 Prometheus 监控指标接入 Grafana 看板
【免费下载链接】juicefsJuiceFS is a distributed POSIX file system built on top of Redis and S3.项目地址: https://gitcode.com/GitHub_Trending/ju/juicefs
JuiceFS 客户端在运行时会输出 Prometheus 格式的监控指标,但这些指标默认只暴露在客户端本机的一个地址上,无法直接按时间观察。要把 JuiceFS 的容量、读写吞吐、缓存命中、元数据延迟等指标接进 Grafana,需要完成三步:配置 Prometheus 周期抓取客户端指标、在 Grafana 中配置 Prometheus 数据源、导入官方 JuiceFS 看板模板。本文以juicefs mount挂载的 FUSE 客户端为主路径,从指标地址确认一直讲到看板呈现,最后覆盖 S3 Gateway、Hadoop Java SDK、Consul 注册等其他接入方式。
前提条件:JuiceFS 客户端已挂载成功,且已按官方文档安装开源版 Prometheus 与 Grafana(项目文档以开源版本为例)。
确认客户端暴露的指标地址
通过juicefs mount挂载后,JuiceFS 会自动在http://localhost:9567/metrics暴露 Prometheus 格式的监控指标(以下示例假设客户端与 Prometheus 同机)。先用命令行确认指标可访问:
curl http://localhost:9567/metrics返回 Prometheus 格式的指标文本即表示地址可用(项目文档附带的 prometheus-client-data.jpg 截图是文档示例输出,各客户端的实际指标项会有差异)。
如果默认地址不合适,挂载时用--metrics选项自定义,例如:
juicefs mount --metrics localhost:9567 ...另外两个查看方式,供不用 Prometheus 时快速核对指标:
- 文件系统根目录下的隐藏文件
.stats,直接cat即可(假设挂载点为/jfs):
cat /jfs/.stats- 需要实时刷新输出时用
juicefs stats命令,它以类似dstat的格式持续打印 CPU/内存、FUSE 读写带宽、元数据操作与本地缓存等性能数据。
配置 Prometheus 抓取 JuiceFS 指标
编辑prometheus.yml,在scrape_configs下新增 JuiceFS 的抓取任务。项目文档给出的完整配置示例如下,其中新增部分是job_name: "juicefs"这一段:
global: scrape_interval: 15s evaluation_interval: 15s alerting: alertmanagers: - static_configs: - targets: # - alertmanager:9093 rule_files: # - "rules.yml" scrape_configs: - job_name: "prometheus" static_configs: - targets: ["localhost:9090"] - job_name: "juicefs" static_configs: - targets: ["localhost:9567"]targets指向客户端暴露指标的地址,文档示例为同机的localhost:9567;客户端在其他机器上时,把它改成对应机器的地址即可,端口与挂载命令中--metrics选项的取值保持一致(文档中该选项默认值为127.0.0.1:9567)。
启动 Prometheus 服务:
./prometheus --config.file=prometheus.yml启动后访问http://localhost:9090,能看到 Prometheus 界面即表示抓取服务已就绪,这一步也是项目文档给出的检查方式。
在 Grafana 中配置 Prometheus 数据源
在 Grafana 中新建一个类型为 Prometheus 的数据源:
- Name:便于识别的名字,例如文件系统名称;
- URL:Prometheus 的数据 API 地址,通常为
http://localhost:9090。
导入官方 JuiceFS 看板模板
JuiceFS 提供官方 Grafana 看板模板,在 Grafana 的导入流程中使用看板 ID20794(项目文档同时给出了 Grafana 官方看板库中对应条目的页面地址)导入即可,数据源指向上一节创建的 Prometheus 数据源。导入完成后,看板呈现官方模板的完整面板,效果以上文开头的文档示例图为准。
其他客户端类型的接入方式
以下分支仅在你的客户端不是 FUSE 挂载时参考,主路径步骤不变,只是指标采集端点不同。
S3 Gateway
需要 JuiceFS 客户端版本 0.17.1 及以上。Gateway 默认同样在http://localhost:9567/metrics提供监控指标,可用-metrics选项自定义,例如:
juicefs gateway --metrics localhost:9567 ...在 Kubernetes 中部署 Gateway 时,文档给出了基于 Pod Service Discovery 的抓取配置(保留app.kubernetes.io/name=juicefs-s3-gateway的 Pod,并把端口替换为 9567):
scrape_configs: - job_name: 'juicefs-s3-gateway' kubernetes_sd_configs: - role: pod relabel_configs: - source_labels: [__meta_kubernetes_pod_label_app_kubernetes_io_name] action: keep regex: juicefs-s3-gateway - source_labels: [__address__] action: replace regex: ([^:]+)(:\d+)? replacement: $1:9567 target_label: __address__ - source_labels: [__meta_kubernetes_pod_node_name] target_label: node action: replaceHadoop Java SDK
Hadoop Java SDK 不对外暴露 HTTP 指标端点,而是支持把指标推送到 Pushgateway、Graphite 或 Prometheus remote write 端点,对应配置项分别为juicefs.push-gateway、juicefs.push-graphite、juicefs.push-remote-write,推送频率用juicefs.push-interval调整(默认每 10 秒一次):
<property> <name>juicefs.push-gateway</name> <value>host:port</value> </property>使用 Pushgateway 时项目文档有三点提示:Prometheus 的 scrape 配置需设置honor_labels: true;Pushgateway 默认只在内存保存指标,可配合--persistence.file与--persistence.interval落盘(默认每 5 分钟保存一次);各进程指标会持续累积,建议定期清理。清理命令会清除 Pushgateway 上的全部监控指标(不影响正在运行的 SDK 继续上报),且 Pushgateway 启动时必须带--web.enable-admin-api:
curl -X PUT http://host:9091/api/v1/admin/wipe使用 Consul 作为注册中心
客户端版本 1.0.0 及以上支持用 Consul 注册 metrics API 地址,默认 Consul 地址为127.0.0.1:8500,可用--consul选项自定义,例如:
juicefs mount --consul 1.2.3.4:8500 ...配置了 Consul 地址后无需再配--metrics,JuiceFS 会按自身网络与端口条件自动确定 metrics 地址;若同时设置了--metrics,会优先尝试监听该地址。每个注册到 Consul 的服务,服务名固定为juicefs,服务 ID 格式为<IP>:<mount-point>(S3 Gateway 的mountpoint值恒为s3gateway),meta 中带hostname与mountpoint两个键。之后在prometheus.yml中新增consul_sd_config配置,并把services填为juicefs即可完成发现。
常用指标与标签速查
看板各面板对应的指标名可在 JuiceFS Metrics 中查到。所有指标带有三个全局标签:
| 标签 | 含义 |
|---|---|
vol_name | 卷名 |
instance | 客户端主机,格式<host>:<port> |
mp | 挂载点路径;经 Pushgateway 上报时(如 Hadoop Java SDK)为sdk-<PID> |
几个高频指标:juicefs_used_space(已用空间,byte)、juicefs_used_inodes(inode 数)、juicefs_cpu_usage(累积 CPU 用量,second)、juicefs_blockcache_hits/juicefs_blockcache_miss(本地缓存命中/未命中次数)、juicefs_object_request_errors(对象存储失败请求数)。多客户端接入同一 Prometheus 时,靠instance与mp标签区分不同挂载点。
边界与限制
- 本文主路径对应
juicefs mount的 FUSE 客户端;Kubernetes CSI Driver 场景的指标采集方式不同,项目文档将其指向 CSI Driver 的专门文档,本文不展开。 - 版本要求:S3 Gateway 的监控指标需要客户端 0.17.1 及以上,Consul 注册需要 1.0.0 及以上。
- 指标端点默认绑定本机(
127.0.0.1:9567),跨机器抓取时必须先用--metrics明确监听地址,再在 Prometheus 的targets中指向它;完整配置项说明见监控与数据可视化文档。
【免费下载链接】juicefsJuiceFS is a distributed POSIX file system built on top of Redis and S3.项目地址: https://gitcode.com/GitHub_Trending/ju/juicefs
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考