Sub topic 14
Monitoring clusters and troubleshooting common problems
This chapter assumes you have read the earlier chapters on cluster anatomy, access modes, autoscaling and auto termination, and the cost model. You should know what a driver and an executor are, and you should be able to read a cluster configuration in JSON. The goal is a repeatable way to find out why a cluster is slow, unhealthy, expensive, or gone.
Where to look first
Classic compute (all-purpose and job clusters) exposes several sources of evidence. Each answers a different question.
| Source | Where | Answers |
|---|---|---|
| Event log | Cluster page, Event log tab, or the Clusters API | What did the platform do, and when? Start, resize, node loss, termination. |
| Driver logs | Cluster page, Driver logs tab | What did the driver process print? Stack traces, library errors, init script output. |
| Metrics | Cluster page, Metrics tab | How loaded were CPU, memory, and network on each node? |
| Spark UI | Cluster page, Spark UI tab | Why was a particular job or stage slow? Skew, spill, shuffle size. |
| System tables | `system.compute`, `system.billing` | What happened over days or weeks, and what did it cost? |
Start with the event log. It tells you whether the problem is the platform (nodes could not be acquired, the cluster was terminated) or your code (the cluster stayed healthy while a job failed). Only then move to logs, metrics, and the Spark UI.
Serverless compute has no cluster page to open. You do not see a driver, workers, or a cluster event log. Evidence comes from the notebook or job run output, the query history and query profile, and the system tables. The rest of this chapter points out where that changes things.
Reading the event log
Every cluster records a stream of events. The ones you will use most often are these:
STARTING,RUNNING,TERMINATING, andTERMINATEDmark the lifecycle.RESIZINGandUPSIZE_COMPLETEDshow autoscaling at work.NODES_LOSTmeans workers disappeared, often because the cloud provider reclaimed spot instances.DRIVER_NOT_RESPONDINGmeans the driver stopped answering health checks.INIT_SCRIPTS_STARTEDandINIT_SCRIPTS_FINISHEDbracket cluster-scoped init scripts.
A TERMINATED event carries a termination reason with a code, a type, and parameters. The type tells you who is responsible. SUCCESS covers normal shutdowns such as INACTIVITY after auto termination. CLIENT_ERROR points at your configuration, CLOUD_FAILURE at the cloud provider, and SERVICE_FAULT at Databricks.
You can pull the same events through the Clusters API. This script prints the most recent events for a cluster. It assumes DATABRICKS_HOST holds the workspace URL without a trailing slash and DATABRICKS_TOKEN holds a personal access token.
import os
from datetime import datetime, timezone
import requests
host = os.environ["DATABRICKS_HOST"]
token = os.environ["DATABRICKS_TOKEN"]
def cluster_events(cluster_id, event_types=None, limit=25):
body = {"cluster_id": cluster_id, "limit": limit, "order": "DESC"}
if event_types:
body["event_types"] = event_types
resp = requests.post(
f"{host}/api/2.1/clusters/events",
headers={"Authorization": f"Bearer {token}"},
json=body,
timeout=30,
)
resp.raise_for_status()
return resp.json().get("events", [])
if __name__ == "__main__":
for event in cluster_events("0101-000000-abcd1234"):
ts = datetime.fromtimestamp(event["timestamp"] / 1000, tz=timezone.utc)
print(ts.isoformat(), event["type"], event.get("details", {}))Replace the cluster ID with your own. Timestamps are milliseconds since the Unix epoch, which is why the script divides by 1000.
Using metrics to size a cluster
The Metrics tab graphs CPU, memory, network, and file system usage per node, and the driver is shown separately. Look for these patterns:
- Driver memory near its limit while workers are idle. The work is happening on the driver. Typical causes are
collect()ortoPandas()on a large result, or many notebooks attached to one all-purpose cluster. - Memory high and swap or disk activity rising on workers. Executors are spilling. Use a node type with more memory per core, or reduce data per partition.
- CPU low on most workers for long stretches. The cluster is oversized for the work, or a few tasks run alone because of skew.
- CPU saturated on every node. The cluster is undersized, or autoscaling has reached
max_workers.
For history beyond what the UI shows, query the node timeline system table. This query finds the peak memory and average CPU per node over the last day.
SELECT
cluster_id,
instance_id,
driver,
MAX(mem_used_percent) AS peak_mem_percent,
AVG(cpu_user_percent + cpu_system_percent) AS avg_cpu_percent
FROM system.compute.node_timeline
WHERE cluster_id = '0101-000000-abcd1234'
AND start_time >= current_timestamp() - INTERVAL 1 DAY
GROUP BY cluster_id, instance_id, driver
ORDER BY peak_mem_percent DESC;Your account must have the system.compute schema enabled and your user must be granted access to it.
Common problems and their usual causes
| Symptom | Likely cause | First check | Typical fix |
|---|---|---|---|
| Cluster stays in `PENDING` or fails to start | Cloud quota exhausted, instance type unavailable, subnet out of IP addresses | Termination reason code, such as `CLOUD_PROVIDER_LAUNCH_FAILURE` | Pick another node type or zone, request a quota increase, widen the subnet |
| Cluster terminates right after starting | Failing init script, or a pool that cannot supply nodes | `INIT_SCRIPT_FAILURE` or `INSTANCE_POOL_CLUSTER_FAILURE` code, init script logs | Fix the script, or enlarge or reconfigure the pool |
| `DRIVER_NOT_RESPONDING`, or notebook says the cluster is detached | Driver out of memory, or overloaded by many attached notebooks | Driver logs and driver memory in Metrics | Collect less data, use a larger driver node, split users across clusters |
| `NODES_LOST` and tasks retried | Spot instances reclaimed | Event log timing against task failures | Keep the driver on-demand, or use on-demand workers for critical jobs |
| Job slow but cluster looks healthy | Data skew, too few or too many shuffle partitions | Spark UI stage page, task duration distribution | Repartition, salt skewed keys, tune shuffle partitions |
| Library import fails or versions conflict | Cluster library or runtime version mismatch | Driver logs, Libraries tab | Pin versions, use a compatible runtime, restart the cluster after changes |
| Permission or "not supported" error on a command | Access mode restriction | Access mode on the Configuration tab | Use a different API, or choose an access mode that supports the operation |
| Cluster ran overnight and cost money | Auto termination not set or activity kept it alive | `autotermination_minutes`, `system.billing.usage` | Set a shutdown time, check for scheduled queries or open sessions |
Two of these deserve extra detail.
Skew versus size. If a stage has 200 tasks and 199 finish in seconds while one runs for ten minutes, adding workers will not help. The stage page in the Spark UI shows the task duration distribution. A wide gap between the median and the maximum points to skew.
Access mode errors. Standard access mode (USER_ISOLATION) enforces Unity Catalog permissions and isolates users from each other, so it restricts some low-level features. If a command works on a dedicated cluster but fails on a standard one, compare the error message with the documented limitations for the runtime version you use before changing anything else.
Tracking cost with system tables
A cluster that behaves correctly can still be a problem if it runs when no one uses it. The billing usage table records DBUs per cluster and per day.
SELECT
usage_date,
sku_name,
SUM(usage_quantity) AS dbus
FROM system.billing.usage
WHERE usage_metadata.cluster_id = '0101-000000-abcd1234'
AND usage_date >= date_sub(current_date(), 14)
GROUP BY usage_date, sku_name
ORDER BY usage_date;DBU usage on days when nobody worked on the cluster is a sign that auto termination is not firing. Check the idle timeout, then look for something that keeps the cluster active, such as a scheduled dashboard refresh, a streaming query, or a notebook in a loop. Remember that this table covers DBUs only. Cloud infrastructure charges for the virtual machines appear in your cloud provider's bill, as described in the cost model chapter.
A working routine
- State the symptom in one sentence: failed to start, failed during a run, slow, or expensive.
- Open the event log and find the last event before the problem. Read the termination reason if there is one.
- If the cluster was healthy, read the driver logs around the failure time.
- If the problem is speed, compare Metrics with the Spark UI to separate sizing problems from skew.
- Change one setting at a time, and record the change so you can compare runs.
- If the issue repeats, put the fix into the cluster definition or a cluster policy so that it is applied to every new cluster.
Exercise
A nightly job on a job cluster fails after about two minutes. The event log shows a TERMINATED event with the code INIT_SCRIPT_FAILURE and a type of CLIENT_ERROR. Increasing max_workers did not help. Explain why, and say where you look next.
Show answer
The cluster was terminated before any Spark work ran, so worker count is irrelevant. CLIENT_ERROR means the cause is in your configuration, here a cluster-scoped init script that exited with an error. Look at the init script logs (the cluster log delivery location, if configured) and the driver logs around startup to find the failing command, fix or remove the script, and rerun.
Exercise
A stage in the Spark UI has 200 tasks. The median task takes 4 seconds and the longest takes 9 minutes. The Metrics tab shows most workers at under 10 percent CPU. Is adding workers the right fix? What would you try?
Show answer
No. The long task keeps the stage running while the other workers sit idle, which is the pattern of data skew. More workers would only add idle capacity. Try repartitioning on a more even key, salting the skewed key, or enabling adaptive query execution settings that split skewed partitions, then compare the task duration distribution.
Exercise
The system.billing.usage query for an all-purpose cluster shows DBUs every day, including weekends, although no one uses it. List two things to check.
Show answer
First, check that autotermination_minutes is set to a sensible value on the cluster. Second, look for activity that resets the idle timer, such as scheduled dashboard refreshes, a running streaming query, or a notebook with an open loop or long-running command.