api(api, dal): IInfluxDbService. StatRobotStateController мониторинг роботов
This commit is contained in:
@@ -218,6 +218,12 @@
|
||||
public const string GetConnectionStats = BaseStat + "/rabbitmq-connections/";
|
||||
}
|
||||
|
||||
public static class StatRobotState
|
||||
{
|
||||
public const string Get = BaseStat + "/robot-states/";
|
||||
public const string Send = BaseStat + "/robot-states/";
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Наряды
|
||||
|
||||
9
PARR.API/Contracts/V1/Requests/RobotStateRequest.cs
Normal file
9
PARR.API/Contracts/V1/Requests/RobotStateRequest.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using PARR.Constants;
|
||||
|
||||
namespace PARR.API.Contracts.V1.Requests
|
||||
{
|
||||
public class RobotStateRequest
|
||||
{
|
||||
public RobotsAllEnum Robot { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
using FluentValidation;
|
||||
using InfluxDB.Client.Api.Domain;
|
||||
using InfluxDB.Client.Writes;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using PARR.API.Contracts.V1;
|
||||
using PARR.API.Contracts.V1.Requests;
|
||||
using PARR.API.Contracts.V1.Responses.Base;
|
||||
using PARR.API.Controllers.V1.Base;
|
||||
using PARR.Constants;
|
||||
using PARR.DAL.InfluxDbServices;
|
||||
using PARR.DAL.Settings;
|
||||
|
||||
namespace PARR.API.Controllers.V1.Statistics
|
||||
{
|
||||
/// <summary>
|
||||
/// Статистика доступности роботов
|
||||
/// </summary>
|
||||
[Authorize(Roles = ParrRoles.EsppRobot.RoleOrAdmin)]
|
||||
public class StatRobotStateController : BaseApiController
|
||||
{
|
||||
private readonly IInfluxDbService influxDbService;
|
||||
private readonly IValidator<RobotStateRequest> validator;
|
||||
private readonly InfluxDbSettings influxDbSettings;
|
||||
|
||||
public StatRobotStateController(
|
||||
IInfluxDbService influxDbService,
|
||||
IValidator<RobotStateRequest> validator,
|
||||
InfluxDbSettings influxDbSettings
|
||||
)
|
||||
{
|
||||
this.influxDbService = influxDbService;
|
||||
this.validator = validator;
|
||||
this.influxDbSettings = influxDbSettings;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Статистика доступности роботов. Передать инф-у о доступности
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost(ApiRoutes.StatRobotState.Send)]
|
||||
public async Task<IActionResult> Send([FromBody] RobotStateRequest request)
|
||||
{
|
||||
var resultValidate = await validator.ValidateAsync(request);
|
||||
if (!resultValidate.IsValid)
|
||||
return BadRequest(new Response(resultValidate.Errors));
|
||||
|
||||
var result = influxDbService.Write(write =>
|
||||
{
|
||||
var point = PointData.Measurement("robots")
|
||||
.Tag("robot", request.Robot.ToString())
|
||||
//.Field("robot", (int)request.Robot)
|
||||
.Field("isUp", 1)
|
||||
.Timestamp(DateTime.UtcNow, WritePrecision.Ns);
|
||||
|
||||
write.WritePoint(point, bucket: influxDbSettings.Robots!.Bucket, org: influxDbSettings.Organization);
|
||||
}, influxDbSettings.Robots!.Token);
|
||||
|
||||
if (!result)
|
||||
return BadRequest($"Ошибка при отправке данных");
|
||||
|
||||
return Ok(new Response<string>("", true));
|
||||
}
|
||||
}
|
||||
}
|
||||
17
PARR.API/Validators/RobotStateRequestValidator.cs
Normal file
17
PARR.API/Validators/RobotStateRequestValidator.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using FluentValidation;
|
||||
using PARR.API.Contracts.V1.Requests;
|
||||
using PARR.Constants;
|
||||
|
||||
namespace PARR.API.Validators
|
||||
{
|
||||
public class RobotStateRequestValidator : AbstractValidator<RobotStateRequest>
|
||||
{
|
||||
public RobotStateRequestValidator()
|
||||
{
|
||||
RuleFor(t => t.Robot).NotNull().IsInEnum().WithMessage($"Допустимые значения: {(int)RobotsAllEnum.TemplateOrder} ({RobotsAllEnum.TemplateOrder})," +
|
||||
$"{(int)RobotsAllEnum.ScheduleOrder} ({RobotsAllEnum.ScheduleOrder})," +
|
||||
$"{(int)RobotsAllEnum.TemplatesExport} ({RobotsAllEnum.TemplatesExport})," +
|
||||
$"{(int)RobotsAllEnum.ScheduleExport} ({RobotsAllEnum.ScheduleExport})");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,5 +30,8 @@
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
"InfluxDbSettings": {
|
||||
"Url": "http://10.99.253.216:8086"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,5 +56,17 @@
|
||||
"UserCacheSettings": {
|
||||
"UserCacheTtl": "00:05:00",
|
||||
"UserBlockTtl": "00:03:00"
|
||||
},
|
||||
"InfluxDbSettings": {
|
||||
"Url": "http://parr-influxdb:8086",
|
||||
"Organization": "parr",
|
||||
"Robots": {
|
||||
"Bucket": "robots",
|
||||
"Token": "jgEigdAYLlX6_Ey8FsleCyjfGnh-sdieQDs6JtA_XNweINMUhjPKWD-ibALyo4MG6oDBFAUfFNNpwoiUR0HwQA=="
|
||||
},
|
||||
"Logons": {
|
||||
"Bucket": "logons",
|
||||
"Token": "hjhOqZMAOm3UsAJURcROBvNqCRdR1Tp3jGYTdzduLXC4uSVrysjvEzLtM-n8jotdwuD7y0rxa2FzzOZKRGzKLg=="
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user