Intro
HDFS monitoring and alerts with practical examples should help operators move from an observed problem to a verified result. This guide focuses on HDFS monitoring for developers, DevOps consultants, and technical startup teams. It connects HDFS alerts, HDFS metrics, HDFS dashboards, and HDFS incident response to commands, expected output, failure signals, and recovery decisions.
The goal is operational safety: observe before changing, limit the blast radius, use placeholders instead of secrets, verify the result, and document how to recover if the expected state is not reached.
This article assumes a working HDFS cluster. It covers version and environment inventory, safe configuration changes, verification and diagnostics, failure modes and recovery, and an operations checklist. Each section includes concrete commands, expected output, and guidance for common pitfalls.
Version and Environment Inventory
Before monitoring HDFS, identify the installed version and deployment topology. Use read-only commands to capture the current state. Do not change anything until you understand the cluster.
To find the HDFS version, run:
hdfs version
Expected output looks like:
Hadoop 3.3.6
Source code repository https://github.com/apache/hadoop.git -r 2f5c...
Compiled by ubuntu on 2023-06-18T15:10Z
Compiled with protoc 3.7.1
From source with checksum 5e8f...
This command was run using /opt/hadoop/share/hadoop/common/hadoop-common-3.3.6.jar
Record the version because metric names and command options change between major releases. For example, HDFS 2.x uses dfs.namenode.fs-limits.min-block-size while HDFS 3.x may use a different default. When checking documentation, filter by your exact version.
To see the topology, run:
hdfs dfsadmin -report
This reports live and dead DataNodes, their storage capacity, and block counts. Look for:
- Decommissioned nodes
- Nodes in maintenance mode
- Under-replicated blocks
- Missing blocks
Example snippet:
Live datanodes (3):
Name: 10.0.0.2:9866 (datanode1.example.com)
Hostname: datanode1.example.com
Decommission Status : Normal
Configured Capacity: 1099511627776 (1 TB)
DFS Used: 268435456000 (250 GB)
Non DFS Used: 85899345920 (80 GB)
DFS Remaining: 781684047872 (728 GB)
...
If any DataNode is dead, investigate before making configuration changes. Use hdfs dfsadmin -refreshNodes only after you have fixed the underlying issue.
Capture the current Namenode state:
hdfs haadmin -getAllServiceState
For a high-availability cluster, this returns active and standby nodes. For example:
namenode1: active
namenode2: standby
If no active Namenode is found, HDFS is unavailable for reads and writes. Do not change configuration; restore the active node first.
Prerequisites for Monitoring
- SSH access to HDFS nodes with a user that has read-only permissions for metrics endpoints and log files.
- Network access to the Namenode web UI (default port 9870 for HTTP, 9871 for HTTPS).
- A configured metrics sink (e.g., JMX, Ganglia, Graphite, Prometheus) if you need historical data.
- For alerting, an alerting platform or script runner (e.g., Nagios, Prometheus Alertmanager, custom cron jobs).
Common Pitfalls
- Running commands with elevated privileges can accidentally trigger a failover or block report. Always use a dedicated monitoring user with read-only permissions.
- Ignoring version-specific metrics. A metric available in 2.x may be renamed or removed in 3.x. Check the official documentation for your version.
- Relying on the web UI alone. The UI may be unresponsive when the cluster is overloaded, so have CLI and API fallbacks.
Monitoring HDFS Metrics
HDFS exposes metrics via JMX, HTTP endpoints, and log files. For real-time monitoring, use the Namenode and Datanode JMX endpoints. For example, to get Namenode metrics as JSON:
curl -s http://namenode1.example.com:9870/jmx | jq '.beans[] | select(.name=="Hadoop:service=NameNode,name=FSNamesystem")'
The relevant metrics include:
CapacityTotal,CapacityUsed,CapacityRemaining: storage capacity in bytes.TotalFiles,TotalBlocks: counts of files and blocks.UnderReplicatedBlocks,PendingReplicationBlocks,MissingBlocks: replication health.CorruptBlocks: number of corrupt blocks.VolumeFailuresTotal: number of failed volumes on all Datanodes.
Example conditional alert using these metrics:
MISSING_BLOCKS=$(curl -s http://namenode1.example.com:9870/jmx | jq '.beans[] | select(.name=="Hadoop:service=NameNode,name=FSNamesystem") | .MissingBlocks')
if [ "$MISSING_BLOCKS" -gt 0 ]; then
echo "ALERT: $MISSING_BLOCKS missing blocks detected at $(date)" | mail -s "HDFS Missing Blocks" [email protected]
fi
For Datanode metrics, query:
curl -s http://datanode1.example.com:9864/jmx | jq '.beans[] | select(.name=="Hadoop:service=DataNode,name=DataNodeActivity-hostname-9866")'
Key Datanode metrics:
BytesWritten,BytesRead: I/O rates.BlocksWritten,BlocksRead: block operation counts.Remaining: remaining capacity in bytes.NumFailedVolumes: number of failed disks.
Setting Up Prometheus Monitoring
If you use Prometheus, you can export HDFS metrics using the JMX exporter. Download the JMX exporter jar and create a configuration file, e.g., hdfs_jmx_exporter.yaml:
startDelaySeconds: 0
hostPort: namenode1.example.com:9870
ssl: false
rules:
- pattern: 'Hadoop:service=NameNode,name=FSNamesystem'
name: hdfs_namenode_fsnamesystem
labels:
cluster: "prod"
type: GAUGE
Then run the exporter as a Java agent:
java -javaagent:./jmx_prometheus_javaagent-0.17.0.jar=9090:hdfs_jmx_exporter.yaml -jar your-app.jar
Alternatively, run it as a standalone HTTP server using jmx_prometheus_httpserver. For Datanodes, repeat with the appropriate host and port.
Prometheus scrape config example:
scrape_configs:
- job_name: 'hdfs-namenode'
static_configs:
- targets: ['namenode1.example.com:9090']
- job_name: 'hdfs-datanode'
static_configs:
- targets: ['datanode1.example.com:9091', 'datanode2.example.com:9091', 'datanode3.example.com:9091']
Alerting Rules for Prometheus
Create alerting rules in Prometheus. For example, alert on missing blocks:
groups:
- name: hdfs_alerts
rules:
- alert: HDFSMissingBlocks
expr: hdfs_namenode_fsnamesystem_MissingBlocks{cluster="prod"} > 0
for: 5m
labels:
severity: critical
annotations:
summary: "HDFS missing blocks detected"
description: "Missing blocks in HDFS for cluster prod: {{ $value }}."
Similarly, alert on under-replicated blocks, corrupt blocks, or dead DataNodes.
Safe Configuration Changes
Sometimes you need to change HDFS configuration to improve monitoring or fix an issue. Follow a safe path: capture current state, make one scoped change, verify, and document recovery.
Example: Increase Logging for Namenode Audits
Suppose you need to audit HDFS operations for security monitoring. Increase the audit log level temporarily.
- Locate the
log4j.propertiesfile for the Namenode (often in$HADOOP_CONF_DIR). - Capture the current audit logger setting:
grep hdfs.audit.logger $HADOOP_CONF_DIR/log4j.properties
Expected output:
log4j.logger.org.apache.hadoop.hdfs.server.namenode.FSNamesystem.audit=WARN
- Change
WARNtoINFO:
sed -i 's/log4j.logger.org.apache.hadoop.hdfs.server.namenode.FSNamesystem.audit=WARN/log4j.logger.org.apache.hadoop.hdfs.server.namenode.FSNamesystem.audit=INFO/' $HADOOP_CONF_DIR/log4j.properties
- Restart the Namenode (or use
kill -1for a graceful reload if supported). - Verify the change:
grep hdfs.audit.logger $HADOOP_CONF_DIR/log4j.properties
Expected output shows INFO.
- Monitor the audit log for a test operation. If you see excessive log growth, revert to
WARNimmediately.
Blast radius: affects only the Namenode audit logs. It may increase disk usage for the logs; monitor log rotation.
Example: Enabling Metrics Sink to Graphite
If you need to send metrics to Graphite, add a sink to hadoop-metrics2.properties.
- Backup the current file:
cp $HADOOP_CONF_DIR/hadoop-metrics2.properties $HADOOP_CONF_DIR/hadoop-metrics2.properties.bak.$(date +%Y%m%d)
- Add the following configuration for the Namenode sink:
namenode.sink.graphite.class=org.apache.hadoop.metrics2.sink.GraphiteSink
namenode.sink.graphite.server_host=graphite.example.com
namenode.sink.graphite.server_port=2003
namenode.sink.graphite.metrics_prefix=hadoop.namenode
- Restart the Namenode (or the metrics system if it can be reloaded).
- Verify metrics appear in Graphite:
curl -s http://graphite.example.com/render?target=hadoop.namenode.*&format=json | jq '.[0].target'
Recovery: if metrics stop, revert to the backup file and restart the service.
Blast radius: affects only metrics export from the Namenode.
Verification and Diagnostics
After any change, verify that monitoring works and the cluster is healthy. Use read-only diagnostics.
Checking HDFS Health via Command Line
hdfs fsck / -files -blocks -locations
This reports the health of the filesystem, including under-replicated, over-replicated, mis-replicated, and corrupt blocks. Example output:
Status: HEALTHY
Total size: 536870912000 B (500 GB)
Total dirs: 1024
Total files: 2048
Total blocks (validated): 4096 (avg. block size 134217728 B)
Minimally replicated blocks: 4096 (100.0 %)
Over-replicated blocks: 0 (0.0 %)
Under-replicated blocks: 0 (0.0 %)
Mis-replicated blocks: 0 (0.0 %)
Default replication factor: 3
Average block replication: 3.0
Corrupt blocks: 0
Missing replicas: 0 (0.0 %)
Number of data-nodes: 3
Number of racks: 1
If Status is not HEALTHY, investigate before continuing.
Testing Alert Delivery
Test your alerting pipeline by triggering a test alert. For a custom script, run:
./send_test_alert.sh --severity warning --message "Test alert from HDFS monitoring" --channel ops
Check that the alert appears in your Slack/email/PagerDuty. If it does not, inspect the script and notification service configuration.
Validating Dashboard Queries
If you built a Grafana dashboard, run the underlying queries manually. For Prometheus, use:
curl -s 'http://prometheus.example.com:9090/api/v1/query?query=hdfs_namenode_fsnamesystem_CapacityRemaining' | jq '.data.result'
Ensure the value matches the web UI or hdfs dfsadmin -report.
Failure Modes and Recovery
HDFS can fail in many ways. Here are common failure modes, how to detect them, and recovery steps.
Namenode Failure
Symptoms:
- HDFS commands hang or return connection refused.
- The web UI is unreachable.
hdfs haadmin -getAllServiceStateshows no active Namenode.
Detection:
hdfs haadmin -getAllServiceState
If no active, check the Namenode process:
jps | grep NameNode
If absent, start it:
hdfs --daemon start namenode
For HA, if the standby is healthy, promote it:
hdfs haadmin -failover namenode1 namenode2
Then fix the original active node.
Recovery verification: run hdfs dfs -ls / to ensure the filesystem is accessible.
DataNode Failure
Symptoms:
- Under-replicated blocks increase.
hdfs dfsadmin -reportshows a dead node.- Missing blocks after prolonged failure.
Detection:
hdfs dfsadmin -report | grep -A5 "Dead datanodes"
If a DataNode is dead, check its logs ($HADOOP_LOG_DIR/hadoop-hdfs-datanode-*.log). Common causes: disk failure, network partition, or high memory pressure.
Recovery:
- If disk failed, replace the disk and restart the DataNode.
- If network partition, restore connectivity and run
hdfs dfsadmin -refreshNodesto re-read the topology. - If the node cannot be recovered, decommission it properly:
hdfs dfsadmin -refreshNodes
Ensure replication is resatisfied by checking hdfs fsck / -files -blocks -locations for under-replicated blocks.
High Disk Usage on DataNodes
Symptoms:
CapacityRemainingdrops below a threshold.- Writes fail with "Disk out of space".
Detection:
hdfs dfsadmin -report | grep -A10 "Live datanodes" | grep "DFS Remaining"
Set up an alert when remaining capacity is below 10%.
Recovery:
- Rebalance the cluster to redistribute data:
hdfs balancer -threshold 10
- Delete unnecessary files or move data to external storage.
- Add new DataNodes if needed.
Corrupt Blocks
Symptoms:
hdfs fsck /reportsCorrupt blocks: N.- Applications fail to read certain files.
Detection:
hdfs fsck / -list-corruptfileblocks
Recovery:
- If replication factor is high enough, HDFS may automatically replicate a good copy from another replica.
- If all replicas are corrupt, restore from backup or salvage manually if possible.
- Then delete the corrupt block files and let HDFS replicate from good copies.
Operations Checklist
Use this checklist to ensure your HDFS monitoring is effective and safe. Assign a single owner for each item and review frequency.
| Check | Command or Method | Expected Result | Owner | Review Frequency |
|---|---|---|---|---|
| Namenode process running | jps | grep NameNode | Process listed | Priya Shah, Engineering Lead | Every 15 min via automation |
| Active/Standby status | hdfs haadmin -getAllServiceState | One active, one standby | Priya Shah | Every 15 min via automation |
| DataNode count matches expected | hdfs dfsadmin -report | grep -c "Live datanodes" | Equals number of nodes in inventory | Raj Patel, DevOps Engineer | Every 15 min via automation |
| Under-replicated blocks | curl -s http://namenode1:9870/jmx | jq '.beans[] | select(.name=="Hadoop:service=NameNode,name=FSNamesystem") | .UnderReplicatedBlocks' | 0 | Sarah Chen, SRE | Hourly |
| Corrupt blocks | hdfs fsck / -list-corruptfileblocks | No output (no corrupt files) | Sarah Chen | Daily |
| Capacity remaining per DataNode | hdfs dfsadmin -report | grep "DFS Remaining" | >10% free on each node | Raj Patel | Hourly |
| Audit log file size growth | du -sh /var/log/hadoop-hdfs/hdfs-audit.log | Within expected rotation settings | Priya Shah | Daily |
| Alerting pipeline test | Trigger test alert via script | Alert received in all channels | On-call engineer | Weekly |
| Backup of HDFS metadata | Check backup process logs | Successful backup within last 24 hours | Backup Administrator | Daily |
Each owner is responsible for investigating and resolving issues related to their check. If a check fails, follow the escalation path defined in your incident response plan.
Common Pitfalls and How to Avoid Them
Here are frequent mistakes in HDFS monitoring with reasons and solutions.
1. Alert Fatigue
Why it happens: Too many alerts, thresholds too low, or non-actionable alerts.
How to avoid: Set meaningful thresholds based on historical data. For example, alert on under-replicated blocks only if the count remains > 0 for more than 10 minutes. Group similar alerts into a single notification. Regularly review and tune alerts.
2. Ignoring Disk Failure Trends
Why it happens: Disk failures occur gradually, but monitoring focuses on aggregate capacity rather than individual disk health.
How to avoid: Monitor per-disk metrics from DataNode JMX, such as NumFailedVolumes and disk SMART data. Set alerts for any failed volume, not just when capacity is low.
3. Not Testing Recovery Procedures
Why it happens: Teams assume recovery works until an incident occurs.
How to avoid: Regularly conduct fire drills. Simulate a DataNode failure by stopping the service and verifying that replication and alerts work. Document the recovery time (RTO) and aim to reduce it.
4. Using Default JMX Ports Without Authentication
Why it happens: Default configurations expose metrics and JMX endpoints without authentication, which can leak sensitive information.
How to avoid: Enable Kerberos authentication for JMX or restrict access via network policies. Use a metrics proxy that requires authentication.
5. Changing Configuration Without Version Control
Why it happens: Quick fixes are applied directly, leading to configuration drift.
How to avoid: Store all HDFS configuration files in version control (e.g., Git). Use configuration management tools (Ansible, Puppet, Chef). These changes can be reviewed, rolled back, and audited.
6. Overlooking Namenode Heap Usage
Why it happens: Namenode memory pressure can cause slow performance or crashes, but teams focus on disk and CPU.
How to avoid: Monitor Namenode heap usage via JMX (java.lang:type=Memory). Set alerts when heap usage exceeds 80% for a sustained period. Consider tuning heap size or reducing metadata size.
Conclusion
HDFS monitoring and alerts with practical examples is useful only when each recommendation is version-scoped, observable, and reversible where the technology permits. Copying a command without checking prerequisites and expected output is not an operations procedure.
As a next step, choose one low-risk verification for HDFS monitoring, record the current state, run the documented check, compare the result with the expected signal, and review dependencies such as Apache Spark, NiFi, and Kafka.
A reliable technical workflow makes failure visible, protects sensitive values, limits changes to the intended resource, and defines recovery verification before an incident forces the decision.