Example #1
0
        public async Task <HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
        {
            var client      = new SystemMetricsClient();
            var metrics     = client.GetMemoryMetrics();
            var percentUsed = 100 * metrics.Used / metrics.Total;

            var status = HealthStatus.Healthy;

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

            var data = new Dictionary <string, object>
            {
                { "total", metrics.Total },
                { "used", metrics.Used },
                { "free", metrics.Free }
            };

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

            return(await Task.FromResult(result).AnyContext());
        }
Example #2
0
        public void MemoryTest()
        {
            // arrange
            var sut = new SystemMetricsClient();

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

            // assert
            result.Total.ShouldBeGreaterThan(0);
            result.Used.ShouldBeGreaterThan(0);
            result.Free.ShouldBeGreaterThan(0);
        }