Esempio n. 1
0
        public async Task <HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
        {
            var client  = new SystemMetricsClient();
            var metrics = client.GetCpuMetrics();

            var status = HealthStatus.Healthy;

            if (metrics.LoadPercentage > 80)
            {
                status = HealthStatus.Degraded;
            }
            else if (metrics.LoadPercentage > 90)
            {
                status = HealthStatus.Unhealthy;
            }

            var data = new Dictionary <string, object>
            {
                { "load", metrics.LoadPercentage }
            };

            var result = new HealthCheckResult(status, null, null, data);

            return(await Task.FromResult(result).AnyContext());
        }
Esempio n. 2
0
        public void CpuTest()
        {
            // arrange
            var sut = new SystemMetricsClient();

            // act
            var result = sut.GetCpuMetrics();

            // assert
            result.LoadPercentage.ShouldBeGreaterThan(0);
        }