Add stream host to stats

This commit is contained in:
genteure 2022-06-29 19:46:58 +08:00
parent bcc39843c1
commit cbcbd840f0
9 changed files with 59 additions and 5 deletions

View File

@ -4,6 +4,11 @@ namespace BililiveRecorder.Core.Event
{
public sealed class IOStatsEventArgs : EventArgs
{
/// <summary>
/// 直播服务器域名
/// </summary>
public string? StreamHost { get; set; }
/// <summary>
/// 当前统计区间的开始时间
/// </summary>

View File

@ -157,6 +157,7 @@ namespace BililiveRecorder.Core.Recording
this.OnIOStats(new IOStatsEventArgs
{
StreamHost = streamHost,
NetworkBytesDownloaded = networkDownloadBytes,
Duration = durationDiff,
StartTime = startTime,

View File

@ -353,6 +353,7 @@ namespace BililiveRecorder.Core
{
this.logger.Verbose("IO stats: {@stats}", e);
this.Stats.StreamHost = e.StreamHost;
this.Stats.StartTime = e.StartTime;
this.Stats.EndTime = e.EndTime;
this.Stats.Duration = e.Duration;

View File

@ -9,6 +9,7 @@ namespace BililiveRecorder.Core
public class RoomStats : INotifyPropertyChanged
{
#region IO Stats Fields
private string? ___StreamHost;
private DateTimeOffset ___StartTime;
private DateTimeOffset ___EndTime;
private TimeSpan ___Duration;
@ -54,6 +55,11 @@ namespace BililiveRecorder.Core
#region IO Stats Properties
/// <summary>
/// 直播服务器域名
/// </summary>
public string? StreamHost { get => this.___StreamHost; set => this.SetField(ref this.___StreamHost, value); }
/// <summary>
/// 当前统计区间的开始时间
/// </summary>
@ -207,6 +213,8 @@ namespace BililiveRecorder.Core
// ------------------------------
this.StreamHost = null;
this.StartTime = default;
this.EndTime = default;
this.Duration = default;

View File

@ -33,6 +33,7 @@
<TextBlock Visibility="{Binding Stats.DurationRatio,Converter={StaticResource IsNaNToVisibilityCollapsedConverter}}"
TextAlignment="Center" Text="{l:Loc RoomCard_Status_SpeedIndicator_NoData}"/>
<StackPanel Visibility="{Binding Stats.DurationRatio,Converter={StaticResource InvertIsNaNToVisibilityCollapsedConverter}}">
<TextBlock Text="{Binding Stats.StreamHost,StringFormat=直播服务器: {0}}"/>
<TextBlock>
<TextBlock.Text>
<MultiBinding Converter="{l:StringFormatConverter}">

View File

@ -11,7 +11,7 @@
l:ResxLocalizationProvider.DefaultDictionary="Strings"
xmlns:local="clr-namespace:BililiveRecorder.WPF.Controls"
xmlns:core="clr-namespace:BililiveRecorder.Core;assembly=BililiveRecorder.Core"
d:DataContext="{d:DesignInstance core:Room}"
d:DataContext="{d:DesignInstance core:IRoom}"
d:DesignWidth="220" d:DesignHeight="110"
mc:Ignorable="d">
<Border Background="{DynamicResource SystemControlBackgroundAltHighBrush}"

View File

@ -145,14 +145,14 @@ namespace BililiveRecorder.Web.Api
#region Get Room Stats
/// <summary>
/// 读取直播间统计信息
/// 读取直播间录制统计信息
/// </summary>
/// <param name="roomId"></param>
/// <returns></returns>
[HttpGet("{roomId:int}/stats")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(typeof(RestApiError), StatusCodes.Status404NotFound)]
public ActionResult<RoomRecordingStatsDto> GetRoomStats(int roomId)
public ActionResult<RoomRecordingStatsDto> GetRoomRecordingStats(int roomId)
{
var room = this.FetchRoom(roomId);
if (room is null)
@ -161,14 +161,14 @@ namespace BililiveRecorder.Web.Api
}
/// <summary>
/// 读取直播间统计信息
/// 读取直播间录制统计信息
/// </summary>
/// <param name="objectId"></param>
/// <returns></returns>
[HttpGet("{objectId:guid}/stats")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(typeof(RestApiError), StatusCodes.Status404NotFound)]
public ActionResult<RoomRecordingStatsDto> GetRoomStats(Guid objectId)
public ActionResult<RoomRecordingStatsDto> GetRoomRecordingStats(Guid objectId)
{
var room = this.FetchRoom(objectId);
if (room is null)
@ -176,6 +176,38 @@ namespace BililiveRecorder.Web.Api
return this.mapper.Map<RoomRecordingStatsDto>(room.Stats);
}
/// <summary>
/// 读取直播间 IO 统计信息
/// </summary>
/// <param name="roomId"></param>
/// <returns></returns>
[HttpGet("{roomId:int}/ioStats")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(typeof(RestApiError), StatusCodes.Status404NotFound)]
public ActionResult<RoomIOStatsDto> GetRoomIOStats(int roomId)
{
var room = this.FetchRoom(roomId);
if (room is null)
return this.NotFound(new RestApiError { Code = RestApiErrorCode.RoomNotFound, Message = "Room not found" });
return this.mapper.Map<RoomIOStatsDto>(room.Stats);
}
/// <summary>
/// 读取直播间 IO 统计信息
/// </summary>
/// <param name="objectId"></param>
/// <returns></returns>
[HttpGet("{objectId:guid}/ioStats")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(typeof(RestApiError), StatusCodes.Status404NotFound)]
public ActionResult<RoomIOStatsDto> GetRoomIOStats(Guid objectId)
{
var room = this.FetchRoom(objectId);
if (room is null)
return this.NotFound(new RestApiError { Code = RestApiErrorCode.RoomNotFound, Message = "Room not found" });
return this.mapper.Map<RoomIOStatsDto>(room.Stats);
}
#endregion
#region Room Config

View File

@ -7,6 +7,7 @@ namespace BililiveRecorder.Web.Models.Graphql
{
public IOStatsType()
{
this.Field(x => x.StreamHost, nullable: true);
this.Field(x => x.StartTime);
this.Field(x => x.EndTime);
this.Field(x => x.Duration, type: typeof(TimeSpanMillisecondsGraphType));

View File

@ -4,6 +4,11 @@ namespace BililiveRecorder.Web.Models.Rest
{
public class RoomIOStatsDto
{
/// <summary>
/// 直播服务器域名
/// </summary>
public string? StreamHost { get; set; }
/// <summary>
/// 当前统计区间的开始时间
/// </summary>