GeekIt

vegeta命令速查

安装与版本、目标文件构造、attack 参数、速率与并发、协议与 TLS、report 解读、plot/encode、CI 门禁与报错排查等 120 条命令

共 120 条命令 · 10 类场景 · 点击右侧图标可复制

命令 / 片段说明复制
vegeta -version查看版本,v12 起模块路径带 /v12
vegeta -h查看子命令与全局参数
vegeta attack -h查看 attack 的全部参数,版本差异以它为准确
go install github.com/tsenart/vegeta/v12@latestGo 环境安装,产物在 $GOPATH/bin
brew install vegetamacOS 安装
dnf install vegetaRHEL/Fedora 系安装
apt install vegetaDebian/Ubuntu,部分版本需自行加源
docker run --rm -i peterevans/vegeta sh -c "cat > /tmp/t.txt && vegeta attack -targets=/tmp/t.txt"容器运行,注意 stdin 与文件挂载方式
GOMAXPROCS=4 vegeta attack ...限制 Go 运行时使用的核数,避免压测机把 CPU 打满
vegeta 是恒定速率工具与 wrk2 同属开环,天然规避协调遗漏带来的乐观延迟
命令 / 片段说明复制
GET http://example.com/最小目标:方法 + 空格的 URL
GET http://example.com/ X-Env: test Authorization: Bearer xxx第一行后紧跟请求头,每行一个
POST http://example.com/api Content-Type: application/json @body.json@ 开头表示从文件读取请求体
GET http://example.com/a GET http://example.com/b空行分隔多个目标,vegeta 会轮询使用
POST http://example.com/api Content-Type: application/json {"k":"v"}请求体也可直接内联,但要注意 shell 与换行
echo "GET http://example.com/" | vegeta attack -duration=5s不写文件,直接用标准输入传单个目标
vegeta attack -targets=targets.txt ...最常用方式:把目标写进文件纳入版本管理
PUT http://example.com/item/1 Content-Type: application/json @put.jsonPUT 请求同样只改首行方法
DELETE http://example.com/item/1无请求体的方法直接一行即可
目标文件里不能有注释行写错格式会报 bad target,建议先用 1 个目标试跑
URL 必须是绝对地址缺 scheme 会解析失败
echo -n "GET http://example.com/" | vegeta attack -rate=10 -duration=5secho 记得 -n,避免多余换行影响解析
命令 / 片段说明复制
vegeta attack -targets=t.txt -rate=50 -duration=30s | vegeta report最经典的管道组合:压测并直接出报告
vegeta attack -targets=t.txt -duration=10s -output=results.bin结果写二进制文件,便于多次分析
vegeta attack -targets=t.txt -rate=100 -duration=30s | tee results.bin | vegeta report边压测边落盘,中断也保留已有结果
echo "GET http://example.com/" | vegeta attack -rate=5 -duration=5s | vegeta report一条命令完成冒烟,验证环境与参数
vegeta attack -targets=t.txt -rate=100 -duration=1m -name=api-v1给本次攻击命名,便于在报告中区分
vegeta attack -targets=t.txt -rate=0 -duration=30srate=0 让 vegeta 以最大能力发压(懒模式)
vegeta attack -targets=t.txt -rate=50 -duration=30s -lazy懒模式,不强求恒定速率,适合找最大吞吐
vegeta attack -targets=t.txt -rate=100 -duration=30s -header "X-Trace: bench"命令行追加请求头,会覆盖目标文件里的同名头
vegeta attack -targets=t.txt -body=payload.json -rate=20 -duration=10s统一替换请求体,配合简单目标文件使用
vegeta attack -targets=t.txt -rate=100 -duration=30s 2>/dev/null > results.bin分离日志与数据,结果文件更干净
attack 必须给 -duration 或持续有输入只给 duration 会按时长结束,不给则一直跑
命令 / 片段说明复制
-rate=100每秒 100 个请求,最简写法
-rate=100/1s显式指定时间单位,等价上一条
-rate=10/500ms每 500ms 发 10 个请求
-rate=5/1m低频场景,做长周期可用性验证
-workers=10并发 worker 数,决定能同时处理多少请求
-max-workers=100worker 上限,rate 高时自动扩容到该值
-connections=10000每个目标的空闲连接池上限
-timeout=5s单请求超时,慢接口要放宽
workers 要按 Little 定律估workers ≈ rate × 目标延迟(秒),给少了会拖慢实际速率
-keepalive=false关闭连接复用,测短连接与握手开销
-redirects=0不跟随重定向,避免把跳转耗时算进业务耗时
-max-body=0只读响应头不读 body,减少客户端开销
rate 越高越要核对实际速率看 report 里的 Rate 是否达到设定值,没达到说明客户端不够
命令 / 片段说明复制
vegeta attack -targets=https.txt -rate=50 -duration=10s目标写 https 地址即走 TLS
-insecure跳过证书校验,压自签或内网 HTTPS 必加
-root-certs=/etc/ssl/certs/ca.pem指定自建 CA 根证书,比 -insecure 更严谨
-cert=client.crt -key=client.keymTLS 双向认证场景
-http2启用 HTTP/2 压测
-format=http/2显式指定协议格式,等价于 -http2
-h2c明文 HTTP/2(h2c),内网 gRPC 前置网关常用
-resolvers=8.8.8.8:53指定 DNS 解析器,排除内网 DNS 干扰
-laddr=10.0.0.5绑定源地址,多网卡机器可分流
-unix-socket=/var/run/app.sock通过 unix socket 压测本机服务,绕过网络
-proxy-header="Proxy-Authorization: Basic xxx"走代理时补充代理认证头
HTTPS 场景先确认 ALPN用 openssl s_client -alpn h2 验证服务端是否真的支持 HTTP/2
命令 / 片段说明复制
vegeta report results.bin默认 text 报告,最常用
cat results.bin | vegeta report管道输入同样支持
Requests [total, rate, throughput]总请求数、目标速率与实际吞吐,三者对照看是否达成
Duration [total, attack, wait]总耗时、攻击时长与等待结果的时间
Latency [mean, 50, 90, 95, 99, max]延迟分位,长尾看 99 与 max
Bytes In / Bytes Out收发字节数,用于评估带宽占用
Success [ratio]成功率,低于预期先看 Status Codes 与 Errors
Status Codes [code:count]各状态码计数,快速识别 4xx/5xx 集中出现的原因
Errors [count]网络层错误汇总,常见 timeout、connection refused
vegeta report -type=json results.binJSON 输出,便于脚本断言与入库
vegeta report -type="hist[0,100ms,200ms,500ms]" results.bin直方图分桶,看延迟分布形态
vegeta report -every=1s results.bin流式输出周期报告,观察压测过程变化
vegeta report -type=json results.bin | jq .latency提取延迟对象,做门禁判断
throughput 明显低于 rate客户端 worker 不足或服务端处理不过来,先排查再采信延迟
命令 / 片段说明复制
vegeta plot results.bin > plot.html生成交互式 HTML 图表,直接发给同事
vegeta plot -title="api-v1 100rps" results.bin > plot.html给图表加标题,便于归档区分
vegeta plot -threshold=500ms results.bin > plot.html以延迟阈值着色,快速看超线比例
vegeta plot -downsampling-threshold=1000 results.bin > plot.html点数过多时先降采样,避免浏览器卡死
vegeta encode results.bin > results.json二进制结果转 JSON,默认 to=json
vegeta encode -to csv results.bin > results.csv转 CSV,方便 Excel 或 BI 分析
vegeta encode -to gob results.bin > results.gob转 gob,便于 Go 程序直接解码
vegeta encode results.json -to bin > results.bin反向转换,把文本结果还原为二进制
vegeta plot <(vegeta encode results.bin)管道方式喂 JSON 数据作图
报告产物与原始 bin 一起归档原始数据能重新出图,比只存截图更有价值
命令 / 片段说明复制
vegeta attack -targets=t.txt -rate=100 -duration=30s -output=results.bin标准做法:结果落盘再分析,避免管道丢失
vegeta report -type=json results.bin > report.jsonJSON 报告落盘,随构建产物归档
jq -e ".success > 0.99" report.json成功率门禁,不满足时 jq 返回非零
jq -e ".latency.p99 < 500" report.jsonP99 延迟门禁(单位纳秒,注意换算)
jq ".latency.p99 / 1000000" report.json纳秒转毫秒,避免误判数量级
jq -e ".throughput > 95" report.json吞吐下限门禁,防止压不出量也算通过
grep -E "Success|Latency" report.txt文本报告里快速提取关键行
vegeta attack ... | tee results.bin | vegeta report > report.txt一次运行同时保留数据与报告
set -o pipefail管道中任一段失败即整体失败,CI 里必加
把 rate、成功率、P99 写入构建摘要每次构建都能看到性能趋势
基线结果纳入版本库或对象存储便于回归对比与历史追溯
命令 / 片段说明复制
for r in 50 100 200 400; do vegeta attack -targets=t.txt -rate=$r -duration=30s -output=r$r.bin; done速率阶梯,逐级观察成功率与延迟拐点
vegeta report -every=5s results.bin长时压测中观察指标漂移,识别资源泄漏
低速率起步预热避开连接建立、缓存冷启动与 JIT 干扰
达成率优先于延迟throughput 明显低于 rate 时,延迟数字已失真
固定变量再对比版本、规格、缓存状态、网络路径都要记录
随机参数绕过缓存目标文件里写多个 URL 轮询,减少缓存命中
同时观察服务端 CPU 与连接数只看报告容易把客户端瓶颈当成服务端问题
多目标轮询更接近真实混合读写接口的比例要贴近线上流量模型
生产环境默认不压测必须压测时走审批、限流与回滚预案
结论要可复现同参数重跑一次,指标偏差应在可接受范围
命令 / 片段说明复制
vegeta: command not found未安装或 $GOPATH/bin 不在 PATH
bad target: ...目标文件格式错误,检查方法、空格与 URL scheme
no targets provided既没给 -targets 也没从 stdin 输入
unknown flag: -xxx参数名写错或当前版本不支持
x509: certificate signed by unknown authority自签证书加 -insecure 或指定 -root-certs
dial tcp 10.0.0.5:443: connect: connection refused端口未监听或被防火墙拦截
context deadline exceeded请求超时,调大 -timeout 并排查慢接口
unexpected EOFresults.bin 不完整,压测被中断或管道提前关闭
rate: parse error速率写法有误,正确格式为 100 或 100/1s
attack 卡住无输出从 stdin 读目标但没喂数据,补 echo 或 -targets
Success 随 rate 上升快速下降已过载,降低速率重新找拐点
Errors 中大量 timeout连接数或 worker 不足,也可能是服务端排队
Status Codes 集中 429触发限流,需与业务确认限流阈值后再压
plot 生成空白图数据点太少或时长为 0,延长 -duration 重跑
report 数值单位混乱JSON 里延迟是纳秒,展示前记得除以 1e6
压测机 CPU 100%客户端瓶颈,减少 worker、用 GOMAXPROCS 限制或多机分散
结果与网关统计不一致中间有 CDN、限流或采样,核对口径与时间窗

