Tail 读取不断增长的动态文件并提取两列,然后打印图表
读取 1 GB 文件(其中记录了时间序列数据)并生成包含两列(一个是时间,另一个是数字)的实时图表的最佳方法是什么?我发现您有不同的方式来调整文件。
What is the best way to read a 1 GB file that gets time series data logged in it and generate a real time graph with two of its columns (one time and other a number)? I see that you have different ways of tailign the file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
听起来对于 RRDTool 来说是一份不错的工作。
但如果你想坚持使用 Python,我会使用 tail 将数据流式传输到我的程序中(这是假设文件被连续写入,否则 Python 中的直接 open() 就可以了)。
myprogram.py 可能类似于:
Sounds like a good job for RRDTool.
But if you want to stick with Python, I would use tail to stream the data into my program (this is assuming the file is continuously written to, otherwise a straight open() in Python will work).
myprogram.py could look something like:
这是 unix 管道,它有 3 个部分:tail'er、过滤器 (gawk) 和绘图仪 (python)。
这是 python 脚本。您可以向其提供 1 (y) 或 2 (xy) 列数据。如果您不使用 gawk,请务必弄清楚如何禁用缓冲。例如
sed -u
。Here's the unix pipe which has 3 parts: the tail'er, the filter (gawk), and the plotter (python).
and here is the python script. You can feed it 1 (y) or 2 (x y) columns of data. If you don't use
gawk
, be sure to figure out how to disable buffering.sed -u
for example.正如约翰提到的,您可以将尾部输出输入到您的文件中,但是如果您由于某种原因想要处理文件中的所有内容,并且还想要一个有点动态图的示例,这里是
您可以从中选取元素,我认为它会解决你的问题。
As John mentioned, you can input the tail output into your file, but if you due to some reason wants to handle everything in your file and also want an example of somewhat dynamic graph, here it is
You can pickup elements from it and I think it will solve your problem.