This commit is contained in:
2020-05-30 20:10:41 +00:00
parent 217488872f
commit 7f7b5c3ac2
7 changed files with 44 additions and 76 deletions

View File

@@ -1,5 +1,6 @@
{"login": "manager","password": "l3tm3in"}
{"login": "OpsAdminLimited","password": "OpsAdminLimited"}
todo: enable response compression

View File

@@ -30,7 +30,7 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.OpenApi" Version="1.1.4" />
<PackageReference Include="MiniProfiler.AspNetCore.Mvc" Version="4.1.0" />
<PackageReference Include="MiniProfiler.AspNetCore" Version="4.1.0" />
<PackageReference Include="NLog" Version="4.6.7" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.9.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.0" />

View File

@@ -14,7 +14,7 @@ using Newtonsoft.Json.Linq;
using AyaNova.Models;
using AyaNova.Api.ControllerHelpers;
using AyaNova.Biz;
using StackExchange.Profiling;
namespace AyaNova.Api.Controllers
{
@@ -33,6 +33,7 @@ namespace AyaNova.Api.Controllers
private readonly ApiServerState serverState;
private const int DEFAULT_MAX_RECORDS = 400;
private const long MB = (1024 * 1024);
/// <summary>
/// ctor
@@ -40,15 +41,37 @@ namespace AyaNova.Api.Controllers
/// <param name="dbcontext"></param>
/// <param name="logger"></param>
/// <param name="apiServerState"></param>
/// <param name="prof"></param>
public ServerMetricsController(AyContext dbcontext, ILogger<LogFilesController> logger, ApiServerState apiServerState)
{
ct = dbcontext;
log = logger;
serverState = apiServerState;
serverState = apiServerState;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
[HttpGet("prof")]
public async Task<IActionResult> GetProfileMetrics()
{
using (MiniProfiler.Current.Step("Get Metrics test"))
{
await Task.Delay(1500);
//await Task.CompletedTask;
}
//MiniProfiler.Current.RenderPlainText()
return Content(MiniProfiler.Current.RenderPlainText());
}
/// <summary>
/// Get Memory and CPU server metrics for time period specified
/// </summary>

View File

@@ -10,6 +10,7 @@ using NLog.Web;
using NLog.Targets;
using NLog.Config;
using AyaNova.Util;
using StackExchange.Profiling;
namespace AyaNova
{
@@ -20,6 +21,7 @@ namespace AyaNova
public static void Main(string[] args)
{
//Get config
var config = new ConfigurationBuilder().AddEnvironmentVariables().AddCommandLine(args).Build();
ServerBootConfig.SetConfiguration(config);
@@ -216,6 +218,7 @@ namespace AyaNova
logger.Info("AyaNova server shutting down");
NLog.LogManager.Shutdown();
}
}

View File

@@ -107,6 +107,12 @@ namespace AyaNova
FileUtil.EnsureUserAndUtilityFoldersExistAndAreNotIdentical(_hostingEnvironment.ContentRootPath);
#region DATABASE
// //NOTE: this is required to workaround a bug with miniprofiler
// //if I don't add the memory cache service miniprofiler does but the
// //addition of npgsql below fucks up the config for memory cache somehow
// //documented here: https://github.com/MiniProfiler/dotnet/issues/433
// services.AddMemoryCache();
_connectionString = ServerBootConfig.AYANOVA_DB_CONNECTION;
//Check DB server exists and can be connected to
@@ -283,75 +289,7 @@ namespace AyaNova
#endregion
#region Mini Profiler
// services.AddMemoryCache();
services.AddMiniProfiler(options =>
{
// All of this is optional. You can simply call .AddMiniProfiler() for all defaults
// (Optional) Path to use for profiler URLs, default is /mini-profiler-resources
// options.RouteBasePath = "/profiler";
// (Optional) Control storage
// (default is 30 minutes in MemoryCacheStorage)
// (options.Storage as System.Runtime.MemoryCacheStorage).CacheDuration = TimeSpan.FromMinutes(60);
// (Optional) Control which SQL formatter to use, InlineFormatter is the default
// options.SqlFormatter = new StackExchange.Profiling.SqlFormatters.InlineFormatter();
// (Optional) To control authorization, you can use the Func<HttpRequest, bool> options:
// (default is everyone can access profilers)
// options.ResultsAuthorize = request => MyGetUserFunction(request).CanSeeMiniProfiler;
// options.ResultsListAuthorize = request => MyGetUserFunction(request).CanSeeMiniProfiler;
// Or, there are async versions available:
// options.ResultsAuthorizeAsync = async request => (await MyGetUserFunctionAsync(request)).CanSeeMiniProfiler;
// options.ResultsAuthorizeListAsync = async request => (await MyGetUserFunctionAsync(request)).CanSeeMiniProfilerLists;
// (Optional) To control which requests are profiled, use the Func<HttpRequest, bool> option:
// (default is everything should be profiled)
// options.ShouldProfile = request => MyShouldThisBeProfiledFunction(request);
// (Optional) Profiles are stored under a user ID, function to get it:
// (default is null, since above methods don't use it by default)
// options.UserIdProvider = request => MyGetUserIdFunction(request);
// (Optional) Swap out the entire profiler provider, if you want
// (default handles async and works fine for almost all applications)
// options.ProfilerProvider = new MyProfilerProvider();
// (Optional) You can disable "Connection Open()", "Connection Close()" (and async variant) tracking.
// (defaults to true, and connection opening/closing is tracked)
// options.TrackConnectionOpenClose = true;
// (Optional) Use something other than the "light" color scheme.
// (defaults to "light")
// options.ColorScheme = StackExchange.Profiling.ColorScheme.Auto;
// The below are newer options, available in .NET Core 3.0 and above:
// (Optional) You can disable MVC filter profiling
// (defaults to true, and filters are profiled)
// options.EnableMvcFilterProfiling = true;
// ...or only save filters that take over a certain millisecond duration (including their children)
// (defaults to null, and all filters are profiled)
// options.MvcFilterMinimumSaveMs = 1.0m;
// (Optional) You can disable MVC view profiling
// (defaults to true, and views are profiled)
// options.EnableMvcViewProfiling = true;
// ...or only save views that take over a certain millisecond duration (including their children)
// (defaults to null, and all views are profiled)
// options.MvcViewMinimumSaveMs = 1.0m;
// (Optional - not recommended) You can enable a heavy debug mode with stacks and tooltips when using memory storage
// It has a lot of overhead vs. normal profiling and should only be used with that in mind
// (defaults to false, debug/heavy mode is off)
//options.EnableDebugMode = true;
});
#endregion
_newLog.LogDebug("Generator");
services.AddSingleton<IHostedService, GeneratorService>();
@@ -373,7 +311,7 @@ namespace AyaNova
// {
// app.UseDeveloperExceptionPage();
// }
_newLog.LogDebug("Profiler");
_newLog.LogDebug("Profiler");
app.UseMiniProfiler();
//Store a reference to the dependency injection service for static classes

View File

@@ -29,7 +29,10 @@ namespace AyaNova.Biz
switch (ayaType)
{
//Oddballs only, otherwise let default handle it
case AyaType.Global:
return "Global";
case AyaType.GlobalOps:
return "GlobalOps";
case AyaType.FileAttachment:
TABLE = "afileattachment";
COLUMN = "displayfilename";

View File

@@ -4,7 +4,7 @@ using Microsoft.Extensions.Logging;
using AyaNova.Util;
using AyaNova.Models;
using Microsoft.EntityFrameworkCore;
using StackExchange.Profiling;
namespace AyaNova.Biz
@@ -177,7 +177,7 @@ namespace AyaNova.Biz
DateTime ClearDate = DateTime.UtcNow - tsDataRetention;
using (AyContext ct = ServiceProviderProvider.DBContext)
{
// ct.Database.ExecuteSqlInterpolated($"delete from ametricmm where t < {ClearDate.ToUniversalTime()}");
// ct.Database.ExecuteSqlInterpolated($"delete from ametricmm where t < {ClearDate.ToUniversalTime()}");
}
_lastDDSnapshot = now;
}