Ejemplo n.º 1
0
        public async Task ExecuteAsync(string localhost, CancellationToken Token = default)
        {
            while (!Token.IsCancellationRequested)
            {
                if (serviceInstance == null)
                {
                    if (!localhost.IsEmpty())
                    {
                        await new HttpClient().GetStringAsync($"{localhost}{BasicConfig.HttpReportsServerRegister}");
                    }

                    await Task.Delay(TimeSpan.FromSeconds(1), Token);
                }
                else
                {
                    _logger.LogInformation($"HttpReportsBackgroundService Execute IP:{serviceInstance.LocalIP} Port:{serviceInstance.LocalPort}");

                    IPerformance performance = await _performanceService.GetPerformance(serviceInstance.LocalIP + ":" + serviceInstance.LocalPort);

                    if (performance != null)
                    {
                        await _storage.AddPerformanceAsync(performance);
                    }

                    await Task.Delay(TimeSpan.FromSeconds(10), Token);
                }
            }
        }
Ejemplo n.º 2
0
        public override async Task <WriteReply> WritePerformance(Performance performance, ServerCallContext context)
        {
            Core.Models.Performance model = new Core.Models.Performance()
            {
                Id                 = performance.Id,
                CreateTime         = new System.DateTime(performance.CreateTimeStamp),
                GCGen0             = performance.GCGen0,
                GCGen1             = performance.GCGen1,
                GCGen2             = performance.GCGen2,
                HeapMemory         = performance.HeapMemory,
                Service            = performance.Service,
                Instance           = performance.Instance,
                PendingThreadCount = performance.PendingThreadCount,
                ProcessCPU         = performance.ProcessCPU,
                ProcessMemory      = performance.ProcessMemory,
                ThreadCount        = performance.ThreadCount
            };

            await _storage.AddPerformanceAsync(model);

            return(new WriteReply()
            {
                Code = 0
            });
        }
        public async Task ExecuteAsync(CancellationToken Token = default)
        {
            while (!Token.IsCancellationRequested)
            {
                Uri uri = new Uri(_options.Urls);

                _logger.LogInformation($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} BackgroundService Execute... ");

                IPerformance performance = await _performanceService.GetPerformance(uri.Host + ":" + uri.Port);

                if (performance != null)
                {
                    await _storage.AddPerformanceAsync(performance);
                }

                await Task.Delay(TimeSpan.FromSeconds(10), Token);
            }
        }
        private async Task Save(string Body, string TransportType)
        {
            if (TransportType == typeof(RequestBag).Name)
            {
                try
                {
                    var package = System.Text.Json.JsonSerializer.Deserialize <List <RequestBag> >(Body, _jsonSetting);

                    if (package != null && package.Any())
                    {
                        foreach (var item in package)
                        {
                            await _storage.AddRequestInfoAsync(item);
                        }
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogWarning("Collector Failed:" + ex.Message);
                }
            }

            if (TransportType == typeof(Performance).Name)
            {
                try
                {
                    var package = System.Text.Json.JsonSerializer.Deserialize <Performance>(Body, _jsonSetting);

                    await _storage.AddPerformanceAsync(package);
                }
                catch (Exception ex)
                {
                    _logger.LogWarning("Collector Failed:" + ex.Message);
                }
            }
        }