> ## Documentation Index
> Fetch the complete documentation index at: https://docs.orbitflare.com/llms.txt
> Use this file to discover all available pages before exploring further.

# getHealth

> 返回节点的当前健康状态

## 参数

此方法不接受任何参数。

## 响应

<ResponseField name="result" type="string">
  以下状态值之一：

  * `"ok"`：节点健康且已同步到最新
  * `"behind"`：节点落后若干 slot
  * `"unknown"`：无法确定节点健康状态
</ResponseField>

## 代码示例

### 基本请求

```bash theme={null}
curl https://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY -X POST -H "Content-Type: application/json" -d '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getHealth"
}'
```

### 替代 HTTP GET 请求

```bash theme={null}
curl https://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY/health
```

### 使用 web3.js

```typescript theme={null}
import { Connection } from '@solana/web3.js';

const connection = new Connection('https://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY');

const health = await connection.getHealth();
console.log('Node health:', health);

// Example: Check if node is healthy
const isHealthy = health === 'ok';
if (!isHealthy) {
  console.warn('Node is not healthy:', health);
}
```

## 注意事项

1. 此方法通常用于负载均衡器健康检查
2. HTTP GET 端点 `/health` 提供相同的信息
3. 如果节点落后于最新集群 slot 超过 `HEALTH_CHECK_SLOT_DISTANCE` 个 slot，则被视为 "behind"
4. "unknown" 状态通常表示节点正在启动或遇到问题

## 最佳实践

1. 使用此端点进行基本健康监控
2. 基于健康状态实现熔断器
3. 考虑使用更详细的方法获取特定健康指标：
   * `getVersion` 获取软件版本
   * `getSlot` 获取 slot 进度
   * `getBlockHeight` 获取区块高度
4. 为健康检查设置适当的超时
5. 处理所有可能的响应值

## 常见错误

| 错误码    | 消息                  | 解决方案                  |
| ------ | ------------------- | --------------------- |
| -32601 | Method not found    | 验证是否连接到 Solana RPC 节点 |
| -32603 | Internal error      | 节点可能遇到问题              |
| 503    | Service Unavailable | 节点尚未准备好处理请求           |

## 用例

1. **负载均衡器配置**
   ```nginx theme={null}
   location /health {
     proxy_pass http://backend;
     proxy_next_upstream error timeout http_503;
   }
   ```

2. **健康监控**
   ```typescript theme={null}
   async function monitorHealth(endpoint: string) {
     const connection = new Connection(endpoint);
     try {
       const health = await connection.getHealth();
       if (health !== 'ok') {
         alertNodeUnhealthy(endpoint, health);
       }
     } catch (error) {
       alertNodeError(endpoint, error);
     }
   }
   ```

3. **客户端负载均衡**
   ```typescript theme={null}
   async function getHealthyEndpoint(endpoints: string[]) {
     for (const endpoint of endpoints) {
       const connection = new Connection(endpoint);
       try {
         const health = await connection.getHealth();
         if (health === 'ok') {
           return endpoint;
         }
       } catch (error) {
         continue;
       }
     }
     throw new Error('No healthy endpoints available');
   }
   ```

4. **系统状态仪表板**
   ```typescript theme={null}
   interface NodeStatus {
     endpoint: string;
     health: string;
     lastChecked: Date;
   }

   async function updateDashboard(nodes: NodeStatus[]) {
     for (const node of nodes) {
       const connection = new Connection(node.endpoint);
       try {
         node.health = await connection.getHealth();
       } catch (error) {
         node.health = 'error';
       }
       node.lastChecked = new Date();
     }
     renderDashboard(nodes);
   }
   ```
