|
@@ -5,6 +5,7 @@ using MECF.Framework.Common.Equipment;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Diagnostics;
|
|
|
+using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Reflection;
|
|
|
using System.ServiceModel.Channels;
|
|
@@ -61,34 +62,35 @@ namespace Venus_RT.Modules
|
|
|
string Occupytime = string.Empty;
|
|
|
string PrivilegeOccupancytime = string.Empty;
|
|
|
string Useroccupiedtime = string.Empty;
|
|
|
+ PerformanceCounter CpuOccupied = new PerformanceCounter("Processor", "% Processor Time", "_Total");
|
|
|
public ResourceMonitor()
|
|
|
{
|
|
|
|
|
|
//ProcessName = "进程名称";
|
|
|
//ProcessID = "进程ID".PadRight(_stringlen - 2, ' ');
|
|
|
//Starttime = "启动时间";
|
|
|
- Response = "是否响应";
|
|
|
- MainWindowHandle = "主窗口句柄";
|
|
|
+ Response = "Response or not";
|
|
|
+ MainWindowHandle = "Main Window Handle";
|
|
|
//MainWindowTitle = "主窗口标题";
|
|
|
- AssociatedProcessHandle = "关联进程句柄";
|
|
|
- Numberofhandlesopened = "进程打开的句柄数";
|
|
|
- Numberofmodules = "模块数量";
|
|
|
- Basicpriority = "基本优先级";
|
|
|
- Increasepriority = "提升优先级";
|
|
|
- processor = "处理器";
|
|
|
- Minimumworkingset = "最小工作集";
|
|
|
- MaximumWorkingSet = "最大工作集";
|
|
|
- Workset = "工作集";
|
|
|
- Peakworkingset = "峰值工作集";
|
|
|
- Dedicatedmemorysize = "专用内存大小";
|
|
|
- UnpagedMemorySize = "未分页内存大小";
|
|
|
- PagingMemorySize = "分页内存大小";
|
|
|
- Peakpagingmemorysize = "峰值分页内存大小";
|
|
|
- VirtualMemorySize = "虚拟内存大小";
|
|
|
- PeakVirtualMemorySize = "峰值虚拟内存大小";
|
|
|
- Occupytime = "占用时间";
|
|
|
- PrivilegeOccupancytime = "特权占用时间";
|
|
|
- Useroccupiedtime = "用户占用时间";
|
|
|
+ AssociatedProcessHandle = "Associated Process Handle ";
|
|
|
+ Numberofhandlesopened = "Number of handles opened ";
|
|
|
+ Numberofmodules = "Number of modules ";
|
|
|
+ Basicpriority = "Basic priority ";
|
|
|
+ Increasepriority = "Increase priority ";
|
|
|
+ processor = "processor ";
|
|
|
+ Minimumworkingset = "Minimum working set ";
|
|
|
+ MaximumWorkingSet = "Maximum working Set ";
|
|
|
+ Workset = "Work set ";
|
|
|
+ Peakworkingset = "Peak working set ";
|
|
|
+ Dedicatedmemorysize = "Dedicated memory size ";
|
|
|
+ UnpagedMemorySize = "Unpaged Memory Size ";
|
|
|
+ PagingMemorySize = "Paging Memory Size ";
|
|
|
+ Peakpagingmemorysize = "Peak paging memory size ";
|
|
|
+ VirtualMemorySize = "Virtual Memory Size ";
|
|
|
+ PeakVirtualMemorySize = "Peak Virtual Memory Size ";
|
|
|
+ Occupytime = "Occupy time ";
|
|
|
+ PrivilegeOccupancytime = "Privilege Occupancy time ";
|
|
|
+ Useroccupiedtime = "User occupied time ";
|
|
|
|
|
|
}
|
|
|
|
|
@@ -104,7 +106,7 @@ namespace Venus_RT.Modules
|
|
|
{
|
|
|
_timer = new Timer();
|
|
|
_timer.Enabled = true;
|
|
|
- _timer.Interval = SC.GetValue<int>("System.CheckResourceInterval") * 1000;
|
|
|
+ _timer.Interval = SC.GetValue<int>("System.CheckResourceInterval") * 60 * 1000;
|
|
|
_timer.Elapsed += GetProcessInfo;
|
|
|
_timer.Start();
|
|
|
//LOG.Write($"{ProcessName}" +
|
|
@@ -161,6 +163,20 @@ namespace Venus_RT.Modules
|
|
|
//_VirtualMemorySize.Add(Convert.ToInt32(pro.VirtualMemorySize64 / 1024)); //虚拟内存大小
|
|
|
//_PeakVirtualMemorySize.Add(Convert.ToInt32(pro.PeakVirtualMemorySize64 / 1048576)); //峰值虚拟内存大小
|
|
|
|
|
|
+ float cpu_use_per = CpuOccupied.NextValue();
|
|
|
+ string cpu_use = $"CPU usage rate:{cpu_use_per:F2}%\t";
|
|
|
+ string drive_use = "";
|
|
|
+ foreach (DriveInfo drive in DriveInfo.GetDrives())
|
|
|
+ {
|
|
|
+ if (drive.IsReady)
|
|
|
+ {
|
|
|
+ drive_use += $"{drive.Name}";
|
|
|
+ drive_use += $" Total:{drive.TotalSize / 1024 / 1024 / 1024}GB";
|
|
|
+ drive_use += $" Used:{(drive.TotalSize - drive.AvailableFreeSpace) / 1024 / 1024 / 1024}GB";
|
|
|
+ drive_use += $" Free:{drive.AvailableFreeSpace / 1024 / 1024 / 1024}GB\t";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
LOG.Write(eEvent.INFO_WINRESOURCE, ModuleName.System,
|
|
|
//$"{ProcessName}:{pro.ProcessName}" +
|
|
|
//$"{pro.StartTime.ToLongDateString() + pro.StartTime.ToLongTimeString()}" +
|
|
@@ -177,16 +193,18 @@ namespace Venus_RT.Modules
|
|
|
$"{MaximumWorkingSet}:{pro.MaxWorkingSet.ToInt32().ToString()}\t" +
|
|
|
$"{Workset}:{pro.WorkingSet64.ToString()}\t" +
|
|
|
$"{Peakworkingset}:{pro.PeakWorkingSet64.ToString()}\t" +
|
|
|
- $"{Dedicatedmemorysize}:{(pro.PrivateMemorySize64 / 1048576).ToString()}\t" +
|
|
|
- $"{UnpagedMemorySize}:{(pro.NonpagedSystemMemorySize64 / 1048576).ToString()}\t" +
|
|
|
- $"{PagingMemorySize}:{(pro.PagedMemorySize64 / 1048576).ToString()}\t" +
|
|
|
- $"{Peakpagingmemorysize}:{(pro.PeakPagedMemorySize64 / 1048576).ToString()}\t" +
|
|
|
- $"{VirtualMemorySize}:{(pro.VirtualMemorySize64 / 1048576).ToString()}\t" +
|
|
|
- $"{PeakVirtualMemorySize}:{(pro.PeakVirtualMemorySize64 / 1048576).ToString()}\t" +
|
|
|
+ $"{Dedicatedmemorysize}:{(pro.PrivateMemorySize64 / 1048576).ToString()}MB\t" +
|
|
|
+ $"{UnpagedMemorySize}:{(pro.NonpagedSystemMemorySize64 / 1048576).ToString()}MB\t" +
|
|
|
+ $"{PagingMemorySize}:{(pro.PagedMemorySize64 / 1048576).ToString()}MB\t" +
|
|
|
+ $"{Peakpagingmemorysize}:{(pro.PeakPagedMemorySize64 / 1048576).ToString()}MB\t" +
|
|
|
+ $"{VirtualMemorySize}:{(pro.VirtualMemorySize64 / 1048576).ToString()}MB\t" +
|
|
|
+ $"{PeakVirtualMemorySize}:{(pro.PeakVirtualMemorySize64 / 1048576).ToString()}MB\t" +
|
|
|
$"{Occupytime}:{pro.TotalProcessorTime.ToString()}\t" +
|
|
|
$"{PrivilegeOccupancytime}:{pro.PrivilegedProcessorTime.ToString()}\t" +
|
|
|
- $"{Useroccupiedtime}:{pro.UserProcessorTime.ToString()}\t");
|
|
|
-
|
|
|
+ $"{Useroccupiedtime}:{pro.UserProcessorTime.ToString()}\t" +
|
|
|
+ $"| PC => {drive_use}"+
|
|
|
+ $"{cpu_use}");
|
|
|
+
|
|
|
//如果虚拟内存大于800MB 即报警
|
|
|
if (pro.PagedMemorySize64 / 1048576 >= threshold)
|
|
|
{
|
|
@@ -195,6 +213,7 @@ namespace Venus_RT.Modules
|
|
|
}
|
|
|
}
|
|
|
//没有就不做任何操作
|
|
|
+
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|