2016-11-07 5 views
2

를 제공합니다 여기서 쟁점이 될 수있는 일을 도와 주시겠습니까? 명령의내가 varnishlog 명령을 사용하고 일부 필드를 필터링하기 위해 노력하고 빈 결과

샘플 출력 : sudo varnishlog -c

* <<Request>> 658516 
- Begin   req 658515 rxreq 
- Timestamp  Start: 1478508065.780332 0.000000 0.000000 
- Timestamp  Req: 1478508065.780332 0.000000 0.000000 
- ReqStart  10.56.36.2 55578 
- ReqMethod  GET 
- ReqURL   /sample/2 
- ReqProtocol HTTP/1.1 
- ReqHeader  Host: localhost:6081 
- ReqHeader  User-Agent: Mozilla/5.0 Firefox/44.0 
- ReqHeader  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
- ReqHeader  Accept-Language: en-US,en;q=0.5 
- ReqHeader  Accept-Encoding: gzip, deflate 
- ReqHeader  Connection: keep-alive 
- ReqHeader  Pragma: no-cache 
- ReqHeader  Cache-Control: no-cache 
- VCL_call  RECV 
- VCL_return  hash 
- ReqUnset  Accept-Encoding: gzip, deflate 
- ReqHeader  Accept-Encoding: gzip 
- VCL_call  HASH 
- VCL_return  lookup 
- Hit   658416 
- VCL_call  HIT 
- VCL_return  deliver 
- RespProtocol HTTP/1.1 
- RespStatus  200 
- RespReason  OK 
- RespHeader  Content-Length: 4774 
- RespHeader  Last-Modified: Tue, 12 Apr 2016 17:42:58 GMT 
- RespHeader  Etag: f9d34a65e8c1b30245c2f12534348ff9 
- RespHeader  X-Timestamp: 1460482977.61998 
- RespHeader  Content-Type: image/png 
- RespHeader  X-Trans-Id: txf52283ea65004e578ddfe-0058203d84 
- RespHeader  Date: Mon, 07 Nov 2016 08:38:28 GMT 
- RespHeader  X-Varnish: 658516 658416 
- RespHeader  Age: 157 
- RespHeader  Via: 1.1 varnish-v4 
- VCL_call  DELIVER 
- RespHeader  X-Varnish-Cache: HIT 
- VCL_return  deliver 
- Timestamp  Process: 1478508065.780379 0.000047 0.000047 
- RespHeader  Accept-Ranges: bytes 
- Debug   "RES_MODE 2" 
- RespHeader  Connection: keep-alive 
- Timestamp  Resp: 1478508065.780411 0.000079 0.000032 
- ReqAcct  415 0 415 393 4774 5167 
+0

첫 번째 grep 패턴을 괄호로 묶으려고합니다. 이렇게 : '(ReqURL | Varnish-Cache)'. 또한 UNIX 버전 및 varnishlog -c 출력의 일부가 매우 유용합니다 – sotona

+0

-u 버퍼링되지 않은 출력을 시도 할 수 있습니까? varnishlog -cu처럼 ... –

+0

@sotona, 대괄호를 사용하여 시도했지만 같은 문제가 발생했습니다. 내 게시물을 명령의 샘플 출력으로 업데이트했습니다. – user3181365

답변

3

당신이 아래 그렙와 --line 버퍼 옵션을 사용할 수 있습니다;

sudo varnishlog -c | grep --line-buffered -E 'ReqURL|Varnish-Cache' | grep --line-buffered 'HIT' 

man grep;

- 라인 버퍼 출력시 라인 버퍼링을 사용하십시오. 이로 인해 성능이 저하 될 수 있습니다.

+0

다른 제 게시글을 확인해 주시겠습니까? http://stackoverflow.com/questions/40462153/grep-multiple-strings-and-then-replace-text 답변은 비슷한 문제가있는 Inian에 의해 주어졌지만 사용 된 명령은' awk '와'sed'와 wile 루프 – user3181365