Merge pull request #385 from Bond-009/usage

Don't send usage to emby
pull/702/head
Joshua M. Boniface 6 years ago committed by GitHub
commit c6618d0a5f

@ -1,131 +0,0 @@
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Plugins;
using MediaBrowser.Controller.Session;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Model.Extensions;
namespace Emby.Server.Implementations.EntryPoints
{
/// <summary>
/// Class UsageEntryPoint
/// </summary>
public class UsageEntryPoint : IServerEntryPoint
{
private readonly IServerApplicationHost _applicationHost;
private readonly IHttpClient _httpClient;
private readonly ILogger _logger;
private readonly ISessionManager _sessionManager;
private readonly IUserManager _userManager;
private readonly IServerConfigurationManager _config;
private readonly ConcurrentDictionary<Guid, ClientInfo> _apps = new ConcurrentDictionary<Guid, ClientInfo>();
public UsageEntryPoint(ILogger logger, IServerApplicationHost applicationHost, IHttpClient httpClient, ISessionManager sessionManager, IUserManager userManager, IServerConfigurationManager config)
{
_logger = logger;
_applicationHost = applicationHost;
_httpClient = httpClient;
_sessionManager = sessionManager;
_userManager = userManager;
_config = config;
_sessionManager.SessionStarted += _sessionManager_SessionStarted;
}
void _sessionManager_SessionStarted(object sender, SessionEventArgs e)
{
var session = e.SessionInfo;
if (!string.IsNullOrEmpty(session.Client) &&
!string.IsNullOrEmpty(session.DeviceName) &&
!string.IsNullOrEmpty(session.DeviceId) &&
!string.IsNullOrEmpty(session.ApplicationVersion))
{
var keys = new List<string>
{
session.Client,
session.DeviceName,
session.DeviceId,
session.ApplicationVersion
};
var key = string.Join("_", keys.ToArray()).GetMD5();
ClientInfo info;
if (!_apps.TryGetValue(key, out info))
{
info = new ClientInfo
{
AppName = session.Client,
AppVersion = session.ApplicationVersion,
DeviceName = session.DeviceName,
DeviceId = session.DeviceId
};
_apps[key] = info;
if (_config.Configuration.EnableAnonymousUsageReporting)
{
Task.Run(() => ReportNewSession(info));
}
}
}
}
private async Task ReportNewSession(ClientInfo client)
{
try
{
await new UsageReporter(_applicationHost, _httpClient, _logger)
.ReportAppUsage(client, CancellationToken.None)
.ConfigureAwait(false);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error sending anonymous usage statistics.");
}
}
public async void Run()
{
await Task.Delay(5000).ConfigureAwait(false);
OnTimerFired();
}
/// <summary>
/// Called when [timer fired].
/// </summary>
private async void OnTimerFired()
{
if (!_config.Configuration.EnableAnonymousUsageReporting)
{
return;
}
try
{
await new UsageReporter(_applicationHost, _httpClient, _logger)
.ReportServerUsage(CancellationToken.None)
.ConfigureAwait(false);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error sending anonymous usage statistics.");
}
}
public void Dispose()
{
_sessionManager.SessionStarted -= _sessionManager_SessionStarted;
}
}
}

@ -1,130 +0,0 @@
using MediaBrowser.Common;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Connect;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Controller;
using Microsoft.Extensions.Logging;
namespace Emby.Server.Implementations.EntryPoints
{
public class UsageReporter
{
private readonly IServerApplicationHost _applicationHost;
private readonly IHttpClient _httpClient;
private readonly ILogger _logger;
private const string MbAdminUrl = "https://www.mb3admin.local/admin/";
public UsageReporter(IServerApplicationHost applicationHost, IHttpClient httpClient, ILogger logger)
{
_applicationHost = applicationHost;
_httpClient = httpClient;
_logger = logger;
}
public async Task ReportServerUsage(CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
var data = new Dictionary<string, string>
{
{ "feature", _applicationHost.Name },
{ "mac", _applicationHost.SystemId },
{ "serverid", _applicationHost.SystemId },
{ "deviceid", _applicationHost.SystemId },
{ "ver", _applicationHost.ApplicationVersion.ToString() },
{ "platform", _applicationHost.OperatingSystemDisplayName }
};
data["plugins"] = string.Join(",", _applicationHost.Plugins.Select(i => i.Id).ToArray());
var logErrors = false;
#if DEBUG
logErrors = true;
#endif
var options = new HttpRequestOptions
{
Url = MbAdminUrl + "service/registration/ping",
CancellationToken = cancellationToken,
// Seeing block length errors
EnableHttpCompression = false,
LogRequest = false,
LogErrors = logErrors,
BufferContent = false
};
options.SetPostData(data);
using (var response = await _httpClient.SendAsync(options, "POST").ConfigureAwait(false))
{
}
}
public async Task ReportAppUsage(ClientInfo app, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(app.DeviceId))
{
throw new ArgumentException("Client info must have a device Id");
}
_logger.LogInformation("App Activity: app: {0}, version: {1}, deviceId: {2}, deviceName: {3}",
app.AppName ?? "Unknown App",
app.AppVersion ?? "Unknown",
app.DeviceId,
app.DeviceName ?? "Unknown");
cancellationToken.ThrowIfCancellationRequested();
var data = new Dictionary<string, string>
{
{ "feature", app.AppName ?? "Unknown App" },
{ "serverid", _applicationHost.SystemId },
{ "deviceid", app.DeviceId },
{ "mac", app.DeviceId },
{ "ver", app.AppVersion ?? "Unknown" },
{ "platform", app.DeviceName },
};
var logErrors = false;
#if DEBUG
logErrors = true;
#endif
var options = new HttpRequestOptions
{
Url = MbAdminUrl + "service/registration/ping",
CancellationToken = cancellationToken,
// Seeing block length errors
EnableHttpCompression = false,
LogRequest = false,
LogErrors = logErrors,
BufferContent = false
};
options.SetPostData(data);
using (var response = await _httpClient.SendAsync(options, "POST").ConfigureAwait(false))
{
}
}
}
public class ClientInfo
{
public string AppName { get; set; }
public string AppVersion { get; set; }
public string DeviceName { get; set; }
public string DeviceId { get; set; }
}
}

@ -175,7 +175,6 @@ namespace MediaBrowser.Model.Configuration
public int SchemaVersion { get; set; }
public bool EnableAnonymousUsageReporting { get; set; }
public bool EnableFolderView { get; set; }
public bool EnableGroupingIntoCollections { get; set; }
public bool DisplaySpecialsWithinSeasons { get; set; }
@ -221,7 +220,6 @@ namespace MediaBrowser.Model.Configuration
HttpsPortNumber = DefaultHttpsPort;
EnableHttps = true;
EnableDashboardResponseCaching = true;
EnableAnonymousUsageReporting = false;
EnableCaseSensitiveItemIds = true;
EnableAutomaticRestart = true;

Loading…
Cancel
Save