如何按时间聚合日志记录
我有一个巨大的日志文件,其中包含以时间戳为前缀的日志消息。时间戳的精度为微秒。我想找到记录最多消息数的 10 秒时间窗口。你怎么能这么做呢?
I have a huge log file containing log messages prefixed with timestamp. The timestamp is with the precision of microseconds. I want to find a 10 sec time window when highest number of messages were logged. How can you do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要逐行读取文件,找出每个时间戳所在的 10 秒周期,并跟踪哪个时间戳范围具有最大的“成员”计数。
您没有指定哪种语言,所以我只使用伪代码:
成员计数并启动新的间隔计数器
You'd need to slurp in the file line by line, figure out which 10s period each timestamp is in, and keep track of which timestamp range had the biggest "member" count.
You don't specify which language, so I'll just use pseudocode:
membership count and start a new interval counter
您可以首先将日志文件聚合为一秒的间隔,然后在这些数字中找到最高权重的序列。
You might first aggregate your log files into one second intervals, then find in these numbers the sequence of highest weight.