我希望Logstash在处理输入条目时简单地删除超过N天的条目.
我知道进行日期级别比较的唯一方法是通过Ruby代码.您需要date过滤器来解析时间戳(这是它自己的问题).
将日期解析为字段(例如event["@timestamp"])后,您可以使用它来确定是否要忽略它:
5.0:
ruby {
code => "event.cancel if (Time.now.to_f - event.get('@timestamp').to_f) > (60 * 60 * 24 * 5)"
}
Run Code Online (Sandbox Code Playgroud)
预5.x的:
ruby {
code => "event.cancel if (Time.now.to_f - event['@timestamp'].to_f) > (60 * 60 * 24 * 5)"
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,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 { }
}
Run Code Online (Sandbox Code Playgroud)
预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 { }
}
Run Code Online (Sandbox Code Playgroud)
使用这种方法,您将进行索引lag_seconds,这是一个小数量,从而允许您分析索引中的滞后,如果它进入ES或其他一些数据存储.
| 归档时间: |
|
| 查看次数: |
2274 次 |
| 最近记录: |