Playbook: troubleshoot a failing site or app
Nội dung này hiện chưa có sẵn bằng ngôn ngữ của bạn.
Work read-only first, collect evidence, then propose one fix at a time. A read
token covers the core tools and the registry reads. Over MCP, every step that goes
through jobs_create needs an operate token (over REST, a read token may dispatch
read-level kinds such as app.logs or site.stats; storage.usage and storage.du are
operate kinds). Fixes need operate.
1. Locate it
Section titled “1. Locate it”- A site:
servers_sites_allreturns its server, type and state.site_get {domain}(core) returns details from the cache. - A Docker app or stack:
servers_docker_all/servers_stacks_all. - Recent changes on that server:
jobs_list {id}. A failed or recent deploy is the usual suspect. - External symptoms:
uptime_incidentsanduptime_monitors_list.
2. Is the server healthy?
Section titled “2. Is the server healthy?”Start with one call: jobs_create {id, body: {type: "system.diagnose"}} (agent 0.2.156+, read
level), then jobs_output. It returns findings (each with severity and a stable code:
disk_full, disk_high, inodes_high, units_failed, oom_kills, memory_low,
memory_pressure, load_high, journal_errors) plus host and load, memory, disks with inodes,
failed units, listening ports, journal errors of the last hour, OOM kills of the last 24 h, the
nginx error tail and the top CPU processes. It changes nothing. The checks below go deeper:
| Check | Tool | Look for |
|---|---|---|
| Online | servers_list | online: false → see Agent won’t come online. Cached reads may be stale. |
| Load | metrics_get {server} · servers_metrics_history {id, query: {range: "6h"}} | CPU or RAM pinned, swap in use, disk above 90% |
| Services | services_status {server} · servers_inventory {id, kind: "services"} | nginx, php*-fpm, mariadb/postgresql, docker or redis not active |
| Disk | jobs_create storage.usage | A full root disk breaks almost everything |
| Traffic | servers_traffic_history {id} | A spike in 5xx, or a sudden traffic surge |
3. Read the logs
Section titled “3. Read the logs”Core tool logs_tail {server, target, lines} (live, read-only):
| Target | When |
|---|---|
site:<domain> (or site:<domain>:nginx-error / :nginx-access / :php-error) | One site’s own logs, the first stop for a site |
nginx-error · nginx-access | Proxy errors (502/504), TLS errors, rewrites |
php-fpm | PHP pool crashes, max_children reached |
mariadb (or mysql) | Database crashes, too many connections |
syslog · auth | OOM kills, systemd restarts, SSH issues |
For containers, use jobs_create app.logs {name, lines} or
docker.logs {container, lines}, and docker_ps {server} for state and restarts.
service.logs {name, lines} returns a system unit’s journal.
4. Type-specific checks
Section titled “4. Type-specific checks”- Runtime sites (
nodejs,python,go):sites_faults {id, domain, query: {range: "24h"}}shows OOM kills, memory or process caps and CPU throttling.jobs_create site.stats {domain}gives a per-site snapshot. A 502 usually means the process isn’t listening on itsappPort. - PHP and WordPress:
php_list {server}andservers_inventory {id, kind: "php_detail"}show versions and FPM settings. For WordPress,wp_cache {domain, action: "status"}shows the cache state, andjobs_create wp.updateslists pending updates. - Docker apps and stacks: a container in a restart loop shows in
docker_ps. Check the image tag and env (app.env-list/stack.env-listmask every value unless you passreveal: true; only reveal when you need a value, and handle that output carefully). For stacks, the primary service must still publish127.0.0.1:__MZ_PORT__:<port>. - TLS:
ssl_list {server}shows expired or missing certificates. - Firewall / SSH: risky firewall/SSH changes revert unless confirmed. A
security.fw,security.fw-toggle,security.sshorsecurity.ssh-allowresult with arevertobject undoes itself after 120 s;servers_inventory {id, kind: "security"}shows it aspending_revert. Ask the human to open a new SSH session, then sendsecurity.confirm {id}. Locked out: the human runsmzagent rescue allfrom the provider’s console.
High CPU or swap: read the signal, not the number
Section titled “High CPU or swap: read the signal, not the number”%CPUper process inps-style lists is a lifetime average; check live load inmetrics_getbefore acting.- A few PHP pools at high CPU with a low page-cache hit rate (
cache:HITrare in the access log) almost always means bots on uncached paths, not visitors. - Swap at 100% with plenty of available RAM is parked memory, not pressure (agent 0.2.143+
heartbeats carry
swap_in_ppsandmem_psi_some_avg60; alert onmem_pressure/swap_in, notswap). See the Assistant KB pages “CPU at 100% from php-fpm pools” and “Swap at 100%” (search_docs).
5. Fix, one step at a time
Section titled “5. Fix, one step at a time”Propose the fix, get the human’s approval for anything user-facing, and verify after each step.
| Problem | Fix | Notes |
|---|---|---|
| Service down | service_control {server, action: "restart", name} previews; add apply: true to run | Or jobs_create service.action {action, name} |
| Runtime site stuck | jobs_create site.restart {domain} | |
| App or stack unhealthy | app.restart {name} / stack.restart {name}; roll back with stack.rollback {name, to} (backups:restore) | Check stack.releases first |
| PHP pool exhausted | php.fpm-get → php.fpm-set; php.restart | Read jobs_schema for the fields |
| Disk full | storage_clean {server, targets: ["apt","logs","tmp","caches"]} previews; add apply: true to delete | jobs_create storage.du finds the big directories |
| Certificate expired | ssl_renew {server, domain} (dry run) → apply: true | Or ssl.issue {domain} |
| Resource cap hit | site.limits-set {domain, mem?, cpu?, tasks?} | Or reduce the load |
| Old agent: job exits 127 | agent_update {id} | Then retry the job |
CPU pinned by php-fpm pools of a few WordPress sites | Read site:<domain>:nginx-access: one IP or POST /xmlrpc.php / /wp-login.php dominating = brute force. agent_update {id} (agents after 0.2.141 apply the WordPress guard: xmlrpc 403, login rate limit, fail2ban) | jobs_create {id, body: {type: "site.wp-guard", domain}} reads the guard (agent 0.2.142+); add xmlrpc: "allow" only if the site uses Jetpack or the WordPress app |
| Swap at 100% | Parked pages if RAM is available and swap-in/out is ~0: the agent’s swap guard reclaims it automatically; real shortage if available RAM is low | jobs_create {id, body: {type: "system.swap-status"}} (agent 0.2.142+) explains the decision; system.swap-reclaim runs it now |
After every fix: re-run the check that showed the problem (logs, services_status,
docker_ps, curl the URL) and confirm the uptime monitor recovers.
When to stop and hand over
Section titled “When to stop and hand over”- The fix needs a shell (
docker.execand the terminal are never available to tokens): give the human the exact commands to run in Terminal, or in an SSH session with the on-boxmzCLI. - The fix needs a scope or plan the token doesn’t have: report
required_scopeorrequired_tier. - The data looks corrupted: propose a restore (Backups and restore) rather than editing in place.
Related
Section titled “Related”- Troubleshooting: agent, jobs, SSL, backups and API errors.
- Safe operating rules