grep command in Linux to search for logs. In complex service systems, logs are scattered on different servers, CLI operations are not intuitive, and server permission management is restricted. As a result, it is difficult to find logs, which seriously affects Ops efficiency. It's even more difficult if you need to do some statistical analysis or monitor alarms based on logs.grep command to CLS to obtain the following advantages:10.20.20.10 ::: [Tue Jan 22 14:49:45 CST 2019 +0800] ::: GET /online/sample HTTP/1.1 ::: 127.0.0.1 ::: 200 ::: 647 ::: 35 ::: http://127.0.0.1/
::: to split the log into eight fields and name each field as follows:IP: 10.20.20.10bytes: 35host: 127.0.0.1length: 647referer: http://127.0.0.1/request: GET /online/sample HTTP/1.1status: 200time: [Tue Jan 22 14:49:45 CST 2019 +0800]
grep command as an example to describe how to achieve a similar log search feature in CLS.10.20.20.10 ::: [Tue Jan 22 14:49:45 CST 2019 +0800] ::: GET /online/sample HTTP/1.1 ::: 127.0.0.1 ::: 200 ::: 647 ::: 35 ::: http://127.0.0.1/
IP: 10.20.20.10bytes: 35host: 127.0.0.1length: 647referer: http://127.0.0.1/request: GET /online/sample HTTP/1.1status: 200time: [Tue Jan 22 14:49:45 CST 2019 +0800]
request is /online/sample.grep command# grep "/online/sample" test.log
request:"/online/sample"
status (status code) is not 200.grep command# grep -v "200" test.log
status is not 200.NOT status:200
status is greater than or equal to 500 as follows:status:>=500
status is not 200.grep command# grep -c -v "200" test.log
NOT status:200 | select count(*) as errorLogCounts
status is 200 and request is /online/sample.grep command# grep "200" test.log | grep "/online/sample"
status:200 AND request:"/online/sample"
request is /online/sample or /offline/sample.grep command# grep -E "/online/sample|/offline/sample" test.log
request:"/online/sample" OR request:"/offline/sample"
request is /online/sample but the log file is not test.log.grep command# grep -rn "/online/sample" --exclude=test.log
request:"/online/sample" AND NOT __FILENAME__:"test.log"
time is [Tue Jan 22 14:49:45 CST 2019 +0800].grep command# grep "[Tue Jan 22 14:49:45 CST 2019 +0800]" -B 10 test.log
time:"[Tue Jan 22 14:49:45 CST 2019 +0800]"
Was this page helpful?
You can also Contact sales or Submit a Ticket for help.
Help us improve! Rate your documentation experience in 5 mins.
Feedback