This commit is contained in:
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@@ -50,7 +50,7 @@
|
|||||||
"AYANOVA_FOLDER_USER_FILES": "c:\\temp\\RavenTestData\\userfiles",
|
"AYANOVA_FOLDER_USER_FILES": "c:\\temp\\RavenTestData\\userfiles",
|
||||||
"AYANOVA_FOLDER_BACKUP_FILES": "c:\\temp\\RavenTestData\\backupfiles",
|
"AYANOVA_FOLDER_BACKUP_FILES": "c:\\temp\\RavenTestData\\backupfiles",
|
||||||
"AYANOVA_METRICS_USE_INFLUXDB": "false",
|
"AYANOVA_METRICS_USE_INFLUXDB": "false",
|
||||||
"AYANOVA_SERVER_TEST_MODE":"true",
|
"AYANOVA_SERVER_TEST_MODE":"false",
|
||||||
"AYANOVA_SERVER_TEST_MODE_SEEDLEVEL":"small",
|
"AYANOVA_SERVER_TEST_MODE_SEEDLEVEL":"small",
|
||||||
"AYANOVA_SERVER_TEST_MODE_TZ_OFFSET":"-7",
|
"AYANOVA_SERVER_TEST_MODE_TZ_OFFSET":"-7",
|
||||||
"AYANOVA_BACKUP_PG_DUMP_PATH":"C:\\data\\code\\PostgreSQLPortable_12.0\\App\\PgSQL\\bin\\"
|
"AYANOVA_BACKUP_PG_DUMP_PATH":"C:\\data\\code\\PostgreSQLPortable_12.0\\App\\PgSQL\\bin\\"
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
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>
|
/// <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>
|
/// <returns>Snapshot of metrics</returns>
|
||||||
[HttpGet]
|
[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)
|
if (serverState.IsClosed)
|
||||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||||
@@ -64,11 +65,30 @@ namespace AyaNova.Api.Controllers
|
|||||||
{
|
{
|
||||||
return StatusCode(403, new ApiNotAuthorizedResponse());
|
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
|
//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
|
//Log
|
||||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.Metrics, AyaEvent.Retrieved), ct);
|
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.Metrics, AyaEvent.Retrieved), ct);
|
||||||
|
|||||||
Reference in New Issue
Block a user