Web服务性能

时间:2012-08-21 13:03:13

标签: c# .net

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

2 个答案:

答案 0 :(得分:0)

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

抱歉,我不能指出你的具体情况 - 我只是看到它已经完成,而不是自己完成:)但我认为这很简单。

答案 1 :(得分: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);
            }
        }
    }
}