by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Sep 28 06:02
    czd890 opened #609
  • Sep 18 12:21
    suslovk synchronize #608
  • Sep 18 11:47
    suslovk opened #608
  • Sep 14 09:45
    Davee02 commented #32
  • Sep 03 05:54
    Stan92 opened #607
  • Sep 02 08:21
    alhardy commented #605
  • Sep 02 01:58
    matthewkrieger edited #606
  • Sep 02 01:44
    matthewkrieger opened #606
  • Sep 01 19:38
    vjacquet opened #605
  • Aug 31 20:02
    siberianguy opened #604
  • Aug 30 20:12
    dehghanfar commented #593
  • Aug 28 12:25
    albertobelardi opened #603
  • Aug 24 16:12
    EugeneKrapivin commented #601
  • Aug 24 16:10
    EugeneKrapivin commented #601
  • Aug 21 18:43
    pbros commented #593
  • Aug 20 09:56
    efmk commented #464
  • Aug 20 06:28
    efmk commented #464
  • Aug 19 10:32
    efmk edited #602
  • Aug 19 10:32
    efmk edited #602
  • Aug 19 09:38
    efmk opened #602
Richard Tasker
@ritasker
@alhardy Thanks for helping me out last week. I didn't realise I had to add a webserver to my console app to get the healthchecks. But I have them now :+1:
Allan Hardy
@alhardy
@ritasker no worries. Health checks can be used without having to register the health check middleware but then you would have to report the health by some other means other than exposing an endpoint.
Silas Reinagel
@SilasReinagel
I seem to be having troubles with the Health Endpoint hosting
Not sure if I am doing something wrong.
        public static void AddHealthChecks(this IServiceCollection services)
        {
            var serviceProvider = services.BuildServiceProvider();
            var health = AppMetricsHealth.CreateDefaultBuilder()
                .HealthChecks.AddCheck(new ServiceHealthCheck<OltpDb>(serviceProvider.GetService<OltpDb>(), "SQL Connection"))
                .Build();

            services.AddHealth(health);
            services.AddHealthEndpoints();
        }

        public static void UseHealthChecks(this IApplicationBuilder applicationBuilder)
        {
            applicationBuilder.UseHealthAllEndpoints();
        }
I have NuGet Packages instead for App.Metrics.AspNetCore, App.Metrics.AspNetCore.Endpoints, App.Metrics.AspNetCore.Health, App.Metrics.AspNetCore.Health.Endpoints, App.Metrics.AspNetCore.Mvc and App.Metrics.AspNetCore.Health.Hosting
I can't find the hosting endpoint when running.
Akash John
@johnakash
Hi Guys
I am looking for a solution to monitor health check of some applications we developed. All the applications are hosted internally and we will be monitoring the same through Health. Could you please let us know if this application help me in that?
MikhaelSorkin
@MikhaelSorkin
Hi all.
Can someone tell me, how to configure reporting from healthchecks to metrics, to evaluate healthchecks only when metrics requested?
We have an installation of Prometheus and we want to control healthchecks evaluation frequency only at Prometheus.
So we need this pipeline:
1) prometheus asks http://some-service/metrics
2) appmetrics evaluates healthchecks and converts result to 0 or 1
3) appmetrics returns this value in prometheus text format
Allan Hardy
@alhardy
Try this:
public static IWebHostBuilder ConfigureDefaultHealth(this IWebHostBuilder webHostBuilder, IMetrics metrics)
        {
            webHostBuilder.ConfigureHealthWithDefaults((context, builder) =>
            {
                // Add additional checks
                builder.Report.ToMetrics(metrics);
            });

            return webHostBuilder;
        }
public sealed class Program
    {
        public static async Task<int> Main(string[] args)
        {
            var webHost = CreateWebHostBuilder(args).Build();

            try
            {
                webHost.Run();

                return 0;
            }
            catch (Exception ex)
            {
                Log.Fatal(ex, "Host terminated unexpectedly, check the application's WebHost configuration.");
                return 1;
            }
            finally
            {
                Log.CloseAndFlush();
            }
        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args)
        {
            var metrics = AppMetrics.CreateDefaultBuilder().BuildDefaultMetrics();

            var webHost = WebHost.CreateDefaultBuilder(args)
                   .UseKestrel(options => options.AddServerHeader = false)
                   .UseContentRoot(Directory.GetCurrentDirectory())
                   .ConfigureDefaultMetrics(metrics)
                   .ConfigureDefaultHealth(metrics)
                   .UseDefaultMetrics()
                   .UseDefaultHealth()
                   .UseStartup<Startup>();

            return webHost;
        }
    }
Program.Metrics.cs
public static class ProgramMetrics
    {
        public static IMetricsRoot BuildDefaultMetrics(this IMetricsBuilder builder)
        {
            var configuration = new ConfigurationBuilder()
                                .AddDefaultSources()
                                .Build();

            // Samples with weight of less than 10% of average should be discarded when rescaling
            const double minimumSampleWeight = 0.001;

            builder.Configuration.ReadFrom(configuration);

            builder.SampleWith.ForwardDecaying(
                AppMetricsReservoirSamplingConstants.DefaultSampleSize,
                AppMetricsReservoirSamplingConstants.DefaultExponentialDecayFactor,
                minimumSampleWeight: minimumSampleWeight);

            if (!Constants.Environments.IsDevelopment())
            {
                var grafanaCloudHostedMetricsOptions = new MetricsReportingHostedMetricsOptions();
                configuration.GetSection(nameof(MetricsReportingHostedMetricsOptions)).Bind(grafanaCloudHostedMetricsOptions);

                builder.Report.ToHostedMetrics(grafanaCloudHostedMetricsOptions);
            }

            return builder.Build();
        }

        public static IWebHostBuilder ConfigureDefaultMetrics(this IWebHostBuilder webHostBuilder, IMetricsRoot metrics)
        {
            webHostBuilder.ConfigureMetrics(metrics);

            return webHostBuilder;
        }

        public static IWebHostBuilder UseDefaultMetrics(this IWebHostBuilder webHostBuilder)
        {
            // Protect endpoints with key
            webHostBuilder.ConfigureServices(
                (context, services) => { services.AddSingleton<IStartupFilter>(new RequireEndpointKeyStartupFilter(context.Configuration)); });

            webHostBuilder.UseMetrics();

            return webHostBuilder;
        }
    }
MikhaelSorkin
@MikhaelSorkin

Hello Allan.
Thank you for your response.
As i understand, this line builder.Report.ToMetrics(metrics) adds reporter which would execute healthchecks at its own frequency - it configures by ReportInterval.
I want to disable this reporting and want to evaluate health score only when prometheus asks for it.
I found another solution to evaluate healthchecks on demand:

var metrics = new MetricsBuilder().Build();
var health = new HealthBuilder().Build();

metrics.Measure.Gauge.SetValue(new GaugeOptions(), () => new FunctionGauge(() =>
{
    var checkResult = health.HealthCheckRunner.ReadAsync().GetAwaiter().GetResult();
    if(checkResult.Status == HealthCheckStatus.Healthy)
    {
        return 1;
    }

    return 0;
}));

Is it ok?

Igor Melnikov
@MelnikovIG
Hi all, how to setup app metrics with prometeus to push initial counter value (0)?