Exemple #1
0
        public static IList <IResourcePerformanceCounter> GetResourceCounters(this List <IPerformanceCountersByResource> to)
        {
            var res = new List <IResourcePerformanceCounter>();
            var performanceCountersByResources = to.Where(resource => !resource.IsDeleted && !string.IsNullOrEmpty(resource.CounterName));

            foreach (var resourcePerformanceCounter in performanceCountersByResources)
            {
                if (resourcePerformanceCounter.TotalErrors)
                {
                    var counter = new WarewolfNumberOfErrorsByResource(resourcePerformanceCounter.ResourceId, resourcePerformanceCounter.CounterName);
                    res.Add(counter);
                }
                if (resourcePerformanceCounter.AverageExecutionTime)
                {
                    var counter = new WarewolfAverageExecutionTimePerformanceCounterByResource(resourcePerformanceCounter.ResourceId, resourcePerformanceCounter.CounterName);
                    res.Add(counter);
                }
                if (resourcePerformanceCounter.ConcurrentRequests)
                {
                    var counter = new WarewolfCurrentExecutionsPerformanceCounterByResource(resourcePerformanceCounter.ResourceId, resourcePerformanceCounter.CounterName);
                    res.Add(counter);
                }
                if (resourcePerformanceCounter.RequestPerSecond)
                {
                    var counter = new WarewolfRequestsPerSecondPerformanceCounterByResource(resourcePerformanceCounter.ResourceId, resourcePerformanceCounter.CounterName);
                    res.Add(counter);
                }
            }
            return(res);
        }
Exemple #2
0
        public IResourcePerformanceCounter CreateCounter(Guid resourceId, WarewolfPerfCounterType type, string name)
        {
            if (GetCounter(resourceId, type) == EmptyCounter)
            {
                IResourcePerformanceCounter counter;
                switch (type)
                {
                case WarewolfPerfCounterType.ExecutionErrors:
                    counter = new WarewolfNumberOfErrorsByResource(resourceId, name);
                    break;

                case WarewolfPerfCounterType.AverageExecutionTime:
                    counter = new WarewolfAverageExecutionTimePerformanceCounterByResource(resourceId, name);
                    break;

                case WarewolfPerfCounterType.ConcurrentRequests:
                    counter = new WarewolfCurrentExecutionsPerformanceCounterByResource(resourceId, name);
                    break;

                case WarewolfPerfCounterType.RequestsPerSecond:
                    counter = new WarewolfRequestsPerSecondPerformanceCounterByResource(resourceId, name);
                    break;

                default:
                    return(new EmptyCounter());
                }

                _resourceCounters.Add(counter);
                _perf.Save(_resourceCounters, EnvironmentVariables.ServerResourcePerfmonSettingsFile);
                return(counter);
            }
            return((IResourcePerformanceCounter)GetCounter(resourceId, type).FromSafe());
        }
        public void WarewolfCurrentExecutionsPerformanceCounterByResource_Construct()
        {
            var mockPerformanceCounterFactory = new Mock <IRealPerformanceCounterFactory>();
            var performanceCounterFactory     = mockPerformanceCounterFactory.Object;
            var originalCounter         = new WarewolfCurrentExecutionsPerformanceCounterByResource(_resourceGuid, _categoryInstanceName, performanceCounterFactory);
            IPerformanceCounter counter = originalCounter;

            Assert.IsTrue(counter.IsActive);
            Assert.AreEqual(WarewolfPerfCounterType.ConcurrentRequests, counter.PerfCounterType);
            Assert.AreEqual(GlobalConstants.WarewolfServices, counter.Category);
            Assert.AreEqual(CounterName, counter.Name);
            Assert.AreEqual(_resourceGuid, originalCounter.ResourceId);
        }
        public void WarewolfCurrentExecutionsPerformanceCounterByResource_Setup_CreatesCounter()
        {
            var mockPerformanceCounterFactory = new Mock <IRealPerformanceCounterFactory>();
            var mockCounter = new Mock <IWarewolfPerformanceCounter>();

            mockPerformanceCounterFactory.Setup(o => o.New(GlobalConstants.WarewolfServices, CounterName, GlobalConstants.GlobalCounterName)).Returns(mockCounter.Object);
            var performanceCounterFactory = mockPerformanceCounterFactory.Object;
            IPerformanceCounter counter   = new WarewolfCurrentExecutionsPerformanceCounterByResource(_resourceGuid, _categoryInstanceName, performanceCounterFactory);

            counter.Setup();

            mockPerformanceCounterFactory.Verify(o => o.New(GlobalConstants.WarewolfServices, CounterName, GlobalConstants.GlobalCounterName), Times.Once);
        }
        public void WarewolfCurrentExecutionsPerformanceCounterByResource_CreationData_Valid()
        {
            var mockPerformanceCounterFactory = new Mock <IRealPerformanceCounterFactory>();
            var performanceCounterFactory     = mockPerformanceCounterFactory.Object;
            IPerformanceCounter counter       = new WarewolfCurrentExecutionsPerformanceCounterByResource(_resourceGuid, _categoryInstanceName, performanceCounterFactory);

            var data = counter.CreationData();

            Assert.AreEqual(1, data.Count());

            var dataItem = counter.CreationData().First();

            Assert.AreEqual("Concurrent requests currently executing", dataItem.CounterHelp);
            Assert.AreEqual(CounterName, dataItem.CounterName);
            Assert.AreEqual(PerformanceCounterType.NumberOfItems32, dataItem.CounterType);
        }
        public void WarewolfCurrentExecutionsPerformanceCounterByResource_Decrement_CallsUnderlyingCounter()
        {
            var mockPerformanceCounterFactory = new Mock <IRealPerformanceCounterFactory>();
            var mockCounter = new Mock <IWarewolfPerformanceCounter>();

            mockCounter.SetupGet(o => o.RawValue).Returns(1);
            mockPerformanceCounterFactory.Setup(o => o.New(GlobalConstants.WarewolfServices, CounterName, GlobalConstants.GlobalCounterName)).Returns(mockCounter.Object).Verifiable();
            var performanceCounterFactory = mockPerformanceCounterFactory.Object;
            IPerformanceCounter counter   = new WarewolfCurrentExecutionsPerformanceCounterByResource(_resourceGuid, _categoryInstanceName, performanceCounterFactory);

            counter.Setup();
            counter.Decrement();

            mockPerformanceCounterFactory.Verify();
            mockCounter.Verify(o => o.Decrement(), Times.Once);
        }