/
AdminDashboardService.cs
63 lines (55 loc) · 2.01 KB
/
AdminDashboardService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System.Collections.Generic;
using ServiceStack.DataAnnotations;
using ServiceStack.Messaging;
using ServiceStack.Redis;
namespace ServiceStack.Admin;
[ExcludeMetadata, Tag(TagNames.Admin)]
public class AdminDashboard : IGet, IReturn<AdminDashboardResponse> {}
public class AdminDashboardResponse : IHasResponseStatus
{
public ServerStats ServerStats { get; set; }
public ResponseStatus ResponseStatus { get; set; }
}
public class ServerStats
{
public Dictionary<string, long> Redis { get; set; }
public Dictionary<string, string> ServerEvents { get; set; }
public string MqDescription { get; set; }
public Dictionary<string, long> MqWorkers { get; set; }
}
[DefaultRequest(typeof(AdminDashboard))]
public class AdminDashboardService : Service
{
public object Any(AdminDashboard request)
{
var mqServer = TryResolve<IMessageService>();
var mqWorker = mqServer?.GetStats();
var stats = new ServerStats {
Redis = (TryResolve<IRedisClientsManager>() as IHasStats)?.Stats,
ServerEvents = TryResolve<IServerEvents>()?.GetStats(),
MqDescription = mqServer?.GetStatsDescription(),
MqWorkers = mqWorker.ToDictionary(),
};
return new AdminDashboardResponse
{
ServerStats = stats,
};
}
}
public static class AdminDashboardUtils
{
public static Dictionary<string, long> ToDictionary(this IMessageHandlerStats stats)
{
if (stats == null)
return null;
var to = new Dictionary<string, long>
{
[nameof(stats.TotalMessagesProcessed)] = stats.TotalMessagesProcessed,
[nameof(stats.TotalMessagesFailed)] = stats.TotalMessagesFailed,
[nameof(stats.TotalRetries)] = stats.TotalRetries,
[nameof(stats.TotalNormalMessagesReceived)] = stats.TotalNormalMessagesReceived,
[nameof(stats.TotalPriorityMessagesReceived)] = stats.TotalPriorityMessagesReceived,
};
return to;
}
}