如何在 Apache 下运行的应用程序中保留动态应用程序级统计信息?
我有一个在 apache 下运行的应用程序,我想保留“当前”统计信息。我想让应用程序告诉我这样的事情:
- 每秒的请求数,按请求
- 延迟类型细分,通过 Thrift 向各种后端服务发出请求(按服务和服务器细分)
- 每秒处理的错误数
- 等。
我想要无需任何外部依赖即可执行此操作。但是,我遇到了在 apache 进程之间共享统计信息的问题。显然,我不能只使用全局内存。解决此类问题的好模式是什么?
该应用程序是使用 pylons 用 python 编写的,尽管我怀疑这更多的是“跨进程通信”设计问题,而不是 python 特定的问题。
I have an application running under apache that I want to keep "in the moment" statistics on. I want to have the application tell me things like:
- requests per second, broken down by types of request
- latency to make requests to various backend services via thrift (broken down by service and server)
- number of errors being served per second
- etc.
I want to do this without any external dependencies. However, I'm running into issues sharing statistics between apache processes. Obviously, I can't just use global memory. What is a good pattern for this sort of issue?
The application is written in python using pylons, though I suspect this is more of a "communication across processes" design question than something that's python specific.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许您可以将相关计数器和其他统计信息保存在所有 apache 进程都可以访问的 memcached 中?
Perhaps you could keep the relevant counters and other statistics in a memcached, that is accessed by all apache processes?
如果你的 apache 以某种方式死掉了怎么办?(关注点分离?)
我个人正在使用(冗余) Nagios 用于监控硬件本身、服务和应用程序指标。这样我就可以轻松/自动地绘制“每秒请求数/在线用户数”、“每秒 CPU 负载/用户活动 X”等图表,这对很多事情都有帮助。
为 nagios 编写插件非常容易,而且还有数千个任何语言的预制脚本。
Apache监控
我通过nagios插件从apache mod_status页面提取我需要的信息来监控apache。
插件响应示例:
APACHE OK - 0.080 秒。响应时间,繁忙/空闲 18/16,打开 766/800,ReqPerSec 12.4,BytesPerReq 3074,BytesPerSec 38034
应用程序监控
我使用 mod_status 只是作为您的列表的示例我想监控。
对于我们的应用程序,我们有一个非常小的 Nagios 插件框架,因此基本上每个 nagios 检查都是一个小类,它针对缓存或数据库运行检查并将其值返回给 nagios(小而简单的命令行脚本)。
更多示例:
我想说的是:扩展 Nagios 进行应用程序监控非常容易。
我的小框架花了我 3-4 个小时来编写,现在我添加的任何检查只需要几分钟。
Nagios 插件开发指南
What if your apache dies somehow? (Separation of concerns?)
Personally I am using (redundant) Nagios to monitor the hardware itself, services, and application metrics. This way i can easily/automatically plot "requests per second/users online", "cpu load/user activy X per second" etc. graphs which help with lots of things.
Writing plugins for nagios is really easy, also there are thousands of premade scripts in any language.
Apache monitoring
I am monitoring apache by extracting the information I need from the apache mod_status page via nagios plugin.
Example plugin response:
APACHE OK - 0.080 sec. response time, Busy/Idle 18/16, open 766/800, ReqPerSec 12.4, BytesPerReq 3074, BytesPerSec 38034
Application Monitoring
I used mod_status just as an example for your list of things you'd like to monitor.
For our application we have a very small framework for Nagios plugins, so basically every nagios check is a small class which runs its check against a cache or database and returns its value to nagios (small and simple commandline-script).
more examples:
What I want to say: Extending Nagios for application monitoring is very easy.
With my little framework which took me 3-4 hours to write, any check I am adding takes me just some minutes now.
Nagios plug-in development guidelines
使用 pylons.g 对象。它是 Pylons 应用程序的 lib/app_globals.py 文件中 Globals 类的实例。它的状态更改对所有线程都是可见的,因此其中的内容需要是线程安全的。
lib/app_globals.py:
控制器/status.py:
Use pylons.g object. It is an instance of Globals class in your Pylons application's lib/app_globals.py file. Its state changes will be visible to all threads, so stuff in it needs to be threadsafe.
lib/app_globals.py:
controllers/status.py: