建议解析 Apache 日志以显示

发布于 2024-10-12 07:13:23 字数 354 浏览 2 评论 0原文

我只是想知道显示每月/每周“访客数量”图表的更好方法是什么。

1:编写一些函数来解析 apache 日志,然后返回一个数组并将其转换为图形。

2:cronjobs 在晚上运行并将日志文件插入 mysql 数据库,然后当“客户端”请求查看每月/每周的访问者图表时,将查询发送到 mysql 并返回图表。

对于#1,我首先认为这是一个好主意,但后来开始考虑服务器上的收费,而且似乎如果用户刷新页面,整个过程将在数据或多或少是数据时重新开始相同(浪费处理器/内存时间)

对于#2,我认为这是一个或两个更好的想法,但想知道是否有其他人做了类似的事情,如果是的话,效果如何。

任何建议将不胜感激。

谢谢。

I was just wondering what would be the better way to show a graph of '# of visitors' per month/week.

1: Write a few functions that go off and parse apaches logs then returns an array and converts it into a graph.

2: cronjobs run at night and insert the log files into a mysql db then when the 'client' requests to see a graph of the visitors per month/week, sends query to mysql and returns and graphs.

With #1 I first thought this would be a good idea but then began to think about the toll on the server plus it seems that if a user refreshed the page the whole process would start over when the data would more-or-less be the same(Wasting processor/memory time)

With #2, I think this is the better idea or the two but was wondering if anyone else did something similar and if so how did it go.

Any advise would be appreciated.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

难理解 2024-10-19 07:13:23

如果您手边有一个数据库,就没有理由不使用它。您可以解析脚本开始前一秒,存储该时间,然后从那里重新开始下一次循环。您可以让 cron 每分钟运行一次,这样对服务器的影响非常小。

此外,在 Python 和 Perl 等语言中,您可以在 readline() / readline 上运行无限循环,并且一旦存在,它将继续返回空字符串或网络行。每次看到空行时添加一个短暂的睡眠,您就可以对长期进程进行实时更新,而无需不断查找和解析的开销。当然,您可能希望有一个 cron 来测试它们是否还活着,如果没有则复活它们。

如果您愿意,我可以提供代码。

If you have a database handy, there's no reason not to use it. You can parse up to say, one second prior to start of script, store that time, and start again from there the next go-around. You can get the cron to run as quickly as every minute with very little server impact that way.

Further, in languages like Python and Perl, you can run an infinite loop on readline() / readline, and it will keep returning either an empty string or the net line as soon as one exists. Add a short sleep every time you see an empty line and you can have realtime updates with a long-lived process, without the overhead of constant seeks and parses. Naturally you might want to have a cron that tests if they're alive and revives them if not.

I can provide code if you like.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文