我知道进行日期级别比较的唯一方法是通过Ruby代码。您需要date
过滤器来解析时间戳(这是它自己的问题)。
将日期解析到一个字段(例如event["@timestamp"]
)后,即可使用它来确定是否要忽略它:
5.0:
ruby {
code => "event.cancel if (Time.now.to_f - event.get('@timestamp').to_f) > (60 * 60 * 24 * 5)"
}
5.x之前的版本:
ruby {
code => "event.cancel if (Time.now.to_f - event['@timestamp'].to_f) > (60 * 60 * 24 * 5)"
}
在这种情况下,5
是N
。
另外,值得指出的是,这与Logstash恰好在运行的机器时间有关。如果不正确,则会影响日期数学。同样,如果源计算机的系统时钟错误,也可能是一个问题。
利用Alain的优点,您可以使用该存储区的滞后时间,除了基于它进行删除之外。
5.0:
ruby {
code => "event.set('lag_seconds', Time.now.to_f - event.get('@timestamp').to_f))"
}
# 5 represents the number of days to allow
if [lag_seconds] > (60 * 60 * 24 * 5) {
drop { }
}
5.x之前的版本:
ruby {
code => "event['lag_seconds'] = Time.now.to_f - event['@timestamp'].to_f)"
}
# 5 represents the number of days to allow
if [lag_seconds] > (60 * 60 * 24 * 5) {
drop { }
}
使用这种方法,您便可以建立索引lag_seconds
,这是一个小数,从而可以分析索引中的滞后(如果该滞后进入ES或其他数据存储)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句