---
eip: 2159
label: EIP-2159
title: Common Prometheus Metrics Names for Clients
status: Final
type: Standards Track
category: Interface
created: 2019-07-01
official: https://eips.ethereum.org/EIPS/eip-2159
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2159.md
canonical: https://eips.huatuo.xyz/zh/eip-2159/
lang: zh
tldr: 为链高度、同步目标和对等节点定义标准的 Prometheus 指标名称，让运维人员用一个仪表盘和一套告警监控不同的以太坊客户端。
tags: [monitoring, prometheus, metrics, clients, operations]
---

# EIP-2159: Common Prometheus Metrics Names for Clients

> Standardized names of common metrics for Ethereum clients to use with Prometheus, a widely used monitoring and alerting solution.

**TL;DR:** 为链高度、同步目标和对等节点定义标准的 Prometheus 指标名称，让运维人员用一个仪表盘和一套告警监控不同的以太坊客户端。

## 它解决什么问题？

大多数以太坊客户端都以 Prometheus 格式导出指标，运维人员可以据此绘制性能图表，并在出问题时告警。但每个客户端给指标起的名字都不一样。如果你混用多种客户端（这对韧性有好处），就需要为每个客户端分别配置仪表盘和告警规则。

EIP-2159 为每个客户端都能上报的几个指标选定了标准名称。有了它们，一个仪表盘和一套告警配置就能适用于异构的节点集合。

## 它如何运作

该 EIP 定义了四个 gauge。客户端可以导出更多指标，但非标准指标**不应**使用 `ethereum_` 前缀。

| 指标 | 含义 | 对应的 JSON-RPC |
| --- | --- | --- |
| `ethereum_blockchain_height` | 规范链的当前高度 | `eth_blockNumber` |
| `ethereum_best_known_block_number` | 估计可用的最高区块 | `eth_syncing` 的 `highestBlock`，未在同步时为 `eth_blockNumber` |
| `ethereum_peer_count` | 当前已连接的对等节点数 | `net_peerCount` |
| `ethereum_peer_limit` | 允许的最大对等节点数 | 无 |

`ethereum_best_known_block_number` 始终有值：节点未在同步时，它等于当前链高度。这样"我落后了多少？"就变成一次简单的减法。

规范有意不规定*如何*暴露指标（端口、路径、参数），因为各客户端本来就不同，把这些标准化收益不大。

## 示例代码

仅基于标准名称的 Prometheus 抓取配置和三条告警规则：

```yaml
# prometheus.yml
scrape_configs:
  - job_name: ethereum
    static_configs:
      - targets: ["node-a:METRICS_PORT", "node-b:METRICS_PORT"]  # each client's metrics port
```

```yaml
# alerts.yml
groups:
  - name: ethereum
    rules:
      - alert: NodeFallingBehind
        expr: ethereum_best_known_block_number - ethereum_blockchain_height > 10
        for: 5m
      - alert: ChainStalled
        expr: increase(ethereum_blockchain_height[5m]) == 0
        for: 5m
      - alert: LowPeers
        expr: ethereum_peer_count < 5
        for: 10m
```

对等节点使用率的仪表盘面板：

```promql
ethereum_peer_count / ethereum_peer_limit
```

## 需要注意

- **状态：Final。** 它是 Interface 标准，不影响共识。
- 示例告警中的阈值仅作说明。请根据你的网络和出块时间调整。
- 已经用旧名称导出这些值的客户端，切换时可能破坏现有仪表盘。规范建议在过渡期同时暴露两种名称。
- 指标端口和启用参数因客户端而异，本文不涉及。请查阅各客户端的文档。
- 共识层（信标链）客户端遵循另一份更详细的指标规范。


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-2159
