分类: LINUX
2008-03-03 22:05:08
Some filter functions accept regular expressions as parameters. But evaluating general regular expressions puts a high load on the CPU, which can cause problems when the message traffic is very high. Often the regular expression can be replaced with simple filter functions and logical operators. Using simple filters and logical operators, the same effect can be achieved at a much lower CPU load.
# 注释 :某些过滤器函数接受正则表达式作为参数,但使用正则表达式会增加 CPU 的开销。
# 对于常用的正则表达式,建议使用内置的过滤器函数和布尔操作符来代替,还可以降低 CPU 的开销。
Example 7.3. Optimizing regular expressions in filters | |
---|---|
Suppose you need a filter that matches the following error message logged by
the # 注释 :例如你想过滤出来自 NTP 服务的日志(xntpd 进程) xntpd[1567]: time error -1159.777379 is too large (set clock manually); The following filter uses regular expressions and matches every instance and variant of this message. # 注释:下面的例子使用 regexp filter f_demo_regexp { Segmenting the # 注释:但如果改为使用多个 match()函数也可以达到相同目的 filter f_demo_optimized_regexp { |