etishor / Metrics.NET

The Metrics.NET library provides a way of instrumenting applications with custom metrics (timers, histograms, counters etc) that can be reported in various ways and can provide insights on what is happening inside a running application.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Monitoring windows service using Metrics.Net

rdongur opened this issue · comments

Hi,
How do we configure/implement Metrics.Net library for monitoring windows services? We have need to monitor http services and windows services (running in the background) as well. Please let me know if anyone had done this before or have some ideas.

thanks,
Raghu

I have some experience hosting Metrics.Net inside a Windows Service (using Topshelf).
In Program.cs I have the following Topshelf specific code:

                var topshelfExitCode = HostFactory.Run(serviceConfiguration =>
                {
                    Log.Logger.Bootstrap(new ConfigurationFromAppConfig());    
                    serviceConfiguration.UseSerilog(Log.Logger);
                    serviceConfiguration.Service<ApiService>(serviceInstance =>
                    {
                        serviceInstance.ConstructUsing(() => new ApiService());

and in ApiService.cs I have

        public void Start()
        {
            try
            { 
                Uri baseAddress = LoadUrl();
                _webApiServer = WebApp.Start<Startup>(url: baseAddress.ToString());
                Metric.Config.WithHttpEndpoint("http://localhost:1337/").WithAllCounters().WithReporting(r => r.WithTextFileReport(@"c:\temp\APIServiceReports.log", TimeSpan.FromSeconds(5)));
            }
            catch (Exception ex)
            {
                ...
            }
        }