Add anonymous metrics

This commit is contained in:
halgari 2019-12-14 21:33:48 -07:00
parent ab44492152
commit ff720cd044
7 changed files with 87 additions and 3 deletions

View File

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Alphaleonis.Win32.Filesystem;
using Nancy;
using Wabbajack.Common;
namespace Wabbajack.CacheServer
{
/// <summary>
/// Extremely
/// </summary>
public class Metrics : NancyModule
{
private static SemaphoreSlim _lockObject = new SemaphoreSlim(1);
public static async Task Log(params object[] args)
{
var msg = new[] {string.Join("\t", args.Select(a => a.ToString()))};
Utils.Log(msg.First());
await _lockObject.WaitAsync();
try
{
File.AppendAllLines("stats.tsv", msg);
}
finally
{
_lockObject.Release();
}
}
public Metrics() : base("/")
{
Get("/metrics/{Action}/{Value}", HandleMetrics);
}
private async Task<string> HandleMetrics(dynamic arg)
{
var date = DateTime.UtcNow;
await Log(date, arg.Action, arg.Value);
return date.ToString();
}
}
}

View File

@ -74,6 +74,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ListValidationService.cs" />
<Compile Include="Metrics.cs" />
<Compile Include="NexusCacheModule.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace Wabbajack.Common
{
public class Metrics
{
/// <summary>
/// This is all we track for metrics, action, and value. The action will be like
/// "downloaded", the value "Joe's list".
/// </summary>
/// <param name="action"></param>
/// <param name="value"></param>
public static async Task Send(string action, params string[] values)
{
var client = new HttpClient();
try
{
await client.GetAsync($"http://build.wabbajack.org/metrics/{action}/{string.Join("\t", values)}");
}
catch (Exception) { }
}
}
}

View File

@ -110,6 +110,7 @@
<Compile Include="FileExtractor.cs" />
<Compile Include="GameMetaData.cs" />
<Compile Include="GOGHandler.cs" />
<Compile Include="Metrics.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SplittingStream.cs" />
<Compile Include="StatusFeed\AErrorMessage.cs" />

View File

@ -39,6 +39,8 @@ namespace Wabbajack.Lib
protected override async Task<bool> _Begin(CancellationToken cancel)
{
if (cancel.IsCancellationRequested) return false;
var metric = Metrics.Send("begin_install", ModList.Name, ModList.WabbajackVersion);
ConfigureProcessor(18, await RecommendQueueSize());
var game = ModList.GameType.MetaData();
@ -134,6 +136,8 @@ namespace Wabbajack.Lib
SetScreenSizeInPrefs();
UpdateTracker.NextStep("Installation complete! You may exit the program.");
var metric2 = Metrics.Send("finish_install", ModList.Name, ModList.WabbajackVersion);
return true;
}

View File

@ -39,6 +39,7 @@ namespace Wabbajack.Lib
protected override async Task<bool> _Begin(CancellationToken cancel)
{
if (cancel.IsCancellationRequested) return false;
var metric = Metrics.Send("begin_install", ModList.Name, ModList.WabbajackVersion);
MessageBox.Show(
"Vortex Support is still experimental and may produce unexpected results. " +
"If anything fails go to the special vortex support channels on the discord. @erri120#2285 " +
@ -109,10 +110,10 @@ namespace Wabbajack.Lib
if (cancel.IsCancellationRequested) return false;
UpdateTracker.NextStep("Installing SteamWorkshopItems");
await InstallSteamWorkshopItems();
//InstallIncludedDownloadMetas();
//InstallIncludedDownloadMetas();
var metric2 = Metrics.Send("finish_install", ModList.Name, ModList.WabbajackVersion);
UpdateTracker.NextStep("Installation complete! You may exit the program.");
return true;
}

View File

@ -81,6 +81,7 @@ namespace Wabbajack
var sub = queue.Status.Select(i => i.ProgressPercent)
.Subscribe(percent => ProgressPercent = percent);
TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
var metric = Metrics.Send("downloading", Metadata.Title);
queue.QueueTask(async () =>
{
var downloader = DownloadDispatcher.ResolveArchive(Metadata.Links.Download);