Metrics.NET icon indicating copy to clipboard operation
Metrics.NET copied to clipboard

Monitoring windows service using Metrics.Net

Open rdongur opened this issue 9 years ago • 1 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

rdongur avatar May 16 '16 16:05 rdongur

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)
            {
                ...
            }
        }

SabrinaMH avatar May 22 '17 14:05 SabrinaMH