Exemple #1
0
        public bool IsHealthy()
        {
            var stopwatch = new Stopwatch();

            const string key = "nginx-request";

            bool requestIsHealthy = false;

            try
            {
                stopwatch.Start();

                var httpClient = _httpClientFactory.CreateClient("nginx-api");

                var response = httpClient.GetAsync(_settings.Url).GetAwaiter().GetResult();

                stopwatch.Stop();

                requestIsHealthy = response.IsSuccessStatusCode &&
                                   _settings.ExpectedResponseTimeInMilliSecond > stopwatch.ElapsedMilliseconds;
            }
            catch (System.Exception)
            {
                requestIsHealthy = false;
            }

            _healthyStore.AddHealthyStatus(key, requestIsHealthy);

            var isUnhealty = _healthyStore.Collection(key)
                             .Take(_settings.UnhealthyCount)
                             .All(e => e == false);

            return(!isUnhealty);
        }
        public bool IsHealthy()
        {
            var nginxIsActive = IsActiveNginx();

            const string key = "nginx";

            _healthyStore.AddHealthyStatus(key, nginxIsActive);

            var isUnhealty = _healthyStore.Collection(key)
                             .Take(_nginxSettings.HealthyCount)
                             .Any(e => e == false);

            return(!isUnhealty);
        }
        public bool IsHealthy()
        {
            var snapshot = _snapshotManager.Take(_networkSettings.InterfaceName);

            const string key = "network";

            if (snapshot.Succeeded)
            {
                var snapshotIsHealthy = _networkSettings.Percentage > snapshot.Percentage;

                _healthyStore.AddHealthyStatus(key, snapshotIsHealthy);
            }

            var isUnhealty = _healthyStore.Collection(key)
                             .Take(_networkSettings.UnhealthyCount)
                             .All(e => e == false);

            return(!isUnhealty);
        }