PC からサーバー上にあるプロセスのメモリ使用量を監視するアプリを開発しようとしています。アプリが実行されているのと同じ PC にあるプロセスのメモリ使用量を監視するアプリを作成しましたが、自分の PC からアプリを実行して別の PC/サーバーのプロセスを監視する方法がわかりません。
どんな助けでも、私を正しい道に導くのに役立ちます。
アップデート
これが私がこれまでに持っているものです:
private static string sProcName = "PCMain";
private static string machine = "serverName";
private static int sProcMemoryInKB = 10000;
static void Main(string[] args) {
VerifyRemoteMachineStatus(machine);
GetMachineName();
Process ReqProcess;
GC.GetTotalMemory(true);
ReqProcess = CurrentlyRunning(sProcName);
do {
if (ReqProcess != null) {
System.Threading.Thread.Sleep(1000);
// calculate the CPU load
System.TimeSpan CPULoad = (DateTime.Now - ReqProcess.StartTime);
Console.WriteLine("CPU Load: " + (ReqProcess.TotalProcessorTime.TotalMilliseconds / CPULoad.TotalMilliseconds) * 100);
PerformanceCounter WorkingSetMemoryCounter = new PerformanceCounter("Process", "Working Set", sProcName, machine);
//System.Threading.Thread.Sleep(1000);
Console.WriteLine("Momory (Working Set) " + (WorkingSetMemoryCounter.NextValue() / 1024) + "K");
PerformanceCounter WorkingSetPrivateMemoryCounter = new PerformanceCounter("Process", "Working Set - Private", ReqProcess.ProcessName, machine);
//System.Threading.Thread.Sleep(1000);
Console.WriteLine("Momory (Private Working Set) " + (WorkingSetPrivateMemoryCounter.NextValue() / 1024) + "K" + Environment.NewLine + Environment.NewLine);
//if ((WorkingSetMemoryCounter.NextValue() / 1024) >= sProcMemoryInKB) {
// SendMail();
//}
}
} while (true);
}
private static Process CurrentlyRunning(string sProcessName) {
//get a list of all running processes on current system
Process[] Processes = Process.GetProcesses();
//Iterate to every process to check if it is out required process
foreach (Process SingleProcess in Processes) {
if (SingleProcess.ProcessName.Contains(sProcessName)) {
//process found
return SingleProcess;
}
}
//Process not found
return null;
}
private static void GetMachineName() {
string[] cmdArgs = System.Environment.GetCommandLineArgs();
if ((cmdArgs != null) && (cmdArgs.Length > 1)) { machine = cmdArgs[1]; }
}
// ping the remote computer
private static bool VerifyRemoteMachineStatus(string machineName) {
try {
using (Ping ping = new Ping()) {
PingReply reply = ping.Send(machineName);
if (reply.Status == IPStatus.Success) { return true; }
}
} catch (Exception ex) {
// return false for any exception encountered
// we'll probably want to just shut down anyway
}
return false;
}