运维常用组合

快速冒烟echo -n "GET http://example.com/" | vegeta attack -rate=5 -duration=5s | vegeta report
标准压测流水线vegeta attack -targets=t.txt -rate=100 -duration=30s -output=results.bin → vegeta report results.bin → vegeta plot results.bin > plot.html
速率阶梯找容量for r in 50 100 200 400 800; do vegeta attack -targets=t.txt -rate=$r -duration=30s -output=r$r.bin; vegeta report r$r.bin | grep -E "Requests|Success|99"; done
CI 性能门禁vegeta attack -targets=t.txt -rate=100 -duration=30s -output=r.bin → report -type=json > report.json → jq -e ".success > 0.99 and (.latency.p99/1000000) < 500" report.json
HTTPS 与 HTTP/2vegeta attack -targets=https.txt -rate=100 -duration=30s -insecure -http2 -output=r.bin → report → plot
长短连接对比默认跑一轮 → 加 -keepalive=false 再跑一轮 → 对比 Latency mean 与 throughput,量化握手开销

实战要点

1. 恒定速率即开环

vegeta 按 -rate 匀速发压,不受响应快慢影响,延迟统计更接近真实

2. 先看 throughput

实际吞吐远低于目标 rate 时,延迟与成功率都不能作为容量结论

