How to get Memory usage size of each services running on Application Server using C#.net
-
Do you mean you want to write your own program or do you want a tool that will display the information to you?
-
I want to write a program in C# that should display all services memory usage which is running on particular application server using C#.net.
In which case start by looking at WMI, you can get the WMICodeCreator from Miscrosoft site which will let you select WMI Objects, view them and their properties and write the code to do the same that you can cut and paste into your application. For instance:
using System;
using System.Management;
using System.Windows.Forms;namespace WMISample
{
public class MyWMIQuery
{
public static void Main()
{
try
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_Service");ManagementObjectSearcher procsearcher = new ManagementObjectSearcher("root\\\\CIMV2", "SELECT \* FROM Win32\_Process"); String q; foreach (ManagementObject queryObj in searcher.Get()) { if (queryObj\["ProcessId"\].ToString() != "0") { Console.WriteLine("-----------------------------------"); q = "SELECT \* FROM Win32\_Process WHERE ProcessId="; q += queryObj\["ProcessId"\].ToString(); procsearcher.Query = new System.Management.ObjectQuery(q); foreach (ManagementObject ProcObj in procsearcher.Get()) { Console.WriteLine("Name: {0} : {1}", queryObj\["Name"\], ProcObj\["WorkingSetSize"\]); } } } } catch (ManagementException e) { MessageBox.Show("An error occurred while querying for WMI data: " + e.Message); } } }
}
You can also get the ProcessId which will be non-zero if the service is running, using the ProcessId you can query WMI to get the process information. Updated the code to get the memory for running Services.
-
In which case start by looking at WMI, you can get the WMICodeCreator from Miscrosoft site which will let you select WMI Objects, view them and their properties and write the code to do the same that you can cut and paste into your application. For instance:
using System;
using System.Management;
using System.Windows.Forms;namespace WMISample
{
public class MyWMIQuery
{
public static void Main()
{
try
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_Service");ManagementObjectSearcher procsearcher = new ManagementObjectSearcher("root\\\\CIMV2", "SELECT \* FROM Win32\_Process"); String q; foreach (ManagementObject queryObj in searcher.Get()) { if (queryObj\["ProcessId"\].ToString() != "0") { Console.WriteLine("-----------------------------------"); q = "SELECT \* FROM Win32\_Process WHERE ProcessId="; q += queryObj\["ProcessId"\].ToString(); procsearcher.Query = new System.Management.ObjectQuery(q); foreach (ManagementObject ProcObj in procsearcher.Get()) { Console.WriteLine("Name: {0} : {1}", queryObj\["Name"\], ProcObj\["WorkingSetSize"\]); } } } } catch (ManagementException e) { MessageBox.Show("An error occurred while querying for WMI data: " + e.Message); } } }
}
You can also get the ProcessId which will be non-zero if the service is running, using the ProcessId you can query WMI to get the process information. Updated the code to get the memory for running Services.
-
i just run your code. Some error came (The type or namespace name 'ManagementObjectSearcher' could not be found). i want to get All Services memory usage running on Application Server in local system using C#. How to achieve this. Please reply me.
Did you add system.management and system.management.instrumentation as references to your project? From Project menu select Add Reference, in the resulting dialogue click the .Net tab and scroll to locate the System.Management and add it to your project, same again for .Instrumentation. FYI. I updated the code in previous reply to get the memory for the process as well.
-
i just run your code. Some error came (The type or namespace name 'ManagementObjectSearcher' could not be found). i want to get All Services memory usage running on Application Server in local system using C#. How to achieve this. Please reply me.
Repeating your question isn't going to get you any faster help. When you encounter an error like this, a quick Google search is enough to find out which DLL you need to reference.
-
Did you add system.management and system.management.instrumentation as references to your project? From Project menu select Add Reference, in the resulting dialogue click the .Net tab and scroll to locate the System.Management and add it to your project, same again for .Instrumentation. FYI. I updated the code in previous reply to get the memory for the process as well.
Hi, I added the reference and is working. [Workingsetsize] means usage memory size or allocated size and this will be for checking in local system no. If i want to check the memory usage of services which are running in Application server from my local system, how can i achieve. how to specify app server from my local system through this code and get memory usage of services of that app server. Please reply me.
-
Repeating your question isn't going to get you any faster help. When you encounter an error like this, a quick Google search is enough to find out which DLL you need to reference.
I added the reference and is working. [Workingsetsize] means usage memory size or allocated size and this will be for checking in local system no. If i want to check the memory usage of services which are running in Application server from my local system, how can i achieve. how to specify app server from my local system through this code and get memory usage of services of that app server. Please reply me.
-
Did you add system.management and system.management.instrumentation as references to your project? From Project menu select Add Reference, in the resulting dialogue click the .Net tab and scroll to locate the System.Management and add it to your project, same again for .Instrumentation. FYI. I updated the code in previous reply to get the memory for the process as well.
-
Hi, how to specify app server IP and service name (If possible) from my local system through this code and get memory usage of services of that app server. How to achieve this. Please reply me.
Use Google.
-
I added the reference and is working. [Workingsetsize] means usage memory size or allocated size and this will be for checking in local system no. If i want to check the memory usage of services which are running in Application server from my local system, how can i achieve. how to specify app server from my local system through this code and get memory usage of services of that app server. Please reply me.
Look here [^] Learn to use Google.