4

我正在寻找可以以编程方式检查的指标,这些指标暗示我的应用程序即将失败。我正在寻找诸如“可用 IO 线程数非常低”、“应用程序池可用内存低”和“处理器使用率高”之类的一般信息。

这适用于 C#/asp.net 和 IIS。

以编程方式检查值的示例很好,但不是必需的。欢迎任何好的想法。

4

5 回答 5

2

您可以以编程方式访问某些内置系统性能计数器的值。如果您需要更具体的详细信息,您也可以构建自己的计数器进行查询。

这是一篇让您入门的文章: 如何以编程方式计算 CPU 使用率

于 2010-06-24T16:58:24.057 回答
2

我的想法:

确定 webapp 的性能输入和输出。

  • 输入(用户数量、用户正在执行的任务、一天中的时间等)
  • 输出(内存使用、线程、滞后)

在真实请求数据下分析您的应用程序。建立一个很好的输入表及其相关输出。例如:

4 users calling page1 -> costs 4   - 6   mb, 4 threads
5 users calling page1 -> costs 7   - 14  mb, 5 threads
2 users calling page2 -> costs 120 - 200 mb, 1 thread

查找经常导致失败的输出并找出导致这些输出的输入。建立一个很好的最大似然失败模型。

当您的输入开始接近您的失败输出时,即将发生的失败很有可能发生。记录故障发生和不发生的时间,并将此信息反馈到您的表格中。您的 webapp 将在即将失败时学习。

更新以回应评论:

找到输出是最简单的部分。

请参阅 SO 问题How to get memory used in c#How to get the cpu usage in C#以及更一般的问题What key performance monitor should I watch for asp.net application

这些问题的要点:

  • GC.GetTotalMemory - 告诉你垃圾收集器分配了多少。

  • 处理器对象- 告诉您关于 cpu 的各种有趣的性能统计信息(cpu 空闲时间、使用情况等)。

于 2010-06-24T17:11:00.423 回答
2

几年前,我实际上有一份工作试图解决这个问题。事实证明,这是一项非常非常困难的工作——如今,您甚至无法信任操作系统,因此在 .net 沙箱中运行几乎不可能确定真正发生了什么。

Here are just a few simple situations you may want to take into consideration if you do decide to go ahead with this.

CPU - you may be able to determine the current CPU usage, but how do you tell if your particular instance has been bound to one CPU? How do you determine if you're running in a cluster, or what the other cores might be doing? You may be running inside a virtual machine with CPU or threads limited - those limits may be changed on the fly.

Memory - what if you're running inside a virtualized instance? What if suddenly an external change is make to increase or reduce the amount of memory available?

于 2010-06-24T17:27:30.727 回答
0

听起来您对失败的外部原因更感兴趣,而不是应用程序本身失败。我认为您正在尝试在这里进行系统性任务;与其尝试猜测可能的故障因素,不如专注于配置您的工作进程以缓解任何这些问题。IIS 工作进程具有很强的弹性 - 检查 ping、回收等功能。

于 2010-06-24T16:53:48.490 回答
0

也许不是程序化的,但记录你必须执行的支持小时数或加班时间以防止它跌倒可能是一个很好的指标。:-)

于 2010-06-24T16:54:29.587 回答