mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-09-17 17:14:18 +02:00
Basic Indexer Statistics Endpoint
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net462;netcoreapp3.1</TargetFrameworks>
|
||||
<NeutralLanguage>en</NeutralLanguage>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DotNet4.SocksProxy" Version="1.4.0.1" />
|
||||
|
@@ -1,7 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using NzbDrone.Core.Indexers;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.ThingiProvider.Events;
|
||||
|
||||
|
@@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Composition;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
|
@@ -1,9 +1,3 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NzbDrone.Core.Applications.Lidarr
|
||||
{
|
||||
public class LidarrField
|
||||
|
@@ -1,9 +1,3 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NzbDrone.Core.Applications.Radarr
|
||||
{
|
||||
public class RadarrField
|
||||
|
@@ -1,9 +1,3 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NzbDrone.Core.Applications.Readarr
|
||||
{
|
||||
public class ReadarrField
|
||||
|
@@ -1,9 +1,3 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NzbDrone.Core.Applications.Sonarr
|
||||
{
|
||||
public class SonarrField
|
||||
|
11
src/NzbDrone.Core/IndexerStats/IndexerStatistics.cs
Normal file
11
src/NzbDrone.Core/IndexerStats/IndexerStatistics.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using NzbDrone.Core.Datastore;
|
||||
|
||||
namespace NzbDrone.Core.IndexerStats
|
||||
{
|
||||
public class IndexerStatistics : ResultSet
|
||||
{
|
||||
public int IndexerId { get; set; }
|
||||
public int AverageResponseTime { get; set; }
|
||||
public int NumberOfQueries { get; set; }
|
||||
}
|
||||
}
|
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Dapper;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Indexers;
|
||||
|
||||
namespace NzbDrone.Core.IndexerStats
|
||||
{
|
||||
public interface IIndexerStatisticsRepository
|
||||
{
|
||||
List<IndexerStatistics> IndexerStatistics();
|
||||
}
|
||||
|
||||
public class IndexerStatisticsRepository : IIndexerStatisticsRepository
|
||||
{
|
||||
private const string _selectTemplate = "SELECT /**select**/ FROM History /**join**/ /**innerjoin**/ /**leftjoin**/ /**where**/ /**groupby**/ /**having**/ /**orderby**/";
|
||||
|
||||
private readonly IMainDatabase _database;
|
||||
|
||||
public IndexerStatisticsRepository(IMainDatabase database)
|
||||
{
|
||||
_database = database;
|
||||
}
|
||||
|
||||
public List<IndexerStatistics> IndexerStatistics()
|
||||
{
|
||||
var time = DateTime.UtcNow;
|
||||
return Query(Builder());
|
||||
}
|
||||
|
||||
public List<IndexerStatistics> IndexerStatistics(int indexerId)
|
||||
{
|
||||
var time = DateTime.UtcNow;
|
||||
return Query(Builder().Where<IndexerDefinition>(x => x.Id == indexerId));
|
||||
}
|
||||
|
||||
private List<IndexerStatistics> Query(SqlBuilder builder)
|
||||
{
|
||||
var sql = builder.AddTemplate(_selectTemplate).LogQuery();
|
||||
|
||||
using (var conn = _database.OpenConnection())
|
||||
{
|
||||
return conn.Query<IndexerStatistics>(sql.RawSql, sql.Parameters).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
private SqlBuilder Builder() => new SqlBuilder()
|
||||
.Select(@"Indexers.Id AS IndexerId,
|
||||
COUNT(History.Id) AS NumberOfQueries,
|
||||
AVG(json_extract(History.Data,'$.elapsedTime')) AS AverageResponseTime")
|
||||
.Join<History.History, IndexerDefinition>((t, r) => t.IndexerId == r.Id)
|
||||
.GroupBy<IndexerDefinition>(x => x.Id);
|
||||
}
|
||||
}
|
27
src/NzbDrone.Core/IndexerStats/IndexerStatisticsService.cs
Normal file
27
src/NzbDrone.Core/IndexerStats/IndexerStatisticsService.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace NzbDrone.Core.IndexerStats
|
||||
{
|
||||
public interface IIndexerStatisticsService
|
||||
{
|
||||
List<IndexerStatistics> IndexerStatistics();
|
||||
}
|
||||
|
||||
public class IndexerStatisticsService : IIndexerStatisticsService
|
||||
{
|
||||
private readonly IIndexerStatisticsRepository _indexerStatisticsRepository;
|
||||
|
||||
public IndexerStatisticsService(IIndexerStatisticsRepository indexerStatisticsRepository)
|
||||
{
|
||||
_indexerStatisticsRepository = indexerStatisticsRepository;
|
||||
}
|
||||
|
||||
public List<IndexerStatistics> IndexerStatistics()
|
||||
{
|
||||
var seasonStatistics = _indexerStatisticsRepository.IndexerStatistics();
|
||||
|
||||
return seasonStatistics.ToList();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,6 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using FluentValidation;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Annotations;
|
||||
|
@@ -1,8 +1,3 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NzbDrone.Core.Messaging.Commands;
|
||||
|
||||
namespace NzbDrone.Core.Indexers.Definitions.Cardigann
|
||||
|
@@ -1,5 +1,4 @@
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace NzbDrone.Core.Indexers.Cardigann
|
||||
|
@@ -4,7 +4,6 @@ using System.Linq;
|
||||
using FluentValidation.Results;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Annotations;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
@@ -2,8 +2,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using NzbDrone.Core.Indexers.Cardigann;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
namespace NzbDrone.Core.Indexers
|
||||
{
|
||||
|
@@ -2,6 +2,7 @@
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFrameworks>net462;netcoreapp3.1</TargetFrameworks>
|
||||
<NeutralLanguage>en</NeutralLanguage>
|
||||
<RuntimeIdentifiers>win-x64</RuntimeIdentifiers>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ApplicationIcon>..\NzbDrone.Host\Prowlarr.ico</ApplicationIcon>
|
||||
|
27
src/Prowlarr.Api.V1/Indexers/IndexerStatsModule.cs
Normal file
27
src/Prowlarr.Api.V1/Indexers/IndexerStatsModule.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NzbDrone.Core.IndexerStats;
|
||||
using Prowlarr.Http;
|
||||
|
||||
namespace Prowlarr.Api.V1.Indexers
|
||||
{
|
||||
public class IndexerStatsModule : ProwlarrRestModule<IndexerStatsResource>
|
||||
{
|
||||
private readonly IIndexerStatisticsService _indexerStatisticsService;
|
||||
|
||||
public IndexerStatsModule(IIndexerStatisticsService indexerStatisticsService)
|
||||
{
|
||||
_indexerStatisticsService = indexerStatisticsService;
|
||||
|
||||
GetResourceAll = GetAll;
|
||||
}
|
||||
|
||||
private List<IndexerStatsResource> GetAll()
|
||||
{
|
||||
return _indexerStatisticsService.IndexerStatistics().ToResource();
|
||||
}
|
||||
}
|
||||
}
|
37
src/Prowlarr.Api.V1/Indexers/IndexerStatsResource.cs
Normal file
37
src/Prowlarr.Api.V1/Indexers/IndexerStatsResource.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.IndexerStats;
|
||||
using Prowlarr.Http.REST;
|
||||
|
||||
namespace Prowlarr.Api.V1.Indexers
|
||||
{
|
||||
public class IndexerStatsResource : RestResource
|
||||
{
|
||||
public int IndexerId { get; set; }
|
||||
public int NumberOfQueries { get; set; }
|
||||
public int AverageResponseTime { get; set; }
|
||||
}
|
||||
|
||||
public static class IndexerStatsResourceMapper
|
||||
{
|
||||
public static IndexerStatsResource ToResource(this IndexerStatistics model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new IndexerStatsResource
|
||||
{
|
||||
IndexerId = model.IndexerId,
|
||||
NumberOfQueries = model.NumberOfQueries,
|
||||
AverageResponseTime = model.AverageResponseTime
|
||||
};
|
||||
}
|
||||
|
||||
public static List<IndexerStatsResource> ToResource(this IEnumerable<IndexerStatistics> models)
|
||||
{
|
||||
return models.Select(ToResource).ToList();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user