Hadoop Metrics and JMX: What to Watch on HDFS and YARN
Where Hadoop Publishes Metrics
| Source | How to read |
|---|---|
| Web UI | NameNode :9870, ResourceManager :8088 (human friendly) |
| JMX JSON | http://host:9870/jmx on every daemon (machine friendly) |
| REST APIs | ResourceManager /ws/v1/cluster/..., WebHDFS, NodeManager /ws/v1/node |
| metrics2 sinks | File, Ganglia, Graphite, Prometheus-style sinks (config file) |
| Logs and audit logs | Event history and who did what |
Query JMX with curl
bash
# list all beans
curl -s http://nn1:9870/jmx | jq '.beans[].name' | head -40
# NameNode summary: capacity, files, blocks
curl -s 'http://nn1:9870/jmx?qry=Hadoop:service=NameNode,name=FSNamesystem' | jq '.beans[0] |
{CapacityTotalGB, CapacityUsedGB, CapacityRemainingGB, FilesTotal, BlocksTotal, MissingBlocks, UnderReplicatedBlocks, CorruptBlocks, PendingReplicationBlocks}'
# HA state and safe mode
curl -s 'http://nn1:9870/jmx?qry=Hadoop:service=NameNode,name=NameNodeStatus' | jq '.beans[0].State'
curl -s 'http://nn1:9870/jmx?qry=Hadoop:service=NameNode,name=NameNodeInfo' | jq '.beans[0] | {Safemode, LiveNodes, DeadNodes, NumberOfMissingBlocks}'
# in secure clusters add: --negotiate -u : --cacert ca.pem and use https://...:9871
The Metrics That Matter: HDFS
| Metric | Meaning | Alert idea |
|---|---|---|
MissingBlocks | Blocks with no replica | > 0 critical |
CorruptBlocks | All replicas corrupt | > 0 critical |
UnderReplicatedBlocks | Fewer replicas than needed | Rising for > 30 min |
CapacityRemaining / used percent | Free space | Used > 75% warn, 85% crit |
| Live / dead DataNodes | Node health | Any new dead node |
FilesTotal, BlocksTotal | Namespace growth | Trend vs heap size |
RpcQueueTimeAvgTime, CallQueueLength | NameNode RPC overload | Queue time > 10 ms avg, queue length growing |
| Heap used and GC pause time | Memory pressure | GC pause > 5 s |
LastCheckpointTime / TransactionsSinceLastCheckpoint | Checkpoint delay | No checkpoint for 2x period |
Safemode state | Read-only mode | ON outside startup |
The Metrics That Matter: YARN
bash
curl -s http://rm1:8088/ws/v1/cluster/metrics | jq '.clusterMetrics |
{appsPending, appsRunning, appsFailed, availableMB, allocatedMB, totalMB, availableVirtualCores, activeNodes, unhealthyNodes, lostNodes, decommissionedNodes}'
curl -s 'http://rm1:8088/ws/v1/cluster/apps?states=RUNNING&limit=5' | jq '.apps.app[] | {id, user, queue, elapsedTime, allocatedMB}'
curl -s http://rm1:8088/ws/v1/cluster/scheduler | jq '.scheduler.schedulerInfo.queues.queue[] | {queueName, usedCapacity, capacity}'
| Metric | Alert idea |
|---|---|
unhealthyNodes, lostNodes | > 0 for several minutes |
appsPending | Growing: cluster or queue is full |
| Memory allocated percent | > 90% for long periods means capacity shortage |
| Application failure rate | Spike after a change |
| RM HA state | Both standby, or flapping |
Daemon Health: JVM Metrics
- Heap and non-heap memory, GC count and time (
java.lang:type=GarbageCollector) - Thread count and open file descriptors
- Process uptime (a recent restart may mean a crash loop)
A Tiny Health Check Script
bash
#!/bin/bash
# hdfs-health.sh : exit 0 healthy, 1 warning, 2 critical (Nagios style)
NN=${1:-nn1.example.com}
J=$(curl -s --max-time 10 "http://$NN:9870/jmx?qry=Hadoop:service=NameNode,name=FSNamesystem")
[ -z "$J" ] && { echo "CRITICAL: cannot read JMX"; exit 2; }
MISSING=$(echo "$J" | jq '.beans[0].MissingBlocks')
UNDER=$(echo "$J" | jq '.beans[0].UnderReplicatedBlocks')
USED=$(echo "$J" | jq '.beans[0] | (.CapacityUsed / .CapacityTotal * 100) | floor')
[ "$MISSING" -gt 0 ] && { echo "CRITICAL: $MISSING missing blocks"; exit 2; }
[ "$USED" -ge 85 ] && { echo "CRITICAL: HDFS ${USED}% used"; exit 2; }
[ "$UNDER" -gt 1000 ] || [ "$USED" -ge 75 ] && { echo "WARNING: under-replicated=$UNDER used=${USED}%"; exit 1; }
echo "OK: used=${USED}% under=$UNDER"; exit 0
metrics2 Sinks
ini
# hadoop-metrics2.properties
*.sink.file.class=org.apache.hadoop.metrics2.sink.FileSink
namenode.sink.file.filename=/var/log/hadoop/namenode-metrics.out
*.period=60
Practical choice: For real monitoring use a time-series system (the next lesson uses Prometheus and Grafana). The JMX endpoint is perfect for quick checks, scripts and debugging.
Know your baseline: Alerts based on fixed numbers fail when workloads change. Record normal ranges for RPC latency, block count growth and daily capacity growth, then alert on changes.
Conclusion
Every Hadoop daemon exposes JMX at /jmx, and the ResourceManager has REST APIs. Watch missing, corrupt and under-replicated blocks, capacity, RPC queue time, heap and GC, unhealthy nodes and pending apps.
Quick Summary:
/jmx + RM REST; MissingBlocks > 0 = critical; capacity and RPC latency.

