feat(api, bll): переделал сервис получения статистики из RabbitMQ. StatRabbitMqController - статистика по очередям и соединениям
This commit is contained in:
@@ -215,6 +215,7 @@
|
||||
public static class StatRabbitMq
|
||||
{
|
||||
public const string GetQueueStats = BaseStat + "/rabbitmq-queues/";
|
||||
public const string GetConnectionStats = BaseStat + "/rabbitmq-connections/";
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
|
||||
namespace PARR.API.Contracts.V1.Responses.Statistics
|
||||
{
|
||||
public class StatRabbitMqQueueResponse
|
||||
{
|
||||
public required string Name { get; set; }
|
||||
|
||||
public int Consumers { get; set; }
|
||||
|
||||
public int MessagesTotal { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using PARR.API.Contracts.V1;
|
||||
using PARR.API.Contracts.V1.Responses.Base;
|
||||
using PARR.API.Contracts.V1.Responses.Statistics;
|
||||
using PARR.API.Controllers.V1.Base;
|
||||
using PARR.API.Settings;
|
||||
using PARR.BLL.Services.Interfaces;
|
||||
@@ -19,12 +18,14 @@ namespace PARR.API.Controllers.V1.Statistics
|
||||
private readonly IMqService mqService;
|
||||
private readonly MqSettings mqSettings;
|
||||
private readonly ILogger<StatRabbitMqController> logger;
|
||||
private readonly IMqAdminService mqAdminService;
|
||||
|
||||
public StatRabbitMqController(IMqService mqService, MqSettings mqSettings, ILogger<StatRabbitMqController> logger)
|
||||
public StatRabbitMqController(IMqService mqService, MqSettings mqSettings, ILogger<StatRabbitMqController> logger, IMqAdminService mqAdminService)
|
||||
{
|
||||
this.mqService = mqService;
|
||||
this.mqSettings = mqSettings;
|
||||
this.logger = logger;
|
||||
this.mqAdminService = mqAdminService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -32,25 +33,48 @@ namespace PARR.API.Controllers.V1.Statistics
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.StatRabbitMq.GetQueueStats)]
|
||||
public IActionResult GetQueueStats()
|
||||
public async Task<IActionResult> GetQueueStats()
|
||||
{
|
||||
var response = new List<StatRabbitMqQueueResponse>();
|
||||
var result = await mqAdminService.GetQueuesAsync(mqSettings.Statistics.StatMqAuth);
|
||||
|
||||
// список очередей
|
||||
foreach (var queue in mqSettings.Statistics.QueueList)
|
||||
{
|
||||
var result = mqService.GetQueueCount(mqSettings.Statistics.StatMqAuth, queue);
|
||||
if (!result.IsSuccess)
|
||||
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = $"Ошибка при получении статистики из RabbitMQ." } }));
|
||||
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
logger.LogError(result.Exception, $"Ошибка при запросе статистики из RabbitMQ для очереди: ${queue}");
|
||||
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = $"" } }));
|
||||
}
|
||||
return Ok(new Response<object?>(result.Response, true));
|
||||
|
||||
response.Add(new StatRabbitMqQueueResponse { Name = queue, Consumers = result.ConsumerCount, MessagesTotal = result.Count });
|
||||
}
|
||||
//var response = new List<StatRabbitMqQueueResponse>();
|
||||
|
||||
return Ok(new Response<List<StatRabbitMqQueueResponse>>(response.OrderBy(t => t.Name).ToList(), true));
|
||||
//// список очередей
|
||||
//foreach (var queue in mqSettings.Statistics.QueueList)
|
||||
//{
|
||||
// var result = mqService.GetQueueCount(mqSettings.Statistics.StatMqAuth, queue);
|
||||
|
||||
// if (!result.IsSuccess)
|
||||
// {
|
||||
// logger.LogError(result.Exception, $"Ошибка при запросе статистики из RabbitMQ для очереди: ${queue}");
|
||||
// return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = $"" } }));
|
||||
// }
|
||||
|
||||
// response.Add(new StatRabbitMqQueueResponse { Name = queue, Consumers = result.ConsumerCount, MessagesTotal = result.Count });
|
||||
//}
|
||||
|
||||
//return Ok(new Response<List<StatRabbitMqQueueResponse>>(response.OrderBy(t => t.Name).ToList(), true));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Статистика соединений в RabbitMQ
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.StatRabbitMq.GetConnectionStats)]
|
||||
public async Task<IActionResult> GetConnectionStats()
|
||||
{
|
||||
var result = await mqAdminService.GetConnectionsAsync(mqSettings.Statistics.StatMqAuth);
|
||||
|
||||
if (!result.IsSuccess)
|
||||
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = $"Ошибка при получении статистики из RabbitMQ." } }));
|
||||
|
||||
return Ok(new Response<object?>(result.Response, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ namespace PARR.API.Settings
|
||||
|
||||
public class MqStatistics
|
||||
{
|
||||
public List<string> QueueList { get; set; } = new List<string>();
|
||||
public StatMqAuth StatMqAuth { get; set; } = new StatMqAuth();
|
||||
}
|
||||
|
||||
|
||||
@@ -50,8 +50,7 @@
|
||||
"HostName": "parr-rabbitmq",
|
||||
"User": "rabbit_stats",
|
||||
"Password": "KJHdgfjHFsdy^&$!ff331"
|
||||
},
|
||||
"QueueList": [ "parr-aihit-data", "parr-espp-schedulers", "parr-espp-templates", "parr-generate-templates", "parr-orders" ]
|
||||
}
|
||||
}
|
||||
},
|
||||
"UserCacheSettings": {
|
||||
|
||||
Reference in New Issue
Block a user