Get the App
SLTechnology News&Howtos  ›  Servers  › 

Shell solves the problem of Redis Slow Log weight removal

Shulou Source: shulou.com Published: 2022-06-02 05:41:25 10月01日 Update

The old employer monitors the slow query log of Redis, uses Crontab to sample the slow query log at regular intervals, and then writes a text file.

So there are many duplicate slow query logs in the text file.

How to deduplicate the whole paragraph of repeated slow query logs?

The way to use the Shell command is the simplest and most straightforward.

Awk'/ ^ 1\) / {print sscatter = ""}; {s "" $0)}; END {print s} 'b.txt | sort | uniq | sed's / /\ n / g' | awk'/ ^ 1\)\ (integer\) / {rc = rc+1;rowdata=rc ")\ t" $1 "" $2 "$3"\ n\ t "4" $5 "$6" $7 "\ n\ t" $8 "$9" $10 " Print rowdata}; / ^ / {print "\ t" $0} END {print "No duplicate logs Total:" rc}'

The core is to merge the entire paragraph of redis logs into one line, remove the duplicates, and restore the format.

Here are the attachments for testing

RedisSlowLog.txt

With Wang Gong's description and explanation of the demand for this problem.

Https://blog.csdn.net/wzy0623/article/details/83652539?tdsourcetag=s_pcqq_aiomsg

Tags: Logs queries files text questions one line owner command that is total mode time core format attachment requirements Wang Gong testing monitoring Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Shulou Information Redmi Huawei Apple