This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@@ -55,7 +56,7 @@ namespace AyaNova.Api.Controllers
|
||||
/// <param name="maxRecords">Optional maximum records to return. If there are more records for the time period selected than this value the result will be downsampled using Largest-Triangle-Three-Buckets algorithm</param>
|
||||
/// <returns>Snapshot of metrics</returns>
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetMetrics([FromQuery, Required] int hours, [FromQuery] int? maxRecords)
|
||||
public async Task<IActionResult> GetMetrics([FromQuery] int? hours, [FromQuery] int? maxRecords)
|
||||
{
|
||||
if (serverState.IsClosed)
|
||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||
@@ -64,11 +65,30 @@ namespace AyaNova.Api.Controllers
|
||||
{
|
||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||
}
|
||||
|
||||
//use specified values or just return all
|
||||
maxRecords ??= int.MaxValue;
|
||||
List<MetricMM> MinuteMetrics = new List<MetricMM>();
|
||||
//Query the data and downsample if required
|
||||
var maxDate = DateTime.UtcNow.Subtract(new TimeSpan(hours, 0, 0, 0));
|
||||
var MinuteMetrics = await ct.MetricMM.AsNoTracking().Where(z => z.t < maxDate).OrderBy(z => z.t).ToListAsync();
|
||||
|
||||
if (hours != null)
|
||||
{
|
||||
DateTime maxDate = DateTime.UtcNow.Subtract(new TimeSpan((int)hours, 0, 0, 0));
|
||||
MinuteMetrics = await ct.MetricMM.AsNoTracking().Where(z => z.t > maxDate).OrderBy(z => z.t).ToListAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
MinuteMetrics = await ct.MetricMM.AsNoTracking().OrderBy(z => z.t).ToListAsync();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (maxRecords < MinuteMetrics.Count)
|
||||
{
|
||||
//downsample it here
|
||||
;//https://github.com/sveinn-steinarsson/flot-downsample/
|
||||
|
||||
}
|
||||
|
||||
//Log
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.Metrics, AyaEvent.Retrieved), ct);
|
||||
|
||||
Reference in New Issue
Block a user