指标上报器
Fluss 允许将指标上报给外部系统。 通过在 conf/server.yaml 中配置一个或多个上报器,即可将指标暴露给外部系统。这些上报器会在每个 CoordinatorServer 和 TabletServer 启动时实例化。
指定多个上报器的示例配置:
metrics.reporters: jmx,prometheus推(Push)与拉(Pull)
指标的暴露方式分为推送(push)和拉取(pull)两种。
基于推送(push)的上报器通常实现 Scheduled 接口,定期将当前指标的汇总信息发送给外部系统。
基于拉取(pull)的上报器则由外部系统主动查询。
指标过滤
每个上报器支持两种过滤器:
metrics.reporter.<name>.filter.includes:需要暴露的指标(默认值:*:*:*)。metrics.reporter.<name>.filter.excludes:需要忽略的指标(默认值:空)。excludes 优先级更高。
规则使用 <scope>[:<name>[:<type>]] 形式,多条规则之间用 ; 分隔,名称/类型之间用 , 分隔。 使用 . 分隔的逻辑作用域(不带 fluss_ 前缀或标签值)以及原始指标名称。 模式支持 * 通配符和正则表达式。类型包括 counter、gauge、meter 或 histogram;省略名称/类型则匹配所有。
例如,排除 PushGateway 中的 bucket 指标(含子分组)和直方图:
metrics.reporter.prometheus-push.filter.includes: *:*:*
metrics.reporter.prometheus-push.filter.excludes: *.bucket;*.bucket.*;*:*:histogram重启 Fluss 进程以使变更生效。
直方图
内置直方图基于最近五分钟内记录的样本(每个直方图最多固定数量)计算统计信息。直方图的 count 是自注册以来的累计值。当最近五分钟内没有记录任何样本时,该窗口为空:
- Prometheus 导出
_count,并为每个分位数上报NaN。 - InfluxDB 写入
count和windowCount: 0,但不包含分布字段。查询分布字段时请过滤windowCount > 0。 - JMX 暴露
WindowCount。仅当WindowCount > 0时才解读其他属性;空窗口下Min和Max为0,其余统计量为NaN。
在 Flink 作业中注册的客户端直方图通过 Flink 的指标上报器上报,不适用上述规则:空窗口时它们上报 NaN 分位数和均值,最小值与最大值为 0。
上报器
以下小节列出了当前支持的上报器。
JMX
类型:拉取(pull)
参数:
port- (可选)JMX 监听连接的端口。 为了能够在一台主机上运行多个上报器实例(例如当某个 TabletServer 与 CoordinatorServer 部署在同一节点时),建议使用类似9250-9260的端口范围。 当指定了范围时,实际使用的端口会显示在相应的服务器日志中。 如果设置了该项,Fluss 会为给定的端口/端口范围启动一个额外的 JMX 连接器。 指标始终在默认的本地 JMX 接口上可用。
示例配置:
metrics.reporters: jmx
metrics.reporter.jmx.port: 9250-9260通过 JMX 暴露的指标由 domain 和一组 key-properties 共同标识,二者一起构成对象名称(object name)。
domain 始终以 org.apache.fluss 开头,后接一个泛化的指标标识符。 这样一个 domain 的示例为 org.apache.fluss.tabletserver.replicaCount。
key-property 列表包含与给定指标关联的所有变量的值。 这样一个列表的示例为 cluster_id=fluss1,host=localhost,server_id=1。
因此,domain 标识了一个指标类,而 key-property 列表标识该类中的一个(或多个)实例。
Prometheus
类型:拉取(pull)
参数:
metrics.reporter.prometheus.port- (可选)Prometheus exporter 监听的端口,默认值为 9249。为了能够在一台主机上运行多个上报器实例(例如当某个 TabletServer 与 CoordinatorServer 部署在同一节点时),建议使用类似9250-9260的端口范围。
示例配置:
metrics.reporters: prometheus
metrics.reporter.prometheus.port: 9250Fluss 指标类型到 Prometheus 指标类型的映射如下:
| Fluss | Prometheus | 说明 |
|---|---|---|
| Counter | Gauge | Prometheus 的 counter 不能递减。 |
| Gauge | Gauge | 仅支持数字和布尔值。 |
| Histogram | Summary | 分位数 .5、.75、.95、.98、.99 和 .999 |
| Meter | Gauge | 该 Gauge 暴露 meter 的速率。 |
PrometheusPushGateway
类型:推送(push)
参数:
metrics.reporter.prometheus-push.host-url- PushGateway 服务器的主机 URL,包含 scheme、主机名和端口。metrics.reporter.prometheus-push.job-name- 指标推送时所属的 job 名称。metrics.reporter.prometheus-push.push-interval- (可选)向 Prometheus PushGateway 推送指标的间隔,默认 10 SECONDS。metrics.reporter.prometheus-push.random-job-name-suffix- (可选)指定是否在 job 名称后附加随机后缀,默认 true。当同一主机上运行多个上报器实例时该选项很有用。metrics.reporter.prometheus-push.delete-on-shutdown- (可选)指定在关闭时是否从 PushGateway 删除指标,默认 true。Fluss 会尽力删除指标但不做保证。metrics.reporter.prometheus-push.grouping-key- 指定分组键,即所有指标的分组和全局标签。标签名与值用=分隔,标签之间用;分隔,例如k1=v1;k2=v2。metrics.reporter.prometheus-push.username- (可选)Prometheus PushGateway Basic Auth 的用户名。留空以禁用认证。metrics.reporter.prometheus-push.password- (可选)Prometheus PushGateway Basic Auth 的密码。仅在配置了username时生效。
示例配置:
metrics.reporters: prometheus-push
metrics.reporter.prometheus-push.host-url: http://localhost:9091
metrics.reporter.prometheus-push.job-name: fluss-tablet-server
metrics.reporter.prometheus-push.push-interval: 10 SECONDS
metrics.reporter.prometheus-push.random-job-name-suffix: true
metrics.reporter.prometheus-push.delete-on-shutdown: true
metrics.reporter.prometheus-push.grouping-key: instance=instance01;cluster=clusterA
metrics.reporter.prometheus-push.username: myuser
metrics.reporter.prometheus-push.password: mypasswordInfluxDB
类型:推送(push)
InfluxDB 上报器同时支持 InfluxDB v2 和 InfluxDB v3,默认版本为 v3。
参数:
metrics.reporter.influxdb.version- (可选)要连接的 InfluxDB 版本,默认v3。支持的值为v2和v3。metrics.reporter.influxdb.host-url- InfluxDB 服务器的主机 URL,包含 scheme、主机名和端口。metrics.reporter.influxdb.bucket- InfluxDB 的 bucket/数据库名称。metrics.reporter.influxdb.org- InfluxDB 的组织名称。InfluxDB v2 必需,InfluxDB v3 不需要。metrics.reporter.influxdb.token- InfluxDB 认证 token。metrics.reporter.influxdb.push-interval- (可选)向 InfluxDB 上报指标的间隔,默认 10 SECONDS。
InfluxDB v3(默认)的示例配置:
metrics.reporters: influxdb
metrics.reporter.influxdb.host-url: http://localhost:8181
metrics.reporter.influxdb.bucket: fluss_metrics
metrics.reporter.influxdb.token: your-influxdb-token
metrics.reporter.influxdb.push-interval: 10 SECONDSInfluxDB v2 的示例配置:
metrics.reporters: influxdb
metrics.reporter.influxdb.version: v2
metrics.reporter.influxdb.host-url: http://localhost:8086
metrics.reporter.influxdb.bucket: fluss_metrics
metrics.reporter.influxdb.org: fluss_org
metrics.reporter.influxdb.token: your-influxdb-token
metrics.reporter.influxdb.push-interval: 10 SECONDS