From 58facaad4ffaf5e19a93f41e2634e541bac0391f Mon Sep 17 00:00:00 2001 From: Yohan Belval Date: Tue, 31 Oct 2023 16:46:42 +0000 Subject: [PATCH] feat: add EnableMetrics override with asp.net config framework/environment vars --- Emby.Server.Implementations/ApplicationHost.cs | 4 +++- Emby.Server.Implementations/ConfigurationOptions.cs | 3 ++- Jellyfin.Server/Startup.cs | 4 ++-- .../Extensions/ConfigurationExtensions.cs | 5 +++++ MediaBrowser.Controller/IServerApplicationHost.cs | 5 +++++ 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index c9bf7f085e..9df954f345 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -263,6 +263,8 @@ namespace Emby.Server.Implementations /// public bool ListenWithHttps => Certificate is not null && ConfigurationManager.GetNetworkConfiguration().EnableHttps; + public bool EnableMetrics => ConfigurationManager.Configuration.EnableMetrics || this._startupConfig.GetValue(EnableMetricsKey); + public string FriendlyName => string.IsNullOrEmpty(ConfigurationManager.Configuration.ServerName) ? Environment.MachineName @@ -449,7 +451,7 @@ namespace Emby.Server.Implementations NetManager = new NetworkManager(ConfigurationManager, _startupConfig, LoggerFactory.CreateLogger()); // Initialize runtime stat collection - if (ConfigurationManager.Configuration.EnableMetrics) + if (this.EnableMetrics) { DotNetRuntimeStatsBuilder.Default().StartCollecting(); } diff --git a/Emby.Server.Implementations/ConfigurationOptions.cs b/Emby.Server.Implementations/ConfigurationOptions.cs index f0c2676279..b19038a762 100644 --- a/Emby.Server.Implementations/ConfigurationOptions.cs +++ b/Emby.Server.Implementations/ConfigurationOptions.cs @@ -19,7 +19,8 @@ namespace Emby.Server.Implementations { FfmpegAnalyzeDurationKey, "200M" }, { PlaylistsAllowDuplicatesKey, bool.FalseString }, { BindToUnixSocketKey, bool.FalseString }, - { SqliteCacheSizeKey, "20000" } + { SqliteCacheSizeKey, "20000" }, + { EnableMetricsKey, bool.FalseString } }; } } diff --git a/Jellyfin.Server/Startup.cs b/Jellyfin.Server/Startup.cs index 2acddb243d..56becb5aef 100644 --- a/Jellyfin.Server/Startup.cs +++ b/Jellyfin.Server/Startup.cs @@ -201,7 +201,7 @@ namespace Jellyfin.Server mainApp.UseWebSocketHandler(); mainApp.UseServerStartupMessage(); - if (_serverConfigurationManager.Configuration.EnableMetrics) + if (_serverApplicationHost.EnableMetrics) { // Must be registered after any middleware that could change HTTP response codes or the data will be bad mainApp.UseHttpMetrics(); @@ -210,7 +210,7 @@ namespace Jellyfin.Server mainApp.UseEndpoints(endpoints => { endpoints.MapControllers(); - if (_serverConfigurationManager.Configuration.EnableMetrics) + if (_serverApplicationHost.EnableMetrics) { endpoints.MapMetrics(); } diff --git a/MediaBrowser.Controller/Extensions/ConfigurationExtensions.cs b/MediaBrowser.Controller/Extensions/ConfigurationExtensions.cs index 6c58064ce9..614df1ad14 100644 --- a/MediaBrowser.Controller/Extensions/ConfigurationExtensions.cs +++ b/MediaBrowser.Controller/Extensions/ConfigurationExtensions.cs @@ -64,6 +64,11 @@ namespace MediaBrowser.Controller.Extensions /// public const string SqliteCacheSizeKey = "sqlite:cacheSize"; + /// + /// The key for enabling the metrics endpoint. + /// + public const string EnableMetricsKey = "EnableMetrics"; + /// /// Gets a value indicating whether the application should host static web content from the . /// diff --git a/MediaBrowser.Controller/IServerApplicationHost.cs b/MediaBrowser.Controller/IServerApplicationHost.cs index e9c4d9e19a..540a8aec6a 100644 --- a/MediaBrowser.Controller/IServerApplicationHost.cs +++ b/MediaBrowser.Controller/IServerApplicationHost.cs @@ -38,6 +38,11 @@ namespace MediaBrowser.Controller /// The name of the friendly. string FriendlyName { get; } + /// + /// Gets a value indicating whether if the server should enable the metrics endpoint. + /// + bool EnableMetrics { get; } + /// /// Gets a URL specific for the request. ///