Skip to main content

Overview

The metrics API provides comprehensive performance data for a specific blockchain chain, including provider statistics, RPC method performance, and system resource usage.

Endpoint

GET /api/metrics/:chain

Path Parameters

chain
string
required
The chain identifier (e.g., ethereum, polygon, arbitrum)

Response

chain
string
required
The chain identifier
chain_id
integer
required
The numeric chain ID (e.g., 1 for Ethereum)
timestamp
integer
required
Unix timestamp in milliseconds when metrics were collected
system_metrics
object
required
VM and system resource utilization
chain_performance
object
required
Aggregated performance metrics for the chain
providers
array
required
Performance metrics for each provider
rpc_methods
array
required
List of RPC methods that have been called on this chain
rpc_performance_by_provider
array
Detailed RPC method performance organized by provider
rpc_performance_by_method
array
Detailed RPC method performance organized by method
last_updated
integer
required
Timestamp when metrics were last updated

Response Example

{
  "chain": "ethereum",
  "chain_id": 1,
  "timestamp": 1709502330123,
  "system_metrics": {
    "memory_mb": 245.6,
    "cpu_percent": 12.4,
    "process_count": 542,
    "run_queue": 0
  },
  "chain_performance": {
    "total_calls": 15234,
    "success_rate": 99.2,
    "p50_latency": 125.5,
    "p95_latency": 342.1,
    "failovers_last_minute": 2,
    "connected_providers": 3,
    "total_providers": 3,
    "recent_activity": 45,
    "rpc_calls_per_second": 12.5,
    "error_rate_percent": 0.8
  },
  "providers": [
    {
      "id": "alchemy-eth-mainnet",
      "name": "Alchemy",
      "score": 95.6,
      "success_rate": 99.8,
      "total_calls": 8432,
      "avg_latency_ms": 115.3,
      "calls_last_minute": 28
    },
    {
      "id": "infura-eth-mainnet",
      "name": "Infura",
      "score": 92.1,
      "success_rate": 99.1,
      "total_calls": 4521,
      "avg_latency_ms": 145.8,
      "calls_last_minute": 12
    },
    {
      "id": "quicknode-eth-mainnet",
      "name": "QuickNode",
      "score": 94.3,
      "success_rate": 99.5,
      "total_calls": 2281,
      "avg_latency_ms": 128.2,
      "calls_last_minute": 5
    }
  ],
  "rpc_methods": [
    "eth_blockNumber",
    "eth_getBlockByNumber",
    "eth_call",
    "eth_getLogs"
  ],
  "rpc_performance_by_provider": [
    {
      "provider_id": "alchemy-eth-mainnet",
      "provider_name": "Alchemy",
      "methods": [
        {
          "method": "eth_blockNumber",
          "avg_latency_ms": 45.2,
          "p50_latency_ms": 42.0,
          "p90_latency_ms": 68.5,
          "p95_latency_ms": 85.3,
          "p99_latency_ms": 124.7,
          "success_rate": 0.998,
          "total_calls": 3421,
          "last_updated": 1709502330100
        }
      ]
    }
  ],
  "rpc_performance_by_method": [
    {
      "method": "eth_blockNumber",
      "providers": [
        {
          "provider_id": "alchemy-eth-mainnet",
          "provider_name": "Alchemy",
          "avg_latency_ms": 45.2,
          "p50_latency_ms": 42.0,
          "p90_latency_ms": 68.5,
          "p95_latency_ms": 85.3,
          "p99_latency_ms": 124.7,
          "success_rate": 0.998,
          "total_calls": 3421,
          "last_updated": 1709502330100
        }
      ]
    }
  ],
  "last_updated": 1709502330100
}

Error Responses

Chain Not Found

{
  "error": "Chain not found",
  "chain": "invalid-chain",
  "available_chains": ["ethereum", "polygon", "arbitrum"]
}
HTTP Status: 404 Not Found

Missing Chain Parameter

{
  "error": "Chain parameter required",
  "usage": "/api/metrics/{chain_name}",
  "available_chains": ["ethereum", "polygon", "arbitrum"]
}
HTTP Status: 400 Bad Request

Use Cases

Monitor Chain Performance

Track overall performance metrics for a blockchain:
curl http://localhost:4000/api/metrics/ethereum

Provider Performance Comparison

Compare performance across different RPC providers:
# Get provider rankings
curl -s http://localhost:4000/api/metrics/ethereum | \
  jq '.providers | sort_by(-.score) | .[] | {name, score, success_rate, avg_latency_ms}'

RPC Method Analysis

Analyze performance of specific RPC methods:
# Check eth_getLogs performance across providers
curl -s http://localhost:4000/api/metrics/ethereum | \
  jq '.rpc_performance_by_method[] | select(.method=="eth_getLogs")'

System Resource Monitoring

Monitor system resource usage:
# Alert if memory usage is high
memory_mb=$(curl -s http://localhost:4000/api/metrics/ethereum | jq '.system_metrics.memory_mb')

if (( $(echo "$memory_mb > 1000" | bc -l) )); then
  echo "Warning: High memory usage: ${memory_mb}MB"
fi

Performance Dashboards

Integrate with monitoring tools like Grafana, Datadog, or Prometheus:
// Fetch metrics periodically
setInterval(async () => {
  const response = await fetch('http://localhost:4000/api/metrics/ethereum');
  const metrics = await response.json();
  
  // Send to monitoring backend
  await sendToDatadog({
    'lasso.chain.success_rate': metrics.chain_performance.success_rate,
    'lasso.chain.p95_latency': metrics.chain_performance.p95_latency,
    'lasso.chain.rps': metrics.chain_performance.rpc_calls_per_second,
    'lasso.system.memory_mb': metrics.system_metrics.memory_mb,
    'lasso.system.cpu_percent': metrics.system_metrics.cpu_percent
  });
}, 30000); // Every 30 seconds

Notes

  • Metrics are updated in real-time based on actual RPC traffic
  • Performance percentiles (p50, p95, etc.) are calculated over a sliding window
  • Provider scores are calculated based on a combination of latency, success rate, and reliability
  • The rpc_performance_by_provider and rpc_performance_by_method fields provide the same data organized differently for convenience
  • System metrics reflect the Erlang VM’s resource usage, not the underlying host system