Gor is a simple http traffic replication tool written in Go.
Its main goal is to replay traffic from production servers to staging and dev environments.
-cpuprofile string write cpu profile to file -debug verbose 打开debug模式,显示所有接口的流量 -http-allow-header value 用一个正则表达式来匹配http头部,如果请求的头部没有匹配上,则被拒绝 gor --input-raw :8080 --output-http staging.com --http-allow-header api-version:^v1 (default []) -http-allow-method value 类似于一个白名单机制来允许通过的http请求方法,除此之外的方法都被拒绝. gor --input-raw :8080 --output-http staging.com --http-allow-method GET --http-allow-method OPTIONS (default []) -http-allow-url value 一个正则表达式用来匹配url, 用来过滤完全匹配的的url,在此之外的都被过滤掉 gor --input-raw :8080 --output-http staging.com --http-allow-url ^www. (default []) -http-disallow-header value 用一个正则表达式来匹配http头部,匹配到的请求会被拒绝掉 gor --input-raw :8080 --output-http staging.com --http-disallow-header "User-Agent: Replayed by Gor" (default []) -http-disallow-url value 用一个正则表达式来匹配url,如果请求匹配上了,则会被拒绝 gor --input-raw :8080 --output-http staging.com --http-disallow-url ^www. (default []) -http-header-limiter value 读取请求,基于FNV32-1A散列来拒绝一定比例的特殊请求 gor --input-raw :8080 --output-http staging.com --http-header-imiter user-id:25% (default []) -http-original-host 在--output-http的输出中,通常gor会使用取代请求的http头,所以应该禁用该选项,保留原始的主机头 -http-param-limiter value Takes a fraction of requests, consistently taking or rejecting a request based on the FNV32-1A hash of a specific GET param: gor --input-raw :8080 --output-http staging.com --http-param-limiter user_id:25% (default []) -http-rewrite-url value Rewrite the request url based on a mapping: gor --input-raw :8080 --output-http staging.com --http-rewrite-url /v1/user/([^\/]+)/ping:/v2/user/$1/ping (default []) -http-set-header value Inject additional headers to http reqest: gor --input-raw :8080 --output-http staging.com --http-set-header 'User-Agent: Gor' (default []) -http-set-param value Set request url param, if param already exists it will be overwritten: gor --input-raw :8080 --output-http staging.com --http-set-param api_key=1 (default []) -input-dummy value Used for testing outputs. Emits 'Get /' request every 1s (default []) -input-file value 从一个文件中读取请求 gor --input-file ./requests.gor --output-http staging.com (default []) -input-http value 从一个http接口读取请求 # Listen for http on 9000 gor --input-http :9000 --output-http staging.com (default []) -input-raw value Capture traffic from given port (use RAW sockets and require *sudo* access): # Capture traffic from 8080 port gor --input-raw :8080 --output-http staging.com (default []) -input-tcp value 用来在多个gor之间流转流量 # Receive requests from other Gor instances on 28020 port, and redirect output to staging gor --input-tcp :28020 --output-http staging.com (default []) -memprofile string write memory profile to this file -middleware string Used for modifying traffic using external command -output-dummy value 用来测试输入,打印出接收的数据. (default []) -output-file value 把进入的请求写入一个文件中 gor --input-raw :80 --output-file ./requests.gor (default []) -output-http value 转发进入的请求到一个http地址上 # Redirect all incoming requests to staging.com address gor --input-raw :80 --output-http http://staging.com (default []) -output-http-elasticsearch string 把请求和响应状态发送到ElasticSearch: gor --input-raw :8080 --output-http staging.com --output-http-elasticsearch 'es_host:api_port/index_name' -output-http-redirects int 设置多少次重定向被允许 -output-http-stats 每5秒钟输出一次输出队列的状态 -output-http-timeout duration 指定http的request/response超时时间,默认是5秒 -output-http-workers int gor默认是动态的扩展工作者数量,你也可以指定固定数量的工作者 -output-tcp value 用来在多个gor之间流转流量 # Listen for requests on 80 port and forward them to other Gor instance on 28020 port gor --input-raw :80 --output-tcp replay.local:28020 (default []) -output-tcp-stats 每5秒钟报告一次tcp输出队列的状态 -split-output true By default each output gets same traffic. If set to true it splits traffic equally among all outputs. -stats 打开输出队列的状态 -verbose Turn on more verbose output
Gor常用命令
简单的HTTP流量复制
1
$ gor --input-raw :80 --output-http "http://staging.com"
HTTP流量复制频率控制(获取每秒超过10个请求)
1
$ gor --input-tcp :28020 --output-http "http://staging.com|10"
HTTP流量复制缩小
1
$ gor --input-raw :80 --output-tcp "replay.local:28020|10%"
HTTP流量记录到本地文件
1
$ gor --input-raw :80 --output-file requests.gor
HTTP流量回放和压测
1
$ gor --input-file "requests.gor|200%" --output-http "staging.com"
HTTP流量过滤复制
1
$ gor --input-raw :8080 --output-http staging.com --output-http-url-regexp ^www.
自定义一些流量复制的参数
1
$ gor --input-raw :80 --output-http 192.168.2.6:8000 --http-allow-method POST --http-set-header 'User-Agent: Gor' -output-http-workers=1 -http-allow-url test.php
将流量复制两份到不同的测试服务
1
$ gor --input-tcp :28020 --output-http "http://staging.com" --output-http "http://dev.com"
将流量像负载均衡一样分配到不同的服务器
1
$ gor --input-tcp :28020 --output-http "http://staging.com" --output-http "http://dev.com" --split-output true