This commit is contained in:
2020-05-26 19:42:25 +00:00
parent e511667dbc
commit 61c9687b66
2 changed files with 67 additions and 22 deletions

View File

@@ -80,27 +80,21 @@ namespace AyaNova.Api.Controllers
MinuteMetrics = await ct.MetricMM.AsNoTracking().OrderBy(z => z.t).ToListAsync();
}
//split out into seperate arrays
//10 digits is epoch seconds
//List<Tuple<double, double>> cpu=new List<Tuple<double, double>>();
var cpu = MinuteMetrics.Select(z => new Tuple<double, double>(new DateTimeOffset(z.t).ToUnixTimeSeconds(), z.CPU)).ToList();
if (maxRecords < MinuteMetrics.Count)
var ret = new
{
cpu = Util.DataUtil.LargestTriangleThreeBuckets(cpu, (int)maxRecords) as List<Tuple<double, double>>;
//downsample it here
;//https://github.com/sveinn-steinarsson/flot-downsample/
MetricMM = new
{
labels = MinuteMetrics.Select(z => new DateTimeOffset(z.t).ToUnixTimeSeconds()).ToArray(),
cpu = MinuteMetrics.Select(z => z.CPU).ToArray(),
gen0 = MinuteMetrics.Select(z => z.Gen0).ToArray(),
gen1 = MinuteMetrics.Select(z => z.Gen1).ToArray(),
gen2 = MinuteMetrics.Select(z => z.Gen2).ToArray(),
allocated = MinuteMetrics.Select(z => z.Allocated).ToArray(),
workingSet = MinuteMetrics.Select(z => z.WorkingSet).ToArray(),
privateBytes = MinuteMetrics.Select(z => z.PrivateBytes).ToArray()
}
//convert to efficient array of double pairs
var v = cpu.Select(z => new double[] { z.Item1, z.Item2 }).ToArray();
var ret = new
{
cpu = v
};
//Log
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.Metrics, AyaEvent.Retrieved), ct);
@@ -109,10 +103,61 @@ namespace AyaNova.Api.Controllers
}
//------------
/*
{
"chartData": {
"labels": [
"sunday",
"monday",
"tuesday",
"wednesday",
"thursday",
"friday",
"saturday"
],
"thisWeek": [
20000,
14000,
12000,
15000,
18000,
19000,
22000
],
"lastWeek": [
19000,
10000,
14000,
14000,
15000,
22000,
24000
]
}
}
*/
// //split out into seperate arrays
// //10 digits is epoch seconds
// //List<Tuple<double, double>> cpu=new List<Tuple<double, double>>();
// var cpu = MinuteMetrics.Select(z => new Tuple<double, double>(new DateTimeOffset(z.t).ToUnixTimeSeconds(), z.CPU)).ToList();
// bool DownSampled=false;
// if (maxRecords < MinuteMetrics.Count)
// {
// cpu = Util.DataUtil.LargestTriangleThreeBuckets(cpu, (int)maxRecords) as List<Tuple<double, double>>;
// //downsample it here
// ;//https://github.com/sveinn-steinarsson/flot-downsample/
// DownSampled=true;
// }
// //convert to efficient array of double pairs
// // var v = cpu.Select(z => new double[] { z.Item1, z.Item2 }).ToArray();
// var v = cpu.Select(z => new MetricItem { x= DateTimeOffset.FromUnixTimeSeconds((long)z.Item1), y=z.Item2 }).ToArray();
}
}

View File

@@ -24,7 +24,7 @@ namespace AyaNova.Biz
private static double _cpu = 0;
#if(DEBUG)
private static TimeSpan tsOneMinute = new TimeSpan(0, 1, 0);
private static TimeSpan tsOneMinute = new TimeSpan(0, 0, 10);
#else
private static TimeSpan tsOneMinute = new TimeSpan(0, 1, 0);
#endif