forked from kerryjiang/SuperSocket
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppDomainAppServer.StatusInfo.cs
More file actions
67 lines (57 loc) · 2.21 KB
/
Copy pathAppDomainAppServer.StatusInfo.cs
File metadata and controls
67 lines (57 loc) · 2.21 KB
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
64
65
66
67
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SuperSocket.SocketBase.Metadata;
using System.Diagnostics;
using SuperSocket.SocketBase;
namespace SuperSocket.SocketEngine
{
[StatusInfo(StatusInfoKeys.CpuUsage, Name = "CPU Usage", Format = "{0:0.00}%", DataType = typeof(double), Order = 112)]
[StatusInfo(StatusInfoKeys.MemoryUsage, Name = "Memory Usage", Format = "{0:0.00}%", DataType = typeof(double), Order = 113)]
partial class AppDomainAppServer
{
private static Process m_Process;
private readonly static bool m_AppDomainMonitoringSupported = false;
static AppDomainAppServer()
{
try
{
AppDomain.MonitoringIsEnabled = true;
m_AppDomainMonitoringSupported = true;
}
catch (NotImplementedException)
{
return;
}
m_Process = Process.GetCurrentProcess();
}
protected override bool StatusMetadataExtended
{
get
{
return m_AppDomainMonitoringSupported;
}
}
public override StatusInfoCollection CollectServerStatus(StatusInfoCollection nodeStatus)
{
var statusCollection = base.CollectServerStatus(nodeStatus);
if (!m_AppDomainMonitoringSupported)
return statusCollection;
if (statusCollection != null && m_HostDomain != null)
{
if (m_Process.TotalProcessorTime.TotalMilliseconds > 0)
{
var value = m_HostDomain.MonitoringTotalProcessorTime.TotalMilliseconds * 100 / m_Process.TotalProcessorTime.TotalMilliseconds;
statusCollection[StatusInfoKeys.CpuUsage] = value;
}
if (AppDomain.MonitoringSurvivedProcessMemorySize > 0)
{
var value = (double)m_HostDomain.MonitoringSurvivedMemorySize * 100 / (double)AppDomain.MonitoringSurvivedProcessMemorySize;
statusCollection[StatusInfoKeys.MemoryUsage] = (double)value;
}
}
return statusCollection;
}
}
}