Skip to content

Commit

Permalink
Add built-in awaiting metric for monitoring stats
Browse files Browse the repository at this point in the history
  • Loading branch information
odinserj committed Jan 25, 2023
1 parent af9c7e6 commit e9d018c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/Hangfire.Core/Dashboard/DashboardMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,18 @@ public static IEnumerable<DashboardMetric> GetMetrics()
{
long awaitingCount = -1;

using (var connection = page.Storage.GetReadOnlyConnection())
if (page.Statistics.Awaiting.HasValue)
{
if (connection is JobStorageConnection storageConnection)
awaitingCount = page.Statistics.Awaiting.Value;
}
else
{
using (var connection = page.Storage.GetReadOnlyConnection())
{
awaitingCount = storageConnection.GetSetCount("awaiting");
if (connection is JobStorageConnection storageConnection)
{
awaitingCount = storageConnection.GetSetCount("awaiting");
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/Hangfire.Core/Storage/Monitoring/StatisticsDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ public class StatisticsDto
public long Failed { get; set; }
public long Deleted { get; set; }
public long? Retries { get; set; }
public long? Awaiting { get; set; }
}
}
2 changes: 2 additions & 0 deletions src/Hangfire.SqlServer/SqlServerMonitoringApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ public override StatisticsDto GetStatistics()
select count(Id) from [{0}].Job with (nolock, forceseek) where StateName = N'Failed';
select count(Id) from [{0}].Job with (nolock, forceseek) where StateName = N'Processing';
select count(Id) from [{0}].Job with (nolock, forceseek) where StateName = N'Scheduled';
select count(Id) from [{0}].Job with (nolock, forceseek) where StateName = N'Awaiting';
select count(Id) from [{0}].Server with (nolock);
select sum(s.[Value]) from (
select sum([Value]) as [Value] from [{0}].Counter with (nolock, forceseek) where [Key] = N'stats:succeeded'
Expand All @@ -433,6 +434,7 @@ union all
stats.Failed = multi.ReadSingle<int>();
stats.Processing = multi.ReadSingle<int>();
stats.Scheduled = multi.ReadSingle<int>();
stats.Awaiting = multi.ReadSingle<int>();

stats.Servers = multi.ReadSingle<int>();

Expand Down

0 comments on commit e9d018c

Please sign in to comment.