|
|
|
|
@@ -33,7 +33,7 @@ namespace AyaNova.Api.Controllers
|
|
|
|
|
private readonly ApiServerState serverState;
|
|
|
|
|
private const int DEFAULT_MAX_RECORDS = 400;
|
|
|
|
|
private const long MB = (1024 * 1024);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// ctor
|
|
|
|
|
@@ -41,72 +41,17 @@ namespace AyaNova.Api.Controllers
|
|
|
|
|
/// <param name="dbcontext"></param>
|
|
|
|
|
/// <param name="logger"></param>
|
|
|
|
|
/// <param name="apiServerState"></param>
|
|
|
|
|
/// <param name="prof"></param>
|
|
|
|
|
|
|
|
|
|
public ServerMetricsController(AyContext dbcontext, ILogger<LogFilesController> logger, ApiServerState apiServerState)
|
|
|
|
|
{
|
|
|
|
|
ct = dbcontext;
|
|
|
|
|
log = logger;
|
|
|
|
|
serverState = apiServerState;
|
|
|
|
|
serverState = apiServerState;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("prof")]
|
|
|
|
|
public async Task<IActionResult> GetProfileMetrics()
|
|
|
|
|
{
|
|
|
|
|
using (MiniProfiler.Current.Step("Get Metrics test"))
|
|
|
|
|
{
|
|
|
|
|
await Task.Delay(1500);
|
|
|
|
|
//await Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//MiniProfiler.Current.RenderPlainText()
|
|
|
|
|
return Content(MiniProfiler.Current.RenderPlainText());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
https://github.com/MiniProfiler/dotnet/blob/95eddc7d57cee9f377419733bf18e76f3e5879e5/src/MiniProfiler/MiniProfilerHandler.cs
|
|
|
|
|
|
|
|
|
|
private string ResultsList(HttpContext context)
|
|
|
|
|
{
|
|
|
|
|
if (!AuthorizeRequest(context, isList: true, message: out string message))
|
|
|
|
|
{
|
|
|
|
|
return message;
|
|
|
|
|
}
|
|
|
|
|
var guids = Options.Storage.List(100);
|
|
|
|
|
var lastId = context.Request["last-id"];
|
|
|
|
|
|
|
|
|
|
if (!lastId.IsNullOrWhiteSpace() && Guid.TryParse(lastId, out var lastGuid))
|
|
|
|
|
{
|
|
|
|
|
guids = guids.TakeWhile(g => g != lastGuid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return guids.Reverse()
|
|
|
|
|
.Select(g => Options.Storage.Load(g))
|
|
|
|
|
.Where(p => p != null)
|
|
|
|
|
.Select(p => new
|
|
|
|
|
{
|
|
|
|
|
p.Id,
|
|
|
|
|
p.Name,
|
|
|
|
|
p.ClientTimings,
|
|
|
|
|
p.Started,
|
|
|
|
|
p.HasUserViewed,
|
|
|
|
|
p.MachineName,
|
|
|
|
|
p.User,
|
|
|
|
|
p.DurationMilliseconds
|
|
|
|
|
}).ToJson();
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Get Memory and CPU server metrics for time period specified
|
|
|
|
|
/// </summary>
|
|
|
|
|
@@ -115,7 +60,7 @@ namespace AyaNova.Api.Controllers
|
|
|
|
|
/// <param name="maxRecords">Optional maximum records to return (downsampled). There is a 400 record maximum fixed default</param>
|
|
|
|
|
/// <returns>Snapshot of metrics</returns>
|
|
|
|
|
[HttpGet("memcpu")]
|
|
|
|
|
public async Task<IActionResult> GetMemCPUetrics([FromQuery, Required] DateTime? tsStart, [FromQuery, Required] DateTime? tsEnd, [FromQuery] int? maxRecords)
|
|
|
|
|
public async Task<IActionResult> GetMemCPUMetrics([FromQuery, Required] DateTime? tsStart, [FromQuery, Required] DateTime? tsEnd, [FromQuery] int? maxRecords)
|
|
|
|
|
{
|
|
|
|
|
//Note: the date and times are nullable and required so that the regular modelstate code kicks in to ensure they are present
|
|
|
|
|
if (serverState.IsClosed)
|
|
|
|
|
@@ -235,75 +180,6 @@ namespace AyaNova.Api.Controllers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Get route server metrics for time period specified
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="tsStart">Start timestamp UTC</param>
|
|
|
|
|
/// <param name="tsEnd">End timestamp UTC</param>
|
|
|
|
|
/// <param name="maxRecords">Optional maximum records to return (downsampled). There is a 400 record maximum fixed default</param>
|
|
|
|
|
/// <returns>Snapshot of metrics</returns>
|
|
|
|
|
[HttpGet("routes")]
|
|
|
|
|
public async Task<IActionResult> GetRouteMetrics([FromQuery, Required] DateTime? tsStart, [FromQuery, Required] DateTime? tsEnd, [FromQuery] int? maxRecords)
|
|
|
|
|
{
|
|
|
|
|
//Note: the date and times are nullable and required so that the regular modelstate code kicks in to ensure they are present
|
|
|
|
|
if (serverState.IsClosed)
|
|
|
|
|
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
|
|
|
|
if (!Authorized.HasReadFullRole(HttpContext.Items, AyaType.Metrics))
|
|
|
|
|
return StatusCode(403, new ApiNotAuthorizedResponse());
|
|
|
|
|
if (!ModelState.IsValid)
|
|
|
|
|
return BadRequest(new ApiErrorResponse(ModelState));
|
|
|
|
|
|
|
|
|
|
maxRecords ??= DEFAULT_MAX_RECORDS;
|
|
|
|
|
|
|
|
|
|
// List<MetricDD> DailyMetrics = new List<MetricDD>();
|
|
|
|
|
// //touniversal is because the parameters are converted to local time here
|
|
|
|
|
// //but then sent to the query as local time as well and not universal time which is what it should be
|
|
|
|
|
// DailyMetrics = await ct.MetricDD.AsNoTracking().Where(z => z.t >= ((DateTime)tsStart).ToUniversalTime() && z.t <= ((DateTime)tsEnd).ToUniversalTime()).OrderBy(z => z.t).ToListAsync();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// var dsAttachmentFileCount = DailyMetrics.Select(z => new Tuple<double, double>(z.t.ToOADate(), z.AttachmentFileCount)).ToList();
|
|
|
|
|
// dsAttachmentFileCount = Util.DataUtil.LargestTriangleThreeBuckets(dsAttachmentFileCount, (int)maxRecords) as List<Tuple<double, double>>;
|
|
|
|
|
|
|
|
|
|
// var dsAttachmentFileSize = DailyMetrics.Select(z => new Tuple<double, double>(z.t.ToOADate(), z.AttachmentFileSize)).ToList();
|
|
|
|
|
// dsAttachmentFileSize = Util.DataUtil.LargestTriangleThreeBuckets(dsAttachmentFileSize, (int)maxRecords) as List<Tuple<double, double>>;
|
|
|
|
|
|
|
|
|
|
// var dsAttachmentFilesAvailableSpace = DailyMetrics.Select(z => new Tuple<double, double>(z.t.ToOADate(), z.AttachmentFilesAvailableSpace)).ToList();
|
|
|
|
|
// dsAttachmentFilesAvailableSpace = Util.DataUtil.LargestTriangleThreeBuckets(dsAttachmentFilesAvailableSpace, (int)maxRecords) as List<Tuple<double, double>>;
|
|
|
|
|
|
|
|
|
|
// var dsUtilityFileCount = DailyMetrics.Select(z => new Tuple<double, double>(z.t.ToOADate(), z.UtilityFileCount)).ToList();
|
|
|
|
|
// dsUtilityFileCount = Util.DataUtil.LargestTriangleThreeBuckets(dsUtilityFileCount, (int)maxRecords) as List<Tuple<double, double>>;
|
|
|
|
|
|
|
|
|
|
// var dsUtilityFileSize = DailyMetrics.Select(z => new Tuple<double, double>(z.t.ToOADate(), z.UtilityFileSize)).ToList();
|
|
|
|
|
// dsUtilityFileSize = Util.DataUtil.LargestTriangleThreeBuckets(dsUtilityFileSize, (int)maxRecords) as List<Tuple<double, double>>;
|
|
|
|
|
|
|
|
|
|
// var dsUtilityFilesAvailableSpace = DailyMetrics.Select(z => new Tuple<double, double>(z.t.ToOADate(), z.UtilityFilesAvailableSpace)).ToList();
|
|
|
|
|
// dsUtilityFilesAvailableSpace = Util.DataUtil.LargestTriangleThreeBuckets(dsUtilityFilesAvailableSpace, (int)maxRecords) as List<Tuple<double, double>>;
|
|
|
|
|
|
|
|
|
|
// var ret = new
|
|
|
|
|
// {
|
|
|
|
|
// attachmentFileCount = dsAttachmentFileCount.Select(z => new MetricLong(DateTime.FromOADate(z.Item1), z.Item2)).ToArray(),
|
|
|
|
|
// attachmentFileSize = dsAttachmentFileSize.Select(z => new MetricLong(DateTime.FromOADate(z.Item1), z.Item2 / MB)).ToArray(),
|
|
|
|
|
// attachmentFilesAvailableSpace = dsAttachmentFilesAvailableSpace.Select(z => new MetricLong(DateTime.FromOADate(z.Item1), z.Item2 / MB)).ToArray(),
|
|
|
|
|
// utilityFileCount = dsUtilityFileCount.Select(z => new MetricLong(DateTime.FromOADate(z.Item1), z.Item2)).ToArray(),
|
|
|
|
|
// utilityFileSize = dsUtilityFileSize.Select(z => new MetricLong(DateTime.FromOADate(z.Item1), z.Item2 / MB)).ToArray(),
|
|
|
|
|
// utilityFilesAvailableSpace = dsUtilityFilesAvailableSpace.Select(z => new MetricLong(DateTime.FromOADate(z.Item1), z.Item2 / MB)).ToArray()
|
|
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
var ret = new { notimplemented = true };
|
|
|
|
|
|
|
|
|
|
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.Metrics, AyaEvent.Retrieved), ct);
|
|
|
|
|
return Ok(ApiOkResponse.Response(ret));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//------------
|
|
|
|
|
public class MetricLong
|
|
|
|
|
{
|
|
|
|
|
|