private static string GetNewServer(this IServiceCollection services, HttpReportsOptions options)
        {
            IConfiguration configuration = services.BuildServiceProvider().GetService <IConfiguration>().GetSection("HttpReports");

            string Default = "http://localhost:5000";

            if (!options.Server.IsEmpty())
            {
                return(options.Server);
            }

            var urls = services.BuildServiceProvider().GetService <IConfiguration>()[WebHostDefaults.ServerUrlsKey] ?? configuration["server.urls"] ?? configuration["server"];

            if (!urls.IsEmpty())
            {
                var first = urls.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();

                if (!first.IsEmpty())
                {
                    return(first);
                }
            }

            return(Default);
        }
 public HttpReportsBackgroundService(IOptions <HttpReportsOptions> options, IConfiguration configuration, ILogger <HttpReportsBackgroundService> logger, IReportsTransport reportsTransport, IPerformanceService performanceService)
 {
     _logger             = logger;
     _performanceService = performanceService;
     _transport          = reportsTransport;
     _config             = configuration;
     _options            = options?.Value;
 }
 public HttpReportsBackgroundService(IOptions <HttpReportsOptions> options, IConfiguration configuration, ILogger <HttpReportsBackgroundService> logger, IHttpContextAccessor contextAccessor, IHttpReportsStorage storage, IPerformanceService performanceService)
 {
     _logger             = logger;
     _performanceService = performanceService;
     _storage            = storage;
     _config             = configuration;
     _options            = options?.Value;
 }
        public static IHttpReportsBuilder AddHttpReports(this IServiceCollection services)
        {
            HttpReportsOptions options = services.BuildServiceProvider().GetService <IConfiguration>().GetSection("HttpReports").Get <HttpReportsOptions>();

            IConfiguration configuration = services.BuildServiceProvider().GetService <IConfiguration>().GetSection("HttpReports");

            services.AddOptions().Configure <HttpReportsOptions>(configuration);

            return(services.AddHttpReportsService(configuration));
        }
Esempio n. 5
0
        public PerformanceService(IOptions <HttpReportsOptions> options)
        {
            Options = options.Value;

            var process = Process.GetCurrentProcess();

            MemoryCounter = new PerformanceCounter("Process", "Working Set - Private", process.ProcessName);

            CPUCounter = new PerformanceCounter("Process", "% Processor Time", process.ProcessName);
        }
Esempio n. 6
0
        public PerformanceService(IOptions <HttpReportsOptions> options)
        {
            Options = options.Value;

            var process = Process.GetCurrentProcess();

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                MemoryCounter = new PerformanceCounter("Process", "Working Set - Private", process.ProcessName);

                CPUCounter = new PerformanceCounter("Process", "% Processor Time", process.ProcessName);
            }
        }
Esempio n. 7
0
        public static IHttpReportsBuilder AddHttpReports(this IServiceCollection services)
        {
            HttpReportsOptions options = services.BuildServiceProvider().GetService <IConfiguration>().GetSection("HttpReports").Get <HttpReportsOptions>();

            IConfiguration configuration = services.BuildServiceProvider().GetService <IConfiguration>().GetSection("HttpReports");

            if (options.Server.IsEmpty())
            {
                var urls = services.BuildServiceProvider().GetService <IConfiguration>()[WebHostDefaults.ServerUrlsKey] ?? configuration["server.urls"];

                if (!urls.IsEmpty())
                {
                    var first = urls.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();

                    if (!string.IsNullOrEmpty(first))
                    {
                        options.Server = first;
                    }
                }
                else
                {
                    options.Server = "http://localhost:5000";
                }
            }

            services.AddOptions();
            services.Configure <HttpReportsOptions>(_ => {
                _.Server        = options.Server;
                _.Service       = options.Service;
                _.MaxBytes      = options.MaxBytes;
                _.RequestFilter = options.RequestFilter;
                _.Switch        = options.Switch;
                _.WithCookie    = options.WithCookie;
                _.WithHeader    = options.WithHeader;
                _.WithRequest   = options.WithRequest;
                _.WithResponse  = options.WithResponse;
            });

            return(services.AddHttpReportsService(configuration));
        }
Esempio n. 8
0
        public PerformanceService(IOptions <HttpReportsOptions> options, ILogger <PerformanceService> logger)
        {
            Options = options.Value;

            _logger = logger;

            var process = Process.GetCurrentProcess();

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                try
                {
                    MemoryCounter = new PerformanceCounter("Process", "Working Set - Private", process.ProcessName);

                    CPUCounter = new PerformanceCounter("Process", "% Processor Time", process.ProcessName);
                }
                catch (Exception ex)
                {
                    SupportPerformanceCounter = false;
                }
            }
        }