按照上一个问题grep if the next X lines doesn't contain a specific string 我希望得到帮助,以使awk更简单。
给出以下日志:
2018-04-04 04:37:41,916 [main] DEBUG com.zaxxer.hikari.HikariConfig - autoCommit......................true
2018-04-04 04:37:41,916 [main] DEBUG com.zaxxer.hikari.HikariConfig - catalog.........................null
2018-04-04 04:37:41,916 [main] DEBUG com.zaxxer.hikari.HikariConfig - connectionInitSql...............null
2018-04-04 04:37:41,916 [main] DEBUG com.zaxxer.hikari.HikariConfig - connectionTestQuery.............null
2018-04-04 04:48:43,209 [housekeeper] DEBUG com.zaxxer.hikari.pool.HikariPool - Before cleanup stats (total=13, active=2, idle=11, waiting=0)
2018-04-04 05:16:19,226 [housekeeper] DEBUG not-relevant...
2018-04-04 05:45:28,383 [housekeeper] WARN com.zaxxer.hikari.pool.ProxyLeakTask - Connection leak detection triggered for com.mysql.jdbc.JDBC4Connection@2f350071, stack trace follows
java.lang.Exception: Apparent connection leak detected
at com.sql.HikariConnectionPool.getConnection(java:)
at com.DBConnection.getConn(java:)
at com.DBConnection.getConn(java:)
at com.EAgent.checkER(aaa.java:)
at com.EAgent$EExecuter.run(aaa.java:)
2018-04-04 05:55:54,425 [housekeeper] DEBUG not-relevant...
2018-04-04 04:48:13,208 [housekeeper] DEBUG com.zaxxer.hikari.pool.HikariPool - Before cleanup stats (total=13, active=0, idle=13, waiting=0)
2018-04-04 04:48:13,208 [housekeeper] DEBUG com.zaxxer.hikari.pool.HikariPool - After cleanup stats (total=13, active=0, idle=13, waiting=0)
2018-04-04 05:58:16,814 [DBPool housekeeper] WARN com.zaxxer.hikari.pool.ProxyLeakTask - Connection leak detection triggered for com.mysql.jdbc.JDBC4Connection@45df031, stack trace follows
java.lang.Exception: Apparent connection leak detected
at com.HikariConnectionPool.getConnection(HikariConnectionPool.java:)
at com.DBConnection.getConn(aaa.java:)
at com.DBConnection.getConn(aaa.java:)
at com.m.checkUC(aaa.java:)
at com.m.run(aaa.java:)
at java.c.ThreadPoolExecutor.runWorker(aaa.java:)
at java.c.ThreadPoolExecutor$Worker.run(aaa.java:)
at java.lang.Thread.run(aaa.java:)
2018-04-04 04:37:41,921 [main] INFO com.zaxxer.hikari.HikariDataSource - Started.
2018-04-04 04:49:43,209 [housekeeper] DEBUG com.zaxxer.hikari.pool.HikariPool - Before cleanup stats (total=11, active=0, idle=11, waiting=0)
2018-04-04 04:49:43,209 [housekeeper] DEBUG com.zaxxer.hikari.pool.HikariPool - After cleanup stats (total=11, active=0, idle=11, waiting=0)
我喜欢按以下条件过滤的awk代码:
1.行以数字开头。
2.包含:"超时失败"或"连接泄漏检测"或者"警告"
3.不包含EAgent(排除 - 即使包含WARN或来自#2的其他术语)
通过这种方式,不需要在公式中添加INFO和DEBUG以及其他不相关的日志行 - 它将被自动忽略。
(只搜索我们需要的东西,而不是我们不需要的东西......)
输出应该只显示第二个WARN堆栈跟踪而没有" EAgent":
2018-04-04 05:58:16,814 [DBPool housekeeper] WARN com.zaxxer.hikari.pool.ProxyLeakTask - Connection leak detection triggered for com.mysql.jdbc.JDBC4Connection@45df031, stack trace follows
java.lang.Exception: Apparent connection leak detected
at com.HikariConnectionPool.getConnection(HikariConnectionPool.java:)
at com.DBConnection.getConn(aaa.java:)
at com.DBConnection.getConn(aaa.java:)
at com.m.checkUC(aaa.java:)
at com.m.run(aaa.java:)
at java.c.ThreadPoolExecutor.runWorker(aaa.java:)
at java.c.ThreadPoolExecutor$Worker.run(aaa.java:)
at java.lang.Thread.run(aaa.java:)
由于
答案 0 :(得分:1)
请您试着跟随并告诉我这是否对您有帮助。
~/.ssh/id_rsa.pub
现在也添加非单线形式的解决方案。
ssh -Tv git@gitlab.com
说明: 现在也要添加代码说明,以便全面了解和学习。
awk '{line=$0;gsub(/^ +/,"")} /^[0-9]+/{flag=""} /^[0-9]+/ && (/WARN/ || /Timeout failure/ || /Connection leak detection/){flag=1;if(val && val !~ /EAgent/){print val};val=""} flag{val=val?val ORS line:line} END{if(val){print val}}' Input_file