0

我有几个在 IIS 7 上运行的负载平衡应用程序服务器。我需要检查每个服务器进行了多少 Web 服务调用。我还需要在特定情况下检查这一点。我们在 .net 中是否有一些东西可以与服务器通信并给我特定实例的快照。谢谢

4

2 回答 2

0

您可以使用 Perfmon 添加有关调用次数的统计信息。一旦你这样做了,你也可以添加计时数据......然后你可以在本地机器上使用 Perfmon 或使用任意数量的工具远程连接它。

抱歉,我无法指出具体细节——我只看到它完成了,我自己没有做过:) 但我认为这很简单。

于 2012-08-21T13:23:10.373 回答
0

还有一些示例代码,展示了如何实现性能计数器:

using System;
using System.Configuration;
using System.Diagnostics;
namespace TEST
{
    // sample implementation
    public static class PerformanceHelper
    {
        // update a performance counter value
        public static void UpdateCounter(string WebMethodName, int count)
        {
            // to be able to turn the monitoring on or off
            if (ConfigurationManager.AppSettings["PerformanceMonitor"].ToUpper() == "TRUE")
            {
                PerformanceCounter counter;
                if (!PerformanceCounterCategory.Exists("SAMPLE"))
                {
                    CounterCreationDataCollection listCounters = new CounterCreationDataCollection();
                    CounterCreationData newCounter = new CounterCreationData(WebMethodName, WebMethodName, PerformanceCounterType.NumberOfItems64);
                    listCounters.Add(newCounter);
                    PerformanceCounterCategory.Create("SAMPLE", "DESCRIPTION", new PerformanceCounterCategoryType(), listCounters);
                }
                else
                {
                    if (!PerformanceCounterCategory.CounterExists(WebMethodName, "SAMPLE"))
                    {
                        CounterCreationDataCollection rebuildCounterList = new CounterCreationDataCollection();
                        CounterCreationData newCounter = new CounterCreationData(WebMethodName, WebMethodName, PerformanceCounterType.NumberOfItems64);
                        rebuildCounterList.Add(newCounter);
                        PerformanceCounterCategory category = new PerformanceCounterCategory("SAMPLE");
                        foreach (var item in category.GetCounters())
                        {
                            CounterCreationData existingCounter = new CounterCreationData(item.CounterName, item.CounterName, item.CounterType);
                            rebuildCounterList.Add(existingCounter);
                        }
                        PerformanceCounterCategory.Delete("SAMPLE");
                        PerformanceCounterCategory.Create("SAMPLE", "DESCRIPTION", new PerformanceCounterCategoryType(), rebuildCounterList);
                    }
                }
                counter = new PerformanceCounter("SAMPLE", WebMethodName, false);
                if (count == -1)
                    counter.IncrementBy(-1);
                else
                    counter.IncrementBy(count);
            }
        }
    }
}
于 2012-08-21T13:40:57.737 回答