Example #1
0
        public void InvalidSystemResponse()
        {
            var conf = new AgentCheckConfig
            {
                CpuLimit            = 80,
                IisRequestsLimit    = 42,
                RefreshIntervalInMs = 2000,
                SystemResponse      = (SystemResponse)(-1)
            };

            Assert.Throws <AgentCheckConfigurationException>(() =>
            {
                ValidationExtensions.CheckConfig(conf);
            });
        }
        internal static int ComputeWeight(State state, AgentCheckConfig config)
        {
            int weightCpu          = WeightResponse(state.CpuPercent, config.CpuLimit, config.SystemResponse);
            int weightRequestLimit = WeightResponse(state.IisRequests, config.IisRequestsLimit, config.SystemResponse);
            int weight             = Math.Min(weightCpu, weightRequestLimit);

            if (weight <= 0)
            {
                weight = 1; // security to avoid full drain mode
            }
            if (weight > 100)
            {
                weight = 100; // security to avoid over allocation
            }
            return(weight);
        }
Example #3
0
        public void BoundedWeight(int inputValue, int maxValue, int expected)
        {
            var state = new State
            {
                CpuPercent  = inputValue,
                IisRequests = inputValue,
            };
            var config = new AgentCheckConfig
            {
                CpuLimit         = maxValue,
                IisRequestsLimit = maxValue
            };

            foreach (var systemResponse in Enum.GetValues(typeof(SystemResponse)).OfType <SystemResponse>())
            {
                config.SystemResponse = systemResponse;
                var computed = StateProjection.ComputeWeight(state, config);
                Assert.Equal(expected, computed);
            }
        }
Example #4
0
        public void CpuLimit()
        {
            var conf = new AgentCheckConfig
            {
                IisRequestsLimit    = 42,
                RefreshIntervalInMs = 2000
            };

            Assert.Throws <AgentCheckConfigurationException>(() =>
            {
                conf.CpuLimit = 0;
                ValidationExtensions.CheckConfig(conf);
            });
            Assert.Throws <AgentCheckConfigurationException>(() =>
            {
                conf.CpuLimit = 101;
                ValidationExtensions.CheckConfig(conf);
            });
            conf.CpuLimit = 42;
            ValidationExtensions.CheckConfig(conf);
        }
Example #5
0
        public void IntervalLimit()
        {
            var conf = new AgentCheckConfig
            {
                CpuLimit         = 80,
                IisRequestsLimit = 42
            };

            Assert.Throws <AgentCheckConfigurationException>(() =>
            {
                conf.RefreshIntervalInMs = -1;
                ValidationExtensions.CheckConfig(conf);
            });
            Assert.Throws <AgentCheckConfigurationException>(() =>
            {
                conf.RefreshIntervalInMs = 0;
                ValidationExtensions.CheckConfig(conf);
            });
            conf.RefreshIntervalInMs = 2000;
            ValidationExtensions.CheckConfig(conf);
        }