Merge pull request #2985 from sparky8251/prometheus

Add Prometheus exporters
This commit is contained in:
Bond-009 2020-04-29 11:36:05 +02:00 committed by GitHub
commit 690fb65cd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 0 deletions

View File

@ -106,6 +106,7 @@ using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using OperatingSystem = MediaBrowser.Common.System.OperatingSystem;
using Prometheus.DotNetRuntime;
namespace Emby.Server.Implementations
{
@ -259,6 +260,12 @@ namespace Emby.Server.Implementations
_startupOptions = options;
// Initialize runtime stat collection
if (ServerConfigurationManager.Configuration.EnableMetrics)
{
DotNetRuntimeStatsBuilder.Default().StartCollecting();
}
fileSystem.AddShortcutHandler(new MbLinkShortcutHandler(fileSystem));
_networkManager.NetworkChanged += OnNetworkChanged;

View File

@ -39,6 +39,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="3.1.3" />
<PackageReference Include="Mono.Nat" Version="2.0.1" />
<PackageReference Include="prometheus-net.DotNetRuntime" Version="3.3.1" />
<PackageReference Include="ServiceStack.Text.Core" Version="5.8.0" />
<PackageReference Include="sharpcompress" Version="0.25.0" />
<PackageReference Include="SQLitePCL.pretty.netstandard" Version="2.1.0" />

View File

@ -43,6 +43,8 @@
<PackageReference Include="CommandLineParser" Version="2.7.82" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.3" />
<PackageReference Include="prometheus-net" Version="3.5.0" />
<PackageReference Include="prometheus-net.AspNetCore" Version="3.5.0" />
<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" />

View File

@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Prometheus;
namespace Jellyfin.Server
{
@ -69,9 +70,19 @@ namespace Jellyfin.Server
app.UseJellyfinApiSwagger();
app.UseRouting();
app.UseAuthorization();
if (_serverConfigurationManager.Configuration.EnableMetrics)
{
// Must be registered after any middleware that could chagne HTTP response codes or the data will be bad
app.UseHttpMetrics();
}
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
if (_serverConfigurationManager.Configuration.EnableMetrics)
{
endpoints.MapMetrics(_serverConfigurationManager.Configuration.BaseUrl.TrimStart('/') + "/metrics");
}
});
app.Use(serverApplicationHost.ExecuteHttpHandlerAsync);

View File

@ -19,6 +19,11 @@ namespace MediaBrowser.Model.Configuration
/// </summary>
public bool EnableUPnP { get; set; }
/// <summary>
/// Gets or sets a value indicating whether to enable prometheus metrics exporting.
/// </summary>
public bool EnableMetrics { get; set; }
/// <summary>
/// Gets or sets the public mapped port.
/// </summary>
@ -246,6 +251,7 @@ namespace MediaBrowser.Model.Configuration
PublicHttpsPort = DefaultHttpsPort;
HttpServerPortNumber = DefaultHttpPort;
HttpsPortNumber = DefaultHttpsPort;
EnableMetrics = false;
EnableHttps = false;
EnableDashboardResponseCaching = true;
EnableCaseSensitiveItemIds = true;