3. workers 按延迟估

workers ≈ rate × 目标延迟(秒),估小了会被客户端卡住

4. 结果先落盘再分析

用 -output 存 bin,失败中断也能保留已有数据并反复出报告

5. JSON 延迟是纳秒

门禁脚本里务必换算成毫秒,否则判断会差三个数量级

6. 目标文件纳入版本管理

压测目标和参数同样需要评审与追溯,避免"随手一压"

共 120 条 vegeta 命令 · 示例中的域名、速率与文件路径请替换为实际环境

关于vegeta命令速查

在线 vegeta 命令速查手册,按安装与版本、目标文件与请求构造、attack 基础用法、速率与并发控制、协议 TLS 与网络选项、report 结果解读、plot 与 encode、输出采集与 CI 集成、压测方法与容量评估、常见报错与排查等 10 类场景整理 120 条常用命令与参数组合,每条附中文说明与可直接复制的写法,支持关键词搜索、分类折叠和一键复制,打开网页即可查阅。涵盖 go install github.com/tsenart/vegeta/v12@latest 与 brew/dnf/docker 安装、vegeta -version、targets 文件格式(METHOD URL、请求头、@body 文件、空行分隔多个目标)、attack 的 -targets 与 -rate 与 -duration 与 -output 与 -name 与 -workers 与 -max-workers 与 -connections 与 -timeout 与 -lazy 与 -keepalive 与 -redirects 与 -max-body 与 -header 与 -body 与 -cert/-key/-root-certs 与 -insecure 与 -http2/-format=http/2/-h2c 与 -resolvers 与 -laddr 与 -unix-socket、速率写法 50、100/1s、10/500ms 与 rate=0 懒模式、report 的 -type=text|json|hist[0,100ms,10ms] 与 -every 1s 流式输出与 Latency 的 mean/50/90/95/99/max 与 Success 与 Status Codes 与 Errors 与 Bytes In/Out 与 Throughput 逐项含义、plot 生成 HTML 图与 -threshold/-downsampling-threshold、encode 的 -to json|csv|gob 格式转换,以及 grep/jq 提取成功率达到 CI 门禁、结果文件归档与基线对比,还有 command not found、bad target、no targets provided、unknown flag、x509 certificate signed by unknown authority(-insecure)、connection refused、context deadline exceeded、unexpected EOF(结果文件不完整)、rate 解析失败、stdin 无数据挂起、高 rate 下 Success 下降等报错排查。适用于恒定到达率接口压测、SLA 与容量验证、压测结果可视化与回归对比、CI 性能门禁、HTTPS 与 HTTP/2 场景测试,以及运维、测试与后端工程师面试复习。

核心能力

  • 涵盖 go install github.com/tsenart/vegeta/v12@latest 与 brew/dnf/docker 安装、vegeta -version、targets 文件格式(METHOD URL、请求头、@body 文件、空行分隔多个目标)、attack 的 -targets 与 -rate 与 -duration 与 -output 与 -name 与 -workers 与 -max-workers 与 -connections 与 -timeout 与 -lazy 与 -keepalive 与 -redirects 与 -max-body 与 -header 与 -body 与 -cert/-key/-root-certs 与 -insecure 与 -http2/-format=http/2/-h2c 与 -resolvers 与 -laddr 与 -unix-socket、速率写法 50、100/1s、10/500ms 与 rate=0 懒模式、report 的 -type=text|json|hist[0,100ms,10ms] 与 -every 1s 流式输出与 Latency 的 mean/50/90/95/99/max 与 Success 与 Status Codes 与 Errors 与 Bytes In/Out 与 Throughput 逐项含义、plot 生成 HTML 图与 -threshold/-downsampling-threshold、encode 的 -to json|csv|gob 格式转换,以及 grep/jq 提取成功率达到 CI 门禁、结果文件归档与基线对比,还有 command not found、bad target、no targets provided、unknown flag、x509 certificate signed by unknown authority(-insecure)、connection refused、context deadline exceeded、unexpected EOF(结果文件不完整)、rate 解析失败、stdin 无数据挂起、高 rate 下 Success 下降等报错排查

适用场景

适用于恒定到达率接口压测、SLA 与容量验证、压测结果可视化与回归对比、CI 性能门禁、HTTPS 与 HTTP/2 场景测试,以及运维、测试与后端工程师面试复习。vegeta命令速查全程在浏览器中完成,无需安装插件,可放心用于日常办公与排障。

常见问题

vegeta命令速查是免费的吗?需要注册或安装吗?
vegeta命令速查完全免费,无需注册、无需下载安装任何软件,用浏览器打开网页即可直接使用,也不限制使用次数。
vegeta命令速查支持哪些功能?
涵盖 go install github.com/tsenart/vegeta/v12@latest 与 brew/dnf/docker 安装、vegeta -version、targets 文件格式(METHOD URL、请求头、@body 文件、空行分隔多个目标)、attack 的 -targets 与 -rate 与 -duration 与 -output 与 -name 与 -workers 与 -max-workers 与 -connections 与 -timeout 与 -lazy 与 -keepalive 与 -redirects 与 -max-body 与 -header 与 -body 与 -cert/-key/-root-certs 与 -insecure 与 -http2/-format=http/2/-h2c 与 -resolvers 与 -laddr 与 -unix-socket、速率写法 50、100/1s、10/500ms 与 rate=0 懒模式、report 的 -type=text|json|hist[0,100ms,10ms] 与 -every 1s 流式输出与 Latency 的 mean/50/90/95/99/max 与 Success 与 Status Codes 与 Errors 与 Bytes In/Out 与 Throughput 逐项含义、plot 生成 HTML 图与 -threshold/-downsampling-threshold、encode 的 -to json|csv|gob 格式转换,以及 grep/jq 提取成功率达到 CI 门禁、结果文件归档与基线对比,还有 command not found、bad target、no targets provided、unknown flag、x509 certificate signed by unknown authority(-insecure)、connection refused、context deadline exceeded、unexpected EOF(结果文件不完整)、rate 解析失败、stdin 无数据挂起、高 rate 下 Success 下降等报错排查。
vegeta命令速查适合哪些场景使用?
适用于恒定到达率接口压测、SLA 与容量验证、压测结果可视化与回归对比、CI 性能门禁、HTTPS 与 HTTP/2 场景测试,以及运维、测试与后端工程师面试复习。