File size: 20,700 Bytes
71e9dba | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | ---
id: OPS_task_12_iotop_baobab_diskhog
name: 磁盘 I/O 跑飞进程的 iotop+baobab 联合溯源
category: OPS
timeout_seconds: 1800
---
## Prompt
Background: An on-call teammate pings you in chat: "The `/tmp_workspace/varlog` mount has gone from 12% to 71% in the last 30 minutes — if it keeps climbing, staging is going to page. `du -sh` is slow and doesn't show me which subdirectory is growing. Please locate the current writer (a process writing one log file at a sustained ~6 MiB/s) and the exact hog file path, stop it, then write up a report I can drop in the post-mortem channel."
Environment already prepared: warmup has launched a three-thread Python background process `log_burst.py`; one of its threads is the runaway writer, and its pid is recorded in `/tmp_workspace/state/log_burst.pid` (fallback reference only when things go wrong — not the answer).
Task objective: use two independent evidence chains — structured (CLI / `/proc` / iotop / lsof) and visual (a directory-size visualization scan such as GNOME baobab or an equivalent tree-map) — to locate the hog process and the file it is writing to, stop the bleeding and rescan, then write an incident report suitable for the post-mortem channel. All deliverables go under `/tmp_workspace/results/`.
### Hard constraints on the main deliverable `diagnosis.json`
- Must contain 7 self-consistent fields: `top_io_pid` (int), `top_io_cmd` (str, must contain the substring `log_burst.py`), `largest_dir_path`, `largest_file_path` (must contain both the directory name `report_renderer` and the suffix `.frames.log`), `write_mibps_observed` (float ≥ 3.0, consistent with the actually observed rate), `remediation_taken` (str), `post_remediation_iostat_w_mibps` (float).
- Anti-cheat: `top_io_pid` / `top_io_cmd` must be obtained from live per-process I/O observation plus the real `ps` cmdline; `actions.log` must not contain literals such as `cat /tmp_workspace/state/log_burst.pid` or `pgrep log_burst` that shortcut by reading the pidfile.
- The contender process (`log_burst.py`) must remain running until `iostat_after.txt` sampling begins, otherwise the before/after comparison is invalid.
### Supporting deliverables (located in `/tmp_workspace/results/`)
| File | Requirement |
|---|---|
| `df_before.txt` | Capacity / inode snapshot of the `/tmp_workspace/varlog` mount (must contain `%` or the path); non-empty |
| `iostat_before.txt` | Steady-state disk I/O snapshot, ≥ 2 sampling blocks, containing one of the column headers `wMB/s` / `kB_wrtn` / `w/s` |
| `iotop_top.txt` | Per-process aggregated write-rate snapshot, containing one of `DISK WRITE` / `kB_wr/s` / `Total DISK WRITE` (or a semantically equivalent fallback such as `pidstat -d`); the hog cmdline and rate value must be readable from it |
| `lsof_hog.txt` | Reverse lookup of "who has the hog file open", containing a `PID` column + `COMMAND` column + the real `.frames.log` file name |
| `ps_hog.txt` | Process details of the hog PID, containing the real `log_burst.py` cmdline |
| `proc_fd.txt` | fd-table listing of the hog PID; the hog file name must appear in the fd list |
| `remediation.sh` | List of remediation commands (each annotated with `# what`). Must try SIGTERM first before considering SIGKILL; must clear the file with `truncate -s 0` rather than `rm` (preserving the inode); `rm -rf /tmp_workspace/varlog` is **forbidden** |
| `iostat_after.txt` | iostat resampled after remediation; the steady-state write rate must be ≤ 1/5 of the steady-state value in `iostat_before.txt` |
| `postmortem.md` | Post-mortem of ≥ 600 characters; must contain the 4 section headings `## 时间线`, `## 根因`, `## 止血与彻底修复建议`, `## 跨通道证据链`; terminology hits among `rotation/frames/renderer/iotop/baobab/lsof` ≥ 4/6 |
| `cross_channel.json` | `{"switches": <int ≥ 5>, "trace": [...]}`; `trace` must have ≥ 5 items with ≥ 2 STRUCT and ≥ 2 VISUAL each; every item must have a corresponding file-evidence artifact |
### 4 work-in-progress screenshots (fixed file names, PNG, ≥ 800×600, each ≥ 40 KB)
- `view_baobab_overview.png`: overall view of a directory-size visualization scan over `/tmp_workspace/varlog` (folder list + ring chart or tree-map).
- `view_baobab_treemap_hover.png`: in tree-map view, **the largest rectangle (occupying ≥ 60% of the canvas)** is shown in hover/tooltip state, with the tooltip displaying the full path and a human-readable size.
- `view_files_highlighted.png`: a file-manager view drilling from the visualization down to the specific hog file, with **the target `.frames.log` file highlighted/selected**.
- `view_baobab_after.png`: tree-map view after remediation and rescan; **no single rectangle dominates the canvas anymore**.
Grading performs OCR keyword checks and VLM visual scoring on the screenshots, which must be real windows rather than placeholders or collages; STRUCT textual evidence and VISUAL screenshot evidence must corroborate each other on PID and file path.
## Expected Behavior
设计意图与典型解题路径(仅供出题人参考,不发给 agent):
1. 推荐用 `iotop -aoP` 做按进程聚合的累计写速率统计;也可走 `pidstat -d 1` 或直接读 `/proc/<pid>/io` 的 fallback。可视化通道推荐 GNOME Disk Usage Analyzer (baobab),也可用任何提供 tree-map / ring chart 的等价工具。
2. step 1:`df -h /tmp_workspace/varlog` + `iostat -xm 2 3` 拿稳态 baseline,分别落 `df_before.txt` / `iostat_before.txt`。
3. step 2:`iotop -aoP` 跑十几秒后中断,落 `iotop_top.txt`,从中读出 hog PID + cmdline + ~6 MiB/s 写速率。
4. step 3:用 baobab(或等价 tree-map 工具)扫 `/tmp_workspace/varlog`,截 overview,并在最大矩形上 hover 截 treemap_hover。
5. step 4:`lsof | grep .frames.log`、`ps -p <pid> -o pid,cmd,etime`、`ls -la /proc/<pid>/fd/` 三件套互相印证,使 PID ↔ 文件路径自洽,分别落 `lsof_hog.txt` / `ps_hog.txt` / `proc_fd.txt`。
6. step 5:用文件管理器定位并选中目标 `.frames.log`,截 `view_files_highlighted.png`。
7. step 6:写 `remediation.sh`:先 `kill -TERM <pid>`,必要时 `kill -KILL`;再 `truncate -s 0 <file>`;严禁 `rm -rf`。
8. step 7:再跑一次 `iostat -xm 2 3` 落 `iostat_after.txt`,并复扫目录大小可视化截 `view_baobab_after.png`。
9. step 8:组织 `diagnosis.json` / `cross_channel.json` / `postmortem.md`,构成完整跨通道证据链。
约束说明(反作弊):`actions.log` 不得包含直接读 `/tmp_workspace/state/log_burst.pid` 的字面量;`top_io_pid` / `top_io_cmd` 必须来自 iotop / ps 现场观测真值。
评分要点(hard gates,从评分上限反推):
- 缺 STRUCT 任一关键证据(iotop / lsof / ps cmdline)→ 封顶 0.4
- 缺 GUI 截图(4 张真图不足一半)→ 封顶 0.4
- 截图 OCR 关键字命中率 < 0.5 → 封顶 0.5
- VLM 视觉判分 < 0.6(baobab 真窗口 / 主导矩形 / after 已清理)→ 封顶 0.55
- diagnosis.json 的路径与 cmdline 都对不上现场 → 封顶 0.55
- iostat_after 稳态写速率未降到 before 的 1/5 → 对应子项扣分
## Source
- r/devops 2023-11 thread "headless chrome screenshot worker filled
/var/log in 12 hours"(产生本任务设计灵感的真实事故模式)
- iotop manpage + IBM Developer "Linux performance tools — iotop"
https://developer.ibm.com/articles/au-aix7iotop/
- GNOME baobab User Guide
https://help.gnome.org/users/baobab/stable/
- 对应 EyesOn-Bench OPS 维度:O12 — storage I/O attribution via
CLI byte-counters × GUI tree-map area-encoding
## Grading Criteria
- [ ] 1. `df_before.txt` + `iostat_before.txt` 存在且非空
- [ ] 2. `iotop_top.txt` 存在;包含 "DISK WRITE" 表头或同义关键字
- [ ] 3. `view_baobab_overview.png` 存在 ≥ 800×600,OCR 命中
"Disk Usage Analyzer / Folder / Size / Contents" 之一
- [ ] 4. `view_baobab_treemap_hover.png` 存在;VLM judge 能识别
tree-map + tooltip
- [ ] 5. `view_files_highlighted.png` 存在;OCR 命中 ".frames.log" 或文件名
- [ ] 6. `lsof_hog.txt` 含 PID 列 + COMMAND 列 + 出现 hog 文件名
- [ ] 7. `ps_hog.txt` 含 `log_burst.py` 字样(agent 自己抓到的真 cmdline)
- [ ] 8. `diagnosis.json` 7 个必备字段全在;largest_file_path 与 hog 的
真实路径在 baobab 截图中匹配
- [ ] 9. `iostat_after.txt` 的稳态 wMB/s ≤ before 的 1/5
- [ ] 10. `view_baobab_after.png` 存在;VLM judge 显示 tree-map 不再有
一块矩形吃满全图
- [ ] 11. `postmortem.md` ≥ 600 字符 + 关键词 ≥ 4/6 + 4 段标题齐
- [ ] 12. `cross_channel.json` switches ≥ 5
- [ ] 13. Hard gate:缺 STRUCT/VISUAL 任一通道证据 → 封顶 0.4
## Automated Checks
```python
def grade(workspace_path=None, **kwargs) -> dict:
"""OPS_task_12 grader: storage I/O attribution via iotop CLI + baobab GUI.
Sub-scores cover CLI evidence (df / iostat / iotop / lsof / ps), GUI
screenshots (overview, treemap hover, files highlighted, after-fix),
OCR + VLM verification, post-remediation iostat ratio, postmortem
quality, and cross-channel switch count."""
import json, os, re, subprocess
from pathlib import Path
rd = Path("/tmp_workspace/results")
gt_dir = Path("/opt/ops12_gt") if Path("/opt/ops12_gt/expected.json").exists() else Path("/tmp_workspace/gt")
s = {}
expected = {}
if (gt_dir / "expected.json").exists():
try: expected = json.loads((gt_dir / "expected.json").read_text())
except Exception: expected = {}
hog_sub = expected.get("hog_process_cmdline_substring", "log_burst.py")
hog_file_suffix = expected.get("hog_log_filename_suffix", ".frames.log")
hog_dir_basename = expected.get("expected_treemap_largest_subdir_basename", "report_renderer")
drop_factor = float(expected.get("min_post_remediation_drop_factor", 5.0))
def _read(name):
p = rd / name
return p.read_text(errors="ignore") if p.exists() else ""
# 1. df + iostat before
df_before = _read("df_before.txt")
s["df_before_present"] = 1.0 if df_before and ("/tmp_workspace/varlog" in df_before or "%" in df_before) else 0.0
iostat_before = _read("iostat_before.txt")
s["iostat_before_present"] = 1.0 if iostat_before and re.search(r"wMB/s|w/s|kB_wrtn", iostat_before) else (0.4 if iostat_before else 0.0)
# 2. iotop_top.txt — must mention DISK WRITE or pidstat fallback
iotop_txt = _read("iotop_top.txt")
if iotop_txt:
has_hdr = bool(re.search(r"Total DISK WRITE|DISK\s+WRITE\s+", iotop_txt))
has_pidstat = bool(re.search(r"\bkB_wr/s\b", iotop_txt) and re.search(r"\bCommand\b", iotop_txt))
has_rate = bool(re.search(r"\b([3-9]|\d{2,})(\.\d+)?\s*(M|MB|MiB)/s\b|\b\d{4,}(\.\d+)?\s*K", iotop_txt))
s["iotop_evidence"] = 1.0 if (has_hdr or has_pidstat) and has_rate and hog_sub in iotop_txt else (0.4 if iotop_txt else 0.0)
else:
s["iotop_evidence"] = 0.0
# 3. lsof + ps + proc fd evidence
lsof_txt = _read("lsof_hog.txt")
s["lsof_present"] = 1.0 if lsof_txt and "PID" in lsof_txt and hog_file_suffix in lsof_txt else (0.5 if lsof_txt else 0.0)
ps_txt = _read("ps_hog.txt")
s["ps_cmdline_match"] = 1.0 if ps_txt and hog_sub in ps_txt else (0.4 if ps_txt else 0.0)
proc_fd = _read("proc_fd.txt")
s["proc_fd_match"] = 1.0 if proc_fd and hog_file_suffix in proc_fd else (0.3 if proc_fd else 0.0)
# 4. diagnosis.json: required keys + cmdline match + path match
diag_path = rd / "diagnosis.json"
diag_keys = 0.0; diag_cmd = 0.0; diag_path_ok = 0.0; diag_mibps = 0.0
if diag_path.exists():
try:
d = json.loads(diag_path.read_text())
req = expected.get("report_required_keys", [])
present = sum(1 for k in req if k in d)
diag_keys = present / max(1, len(req))
cmdline = str(d.get("top_io_cmd", ""))
if hog_sub in cmdline: diag_cmd = 1.0
lf = str(d.get("largest_file_path", ""))
if hog_file_suffix in lf and hog_dir_basename in lf:
diag_path_ok = 1.0
try:
w = float(d.get("write_mibps_observed", 0))
iot_nums = [float(x) for x in re.findall(r"(\d+(?:\.\d+)?)\s*(?:M|MB|MiB)/s", iotop_txt)]
iot_max = max(iot_nums) if iot_nums else 0.0
if w >= 3.0 and iot_max >= 3.0 and abs(w - iot_max) <= max(1.5, 0.4 * iot_max):
diag_mibps = 1.0
elif w >= 3.0 and iot_max >= 3.0:
diag_mibps = 0.5
else:
diag_mibps = 0.0
except Exception:
pass
except Exception:
pass
s["diagnosis_keys"] = diag_keys
s["diagnosis_cmdline_match"] = diag_cmd
s["diagnosis_path_match"] = diag_path_ok
s["diagnosis_writerate_plausible"] = diag_mibps
# 5. post-remediation iostat ratio
iostat_after = _read("iostat_after.txt")
s["iostat_after_present"] = 1.0 if iostat_after else 0.0
def _peak_w(text):
vals = []
for ln in text.splitlines():
# heuristic: numeric column near "wMB/s" rows under device names
m = re.findall(r"\b\d+\.\d+\b", ln)
if m and not ln.startswith("Linux") and "Device" not in ln and "avg" not in ln:
vals.extend(float(x) for x in m)
return max(vals) if vals else 0.0
pre_peak = _peak_w(iostat_before)
post_peak = _peak_w(iostat_after)
if pre_peak > 0 and post_peak >= 0:
ratio = (pre_peak + 0.01) / (post_peak + 0.01)
s["remediation_iostat_drop"] = 1.0 if ratio >= drop_factor else max(0.0, min(1.0, ratio / drop_factor))
else:
s["remediation_iostat_drop"] = 0.4 if iostat_after else 0.0
# 6. GUI screenshots present + size
shots = ["view_baobab_overview.png", "view_baobab_treemap_hover.png",
"view_files_highlighted.png", "view_baobab_after.png"]
def _real_img(p):
try:
from PIL import Image
if not p.exists() or p.stat().st_size < 40000: return False
with Image.open(p) as im: return im.size[0] >= 800 and im.size[1] >= 600
except Exception: return False
present = sum(1 for n in shots if _real_img(rd / n))
s["gui_screenshots_count"] = present / len(shots)
# 7. OCR keyword hits
ocr_hits = 0
try:
import pytesseract
from PIL import Image
kws = {
"view_baobab_overview.png": ["Disk Usage", "Folder", "Size", "Contents", "Analyzer", "baobab"],
"view_baobab_treemap_hover.png": ["MB", "MiB", "GB", hog_dir_basename, hog_file_suffix, "Treemap"],
"view_files_highlighted.png": [hog_file_suffix, hog_dir_basename, "Files"],
"view_baobab_after.png": ["Disk Usage", "Folder", "Size", "Analyzer", "baobab"],
}
for n, ks in kws.items():
p = rd / n
if p.exists():
try:
tx = pytesseract.image_to_string(Image.open(p))
if any(k in tx for k in ks): ocr_hits += 1
except Exception:
pass
s["gui_screenshots_ocr"] = ocr_hits / len(shots)
except ImportError:
s["gui_screenshots_ocr"] = 0.5
# 8. postmortem
pm = _read("postmortem.md")
pm_chars = len(pm)
s["postmortem_length"] = 1.0 if pm_chars >= 600 else pm_chars / 600.0
pm_kws = expected.get("expected_postmortem_keywords",
["rotation", "frames", "renderer", "iotop", "baobab", "lsof"])
hits = sum(1 for k in pm_kws if k.lower() in pm.lower())
s["postmortem_keywords"] = 1.0 if hits >= 6 else (0.6 if hits >= 5 else 0.3 if hits >= 4 else 0.0)
required_h = ("## 时间线", "## 根因", "## 止血与彻底修复建议", "## 跨通道证据链")
sect_hits = sum(1 for h in required_h if h in pm)
s["postmortem_sections"] = 1.0 if sect_hits == 4 else sect_hits / 8.0
# 9. cross-channel switches
cc = rd / "cross_channel.json"
cc_ok = 0.0
if cc.exists():
try:
d = json.loads(cc.read_text())
sw = int(d.get("switches", 0))
tr = d.get("trace", [])
need = {"STRUCT:iostat":"iostat_before.txt","STRUCT:lsof":"lsof_hog.txt",
"STRUCT:ps":"ps_hog.txt","STRUCT:kill":"remediation.sh",
"VISUAL:overview":"view_baobab_overview.png","VISUAL:treemap_hover":"view_baobab_treemap_hover.png",
"VISUAL:after":"view_baobab_after.png"}
backed = sum(1 for x in tr if x in need and (rd / need[x]).exists() and (rd / need[x]).stat().st_size > 200)
if sw >= 5 and len(tr) >= 5 and backed >= 5:
cc_ok = 1.0
elif backed >= 3:
cc_ok = 0.5
except Exception:
pass
s["cross_channel_switches"] = cc_ok
# 10. VLM rubric
try:
from _judge_helper import vlm_score_rubric
except Exception:
vlm_score_rubric = None
vlm_imgs = [str(rd / n) for n in shots if (rd / n).exists()]
vlm_judge = 0.0
if vlm_score_rubric and vlm_imgs:
rubric = {
"vlm_baobab_real": "至少一张截图清晰显示 GNOME Disk Usage Analyzer (baobab) 的主窗口,含左侧 folder 列表 + 中央 ring chart 或 tree-map",
"vlm_treemap_dominant_rect": "treemap 截图里有一个矩形面积明显比其他都大(超过 60% 屏幕面积),且有 tooltip / hover 状态可见",
"vlm_after_state_clean": "view_baobab_after.png 显示 tree-map 已经没有那块吃满全图的巨型矩形",
}
vlm = vlm_score_rubric(vlm_imgs[:3], rubric, instruction="评估值班 SRE 用 baobab 排查磁盘 hog 的截图。")
for k in rubric: s[k] = vlm.get(k, 0.0)
s["judge_method"] = vlm.get("judge_method", "failed")
vlm_judge = sum(s.get(k, 0.0) for k in rubric) / max(1, len(rubric))
else:
for k in ("vlm_baobab_real", "vlm_treemap_dominant_rect", "vlm_after_state_clean"):
s[k] = 0.5
vlm_judge = 0.5
nums = [v for k, v in s.items() if isinstance(v, (int, float)) and k != "judge_method"]
base = sum(nums) / max(1, len(nums))
# Hard gates
has_cli = (s["iotop_evidence"] >= 0.5 and s["lsof_present"] >= 0.5
and s["ps_cmdline_match"] >= 0.4)
if not has_cli: base = min(base, 0.4)
# NOTE: GUI invocation is not a scoring axis; missing PNGs already
# cost the gui_screenshots_count / vlm_* sub_scores.
# Only apply the VLM cap when the helper actually ran. Otherwise the
# 0.5 fallback would penalise environments without _judge_helper.
if vlm_score_rubric is not None and vlm_judge < 0.6:
base = min(base, 0.55)
if s.get("gui_screenshots_ocr", 0.0) < 0.5: base = min(base, 0.5)
if s["diagnosis_path_match"] == 0 and s["diagnosis_cmdline_match"] == 0:
base = min(base, 0.55)
s["overall_score"] = round(base, 3)
return s
```
## Workspace Path
```
workspace/OPS/task_12_iotop_baobab_diskhog
```
## Skills
```
```
## Env
```
```
## Warmup
```bash
set +e
export DEBIAN_FRONTEND=noninteractive
mkdir -p /tmp_workspace/results /tmp_workspace/state /tmp_workspace/varlog /opt/ops12_gt
for i in $(seq 1 30); do [ -d /tmp_workspace/exec ] && break; sleep 1; done
which iostat >/dev/null 2>&1 || timeout 120 apt-get -o Acquire::Retries=10 update -qq || true
which iostat >/dev/null 2>&1 || timeout 300 apt-get -o Acquire::Retries=10 install -y -qq --no-install-recommends sysstat lsof procps psmisc python3 python3-pip coreutils util-linux || true
python3 -c "import matplotlib, squarify, PIL, numpy" >/dev/null 2>&1 || timeout 300 pip install --quiet matplotlib squarify pillow numpy || true
chmod +x /tmp_workspace/exec/start_services.sh 2>/dev/null || true
nohup bash /tmp_workspace/exec/start_services.sh /tmp_workspace/varlog >/tmp_workspace/state/log_burst.out 2>&1 &
disown || true
sleep 2
echo "[warmup] log_burst running at pid $(cat /tmp_workspace/state/log_burst.pid 2>/dev/null || echo ?)"
# Move expected.json (contains hog_*_substring/path/service answer hints
# + postmortem keyword set) to root-only /opt/ops12_gt.
if [ -f /tmp_workspace/gt/expected.json ]; then
mv /tmp_workspace/gt/expected.json /opt/ops12_gt/expected.json 2>/dev/null || true
chown -R root:root /opt/ops12_gt 2>/dev/null || true
chmod 700 /opt/ops12_gt 2>/dev/null || true
chmod 600 /opt/ops12_gt/expected.json 2>/dev/null || true
rmdir /tmp_workspace/gt 2>/dev/null || true
fi
```
|