Updates to metrics and watchdog systems

This commit is contained in:
Timothy Baldridge 2020-11-19 22:00:07 -07:00
parent 3a3206755a
commit a494839a09
6 changed files with 38 additions and 27 deletions

View File

@ -94,7 +94,7 @@ namespace Wabbajack.BuildServer.Controllers
var response = HandleGetReport(new
{
services = (await _quickSync.Report())
.Select(s => new {Name = s.Key, Time = s.Value.LastRunTime, MaxTime = s.Value.Delay, IsLate = s.Value.LastRunTime > s.Value.Delay})
.Select(s => new {Name = s.Key.Name, Time = s.Value.LastRunTime, MaxTime = s.Value.Delay, IsLate = s.Value.LastRunTime > s.Value.Delay})
.OrderBy(s => s.Name)
.ToArray(),
lists = _listValidator.ValidationInfo.Select(s => new {Name = s.Key, Time = s.Value.ValidationTime})

View File

@ -43,13 +43,23 @@ namespace Wabbajack.BuildServer.Controllers
[ResponseCache(Duration = 60 * 60)]
public async Task<IActionResult> MetricsReport(string subject)
{
var results = (await _sql.MetricsReport(subject))
var metrics = (await _sql.MetricsReport(subject)).ToList();
var labels = metrics.GroupBy(m => m.Date)
.OrderBy(m => m.Key)
.Select(m => m.Key)
.ToArray();
var labelStrings = labels.Select(l => l.ToString("MM-dd-yyy")).ToList();
var results = metrics
.GroupBy(m => m.Subject)
.Select(g => new MetricResult
.Select(g =>
{
SeriesName = g.Key,
Labels = g.Select(m => m.Date.ToString(CultureInfo.InvariantCulture)).ToList(),
Values = g.Select(m => m.Count).ToList()
var indexed = g.ToDictionary(m => m.Date, m => m.Count);
return new MetricResult
{
SeriesName = g.Key,
Labels = labelStrings,
Values = labels.Select(l => indexed.TryGetValue(l, out var found) ? found : 0).ToList()
};
});
return Ok(results.ToList());
}

View File

@ -30,23 +30,24 @@ namespace Wabbajack.Server.DataLayer
{
await using var conn = await Open();
return (await conn.QueryAsync<AggregateMetric>(@"
SELECT d.Date, d.GroupingSubject as Subject, Count(*) as Count FROM
(select DISTINCT CONVERT(date, Timestamp) as Date, GroupingSubject, Action, MetricsKey from dbo.Metrics) m
RIGHT OUTER JOIN
(SELECT CONVERT(date, DATEADD(DAY, number + 1, dbo.MinMetricDate())) as Date, GroupingSubject, Action
FROM master..spt_values
CROSS JOIN (
SELECT DISTINCT GroupingSubject, Action FROM dbo.Metrics
WHERE MetricsKey is not null
AND Subject != 'Default'
AND TRY_CONVERT(uniqueidentifier, Subject) is null) as keys
WHERE type = 'P'
AND DATEADD(DAY, number+1, dbo.MinMetricDate()) <= dbo.MaxMetricDate()) as d
ON m.Date = d.Date AND m.GroupingSubject = d.GroupingSubject AND m.Action = d.Action
WHERE d.Action = @action
AND d.Date >= DATEADD(month, -1, GETUTCDATE())
group by d.Date, d.GroupingSubject, d.Action
ORDER BY d.Date, d.GroupingSubject, d.Action", new {Action = action}))
select
datefromparts(datepart(YEAR,Timestamp), datepart(MONTH,Timestamp), datepart(DAY,Timestamp)) as Date,
GroupingSubject as Subject,
count(*) as Count
from dbo.metrics where
Action = @Action
AND GroupingSubject in (select DISTINCT GroupingSubject from dbo.Metrics
WHERE action = @Action
AND MetricsKey is not null
AND Subject != 'Default'
AND Subject != 'untitled'
AND TRY_CONVERT(uniqueidentifier, Subject) is null
AND Timestamp >= DATEADD(DAY, -1, GETUTCDATE()))
group by
datefromparts(datepart(YEAR,Timestamp), datepart(MONTH,Timestamp), datepart(DAY,Timestamp)),
GroupingSubject
Order by datefromparts(datepart(YEAR,Timestamp), datepart(MONTH,Timestamp), datepart(DAY,Timestamp)) asc",
new {Action = action}))
.ToList();
}

View File

@ -32,7 +32,7 @@ namespace Wabbajack.Server.Services
where T : IReportingService
{
using var _ = await _lock.WaitAsync();
_services[typeof(T)] = service;
_services[service.GetType()] = service;
}
public async Task<CancellationToken> GetToken<T>()

View File

@ -20,7 +20,7 @@ namespace Wabbajack.Server.Services
var report = await _quickSync.Report();
foreach (var service in report)
{
if (service.Value.LastRunTime >= service.Value.Delay * 2)
if (service.Value.LastRunTime != default && service.Value.LastRunTime >= service.Value.Delay * 2)
{
await _discord.Send(Channel.Spam,
new DiscordMessage {Content = $"Service {service.Key.Name} has missed it's scheduled execution window"});

View File

@ -51,7 +51,7 @@
return {
label: series.seriesName,
fill: false,
data: _.last(series.values, 30)
data: _.last(series.values, 90)
}});
var ctx = document.getElementById(ele).getContext('2d');
var chart = new Chart(ctx, {
@ -60,7 +60,7 @@
// The data for our dataset
data: {
labels: _.last(labels, 30),
labels: _.last(labels, 90),
datasets: datasets},
// Configuration options go here