DiskMon
A sysops toolkit for scanning, monitoring, reporting, alerting, tracking top usage, checking health, fixing issues, cleaning up, backing up, restoring, logging, benchmarking, and comparing disk-related operations — all from the command line with full history tracking.
Commands
| Command | Description |
|---|
| INLINECODE0 | Record and review disk scan entries (run without args to see recent) |
| INLINECODE1 |
Record and review monitoring entries |
|
diskmon report <input> | Record and review report entries |
|
diskmon alert <input> | Record and review alert entries |
|
diskmon top <input> | Record and review top-usage entries |
|
diskmon usage <input> | Record and review usage entries |
|
diskmon check <input> | Record and review health check entries |
|
diskmon fix <input> | Record and review fix entries |
|
diskmon cleanup <input> | Record and review cleanup entries |
|
diskmon backup <input> | Record and review backup entries |
|
diskmon restore <input> | Record and review restore entries |
|
diskmon log <input> | Record and review log entries |
|
diskmon benchmark <input> | Record and review benchmark entries |
|
diskmon compare <input> | Record and review comparison entries |
|
diskmon stats | Show summary statistics across all log files |
|
diskmon export <fmt> | Export all data in JSON, CSV, or TXT format |
|
diskmon search <term> | Search across all logged entries |
|
diskmon recent | Show the 20 most recent activity entries |
|
diskmon status | Health check — version, data dir, entry count, disk usage |
|
diskmon help | Show usage info and all available commands |
|
diskmon version | Print version string |
Each data command (scan, monitor, report, etc.) works in two modes:
- - With arguments: Logs the input with a timestamp and saves to the corresponding
.log file - Without arguments: Displays the 20 most recent entries from that command's log
Data Storage
All data is stored locally in ~/.local/share/diskmon/. Each command writes to its own log file (e.g., scan.log, monitor.log, alert.log). A unified history.log tracks all activity across commands with timestamps.
- - Log format: INLINECODE27
- History format: INLINECODE28
- No external database or network access required
Requirements
- - Bash 4+ (uses
set -euo pipefail) - Standard POSIX utilities:
date, wc, du, head, tail, grep, basename, INLINECODE37 - No root privileges needed
- No API keys or external dependencies
When to Use
- 1. Tracking disk space trends over time — Use
diskmon monitor and diskmon usage to log periodic disk space readings across servers, building a historical record you can search and export - Setting up alert documentation — Use
diskmon alert to record threshold breaches and disk-full warnings, creating a searchable incident history - Documenting cleanup and maintenance — Use
diskmon cleanup and diskmon fix to keep timestamped logs of what was cleaned, freed, or repaired on which systems - Benchmarking storage performance — Use
diskmon benchmark and diskmon compare to log I/O test results and compare performance across different disks or configurations - Generating audit-ready exports — Use
diskmon export json to produce a structured file of all logged monitoring activity for capacity planning, compliance reviews, or team handoff
Examples
Log a scan and review history
CODEBLOCK0
Monitor, alert, and report workflow
CODEBLOCK1
Cleanup and fix tracking
CODEBLOCK2
Export and statistics
CODEBLOCK3
Backup, restore, and benchmark
CODEBLOCK4
How It Works
DiskMon uses a simple case-dispatch architecture in a single Bash script. Each command maps to a log file under ~/.local/share/diskmon/. When called with arguments, the input is appended with a timestamp. When called without arguments, the last 20 lines of that log are displayed. The stats command aggregates entry counts across all logs, export serializes everything into JSON, CSV, or plain text, and search greps across all log files for a given term.
Support
Powered by BytesAgain | bytesagain.com | hello@bytesagain.com
DiskMon
一个用于扫描、监控、报告、告警、追踪最高使用率、检查健康状态、修复问题、清理、备份、恢复、记录日志、基准测试和比较磁盘相关操作的系统运维工具包——全部通过命令行完成,并带有完整的历史追踪功能。
命令
| 命令 | 描述 |
|---|
| diskmon scan <输入> | 记录并查看磁盘扫描条目(不带参数运行可查看最近记录) |
| diskmon monitor <输入> |
记录并查看监控条目 |
| diskmon report <输入> | 记录并查看报告条目 |
| diskmon alert <输入> | 记录并查看告警条目 |
| diskmon top <输入> | 记录并查看最高使用率条目 |
| diskmon usage <输入> | 记录并查看使用率条目 |
| diskmon check <输入> | 记录并查看健康检查条目 |
| diskmon fix <输入> | 记录并查看修复条目 |
| diskmon cleanup <输入> | 记录并查看清理条目 |
| diskmon backup <输入> | 记录并查看备份条目 |
| diskmon restore <输入> | 记录并查看恢复条目 |
| diskmon log <输入> | 记录并查看日志条目 |
| diskmon benchmark <输入> | 记录并查看基准测试条目 |
| diskmon compare <输入> | 记录并查看比较条目 |
| diskmon stats | 显示所有日志文件的汇总统计信息 |
| diskmon export <格式> | 以JSON、CSV或TXT格式导出所有数据 |
| diskmon search <搜索词> | 在所有记录的条目中搜索 |
| diskmon recent | 显示最近20条活动条目 |
| diskmon status | 健康检查——版本、数据目录、条目数量、磁盘使用情况 |
| diskmon help | 显示使用说明和所有可用命令 |
| diskmon version | 打印版本字符串 |
每个数据命令(scan、monitor、report等)有两种工作模式:
- - 带参数: 将输入内容连同时间戳一起记录,并保存到对应的.log文件中
- 不带参数: 显示该命令日志中最近的20条记录
数据存储
所有数据本地存储在~/.local/share/diskmon/目录下。每个命令写入自己的日志文件(例如scan.log、monitor.log、alert.log)。统一的history.log文件记录所有命令的活动,并带有时间戳。
- - 日志格式:YYYY-MM-DD HH:MM|<输入内容>
- 历史记录格式:MM-DD HH:MM <命令>: <输入内容>
- 无需外部数据库或网络访问
系统要求
- - Bash 4+(使用set -euo pipefail)
- 标准POSIX工具:date、wc、du、head、tail、grep、basename、cat
- 无需root权限
- 无需API密钥或外部依赖
使用场景
- 1. 追踪磁盘空间随时间的变化趋势 — 使用diskmon monitor和diskmon usage定期记录各服务器的磁盘空间读数,建立可搜索和导出的历史记录
- 建立告警文档 — 使用diskmon alert记录阈值违规和磁盘满警告,创建可搜索的事件历史
- 记录清理和维护操作 — 使用diskmon cleanup和diskmon fix保存带时间戳的日志,记录在哪些系统上清理、释放或修复了哪些内容
- 基准测试存储性能 — 使用diskmon benchmark和diskmon compare记录I/O测试结果,比较不同磁盘或配置的性能
- 生成可审计的导出文件 — 使用diskmon export json生成所有记录的监控活动的结构化文件,用于容量规划、合规审查或团队交接
示例
记录扫描并查看历史
bash
记录扫描结果
diskmon scan /dev/sda1: 已用78%,剩余45GB
查看最近的扫描记录
diskmon scan
监控、告警和报告工作流程
bash
记录监控观察结果
diskmon monitor web-server-01 /var 使用率91% — 接近阈值
记录告警
diskmon alert 严重:prod-db-02上的/data使用率98%
生成报告条目
diskmon report 每周磁盘报告:3台服务器超过85%阈值
在所有条目中搜索
diskmon search prod-db
清理和修复追踪
bash
记录清理操作
diskmon cleanup 从app-server-03的/var/log中清理了15GB旧日志
记录修复操作
diskmon fix 将dev-server上的/home LVM卷扩展了20GB
查看最近活动
diskmon recent
导出和统计
bash
所有日志文件的汇总统计
diskmon stats
将所有内容导出为JSON
diskmon export json
导出为CSV用于电子表格分析
diskmon export csv
健康检查
diskmon status
备份、恢复和基准测试
bash
记录备份
diskmon backup 在UTC时间03:00对/data卷进行了快照
记录恢复测试
diskmon restore 已验证从snapshot-2025-03-15恢复/etc
记录基准测试结果
diskmon benchmark 顺序写入:/dev/nvme0n1上480 MB/s
比较两次基准测试运行
diskmon compare nvme0n1与sda:顺序写入480 MB/s对比210 MB/s
工作原理
DiskMon在单个Bash脚本中使用简单的case分发架构。每个命令映射到~/.local/share/diskmon/下的一个日志文件。当带参数调用时,输入内容会附加时间戳。当不带参数调用时,显示该日志的最后20行。stats命令汇总所有日志的条目数量,export将所有内容序列化为JSON、CSV或纯文本,search在所有日志文件中搜索指定词条。
支持
由BytesAgain提供 | bytesagain.com | hello@bytesagain.com