feat(api): StatRabbitMqController GetConnectionStats добавлен параметр ThresholdConnections, вынесен в настройки

This commit is contained in:
Mikhail Trubnikov
2024-07-25 14:38:22 +10:00
parent 70d96cb88f
commit 2e82c696aa
4 changed files with 50 additions and 3 deletions

View File

@@ -0,0 +1,14 @@
namespace PARR.API.Contracts.V1.Responses.Statistics
{
public class StatRabbitMqConnectionsResponse
{
public StatRabbitMqConnectionsMonitoringSettings MonitoringSettings { get; set; }
public object? MqData { get; set; }
}
public class StatRabbitMqConnectionsMonitoringSettings
{
public int ThresholdConnections { get; set; }
}
}

View File

@@ -2,6 +2,7 @@
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,13 +20,21 @@ namespace PARR.API.Controllers.V1.Statistics
private readonly MqSettings mqSettings;
private readonly ILogger<StatRabbitMqController> logger;
private readonly IMqAdminService mqAdminService;
private readonly MonitoringSettings monitoringSettings;
public StatRabbitMqController(IMqService mqService, MqSettings mqSettings, ILogger<StatRabbitMqController> logger, IMqAdminService mqAdminService)
public StatRabbitMqController(
IMqService mqService,
MqSettings mqSettings,
ILogger<StatRabbitMqController> logger,
IMqAdminService mqAdminService,
MonitoringSettings monitoringSettings
)
{
this.mqService = mqService;
this.mqSettings = mqSettings;
this.logger = logger;
this.mqAdminService = mqAdminService;
this.monitoringSettings = monitoringSettings;
}
/// <summary>
@@ -42,6 +51,7 @@ namespace PARR.API.Controllers.V1.Statistics
return Ok(new Response<object?>(result.Response, true));
#region comments
//var response = new List<StatRabbitMqQueueResponse>();
//// список очередей
@@ -59,6 +69,7 @@ namespace PARR.API.Controllers.V1.Statistics
//}
//return Ok(new Response<List<StatRabbitMqQueueResponse>>(response.OrderBy(t => t.Name).ToList(), true));
#endregion
}
@@ -74,7 +85,16 @@ namespace PARR.API.Controllers.V1.Statistics
if (!result.IsSuccess)
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = $"Ошибка при получении статистики из RabbitMQ." } }));
return Ok(new Response<object?>(result.Response, true));
var response = new StatRabbitMqConnectionsResponse
{
MqData = result.Response,
MonitoringSettings = new StatRabbitMqConnectionsMonitoringSettings
{
ThresholdConnections = monitoringSettings.RabbitMq?.ThresholdConnections ?? 0
}
};
return Ok(new Response<StatRabbitMqConnectionsResponse>(response, true));
}
}
}

View File

@@ -3,6 +3,8 @@
public class MonitoringSettings
{
public List<MonitoringRobotSettings> Robots { get; set; } = new List<MonitoringRobotSettings>();
public MonitoringRabbitMq? RabbitMq { get; set; }
}
public class MonitoringRobotSettings
@@ -11,4 +13,12 @@
public TimeSpan InaccessibilityTime { get; set; }
}
public class MonitoringRabbitMq
{
/// <summary>
/// Кол-во подключений к RabbitMq, если меньше, то алярм
/// </summary>
public int ThresholdConnections { get; set; }
}
}

View File

@@ -99,6 +99,9 @@
"Name": "ScheduleExport",
"InaccessibilityTime": "01:20:00"
}
]
],
"RabbitMq": {
"ThresholdConnections": 18
}
}
}