// Server. csnamespace Microshaoft. remotingObjects. server {using System; using System. threading; using System. collections; using System. runtime. remoting; using System. runtime. remoting. channels; using System. runtime. remoting. channels. tcp; using System. runtime. serialization. formatters; using System. serviceProcess; using System. componentModel; using System. configuration. install; using System. security. pr Incipal; using Microshaoft. remotingObjects. serviceContracts. share; using Microshaoft. win32; using Microshaoft; public class ServiceHost: ServiceBase {// <summary> // main entry point of the application. /// </Summary> // [STAThread] public static readonly string serviceName = "eHome Remoting PerfMon Service"; static void Main (string [] args) {// Microshaoft TODO: Add code here to start the application // Microshaoft ServiceHost service = new ServiceHost (); int l = 0; bool needFreeConsole = false; if (args! = Null) {l = args. length;} if (l> 0) {if (args [0]. toLower () = "/console") {needFreeConsole = true; NativeMethods. allocConsole (); Console. title = "Server... "; Console. writeLine ("Alloc Console... "); Console. writeLine ("Current User Identity: {0}", WindowsIdentity. getCurrent (). name); Console. writeLine (". net Framework version: {0} ", Environment. version. toString ();} Console. title = "Server ";// You cannot run the Console as a service. writeLine ("Console"); service. onStart (null); Console. readLine (); return;} Console. writeLine ("Service"); ServiceBase. run (service); if (needFreeConsole) {Console. writeLine ("Free Console... "); NativeMethods. freeConsole () ;}} public ServiceHost () {CanPauseAndContinue = true; ServiceName = ServiceHost. serviceName;} protected override void OnStart (string [] args) {Console. writeLine (Environment. version. toString (); RemotingHelper. startRemoting <remotingjavascemonitor> ("perfmonurl", 8082) ;}[ RunInstallerAttribute (true)] public class ProjectInstaller: Installer {private ServiceInstaller serviceInstaller; private ServiceProcessInstaller processInstaller; public ProjectInstaller () {processInstaller = new ServiceProcessInstaller (); serviceInstaller = new ServiceInsta Roller (); // Service will run under system account processInstaller. account = ServiceAccount. localSystem; // Service will have Start Type of Manual serviceInstaller. startType = ServiceStartMode. manual; serviceInstaller. serviceName = ServiceHost. serviceName; Installers. add (serviceInstaller); Installers. add (processInstaller) ;}} namespace Microshaoft. win32 {using System. runtime. interopServices; publi C class NativeMethods {// <summary> // start the console /// </summary> /// <returns> </returns> [DllImport ("kernel32.dll")] public static extern bool AllocConsole (); /// <summary> // release the console /// </summary> /// <returns> </returns> [DllImport ("kernel32.dll")] public static extern bool FreeConsole () ;}} namespace Microshaoft. remotingObjects {using System; using System. IO; using System. net; using System. web; usi Ng System. text; using System. threading; using System. configuration; using System. collections. generic; using System. diagnostics; using System. globalization; using Microshaoft. remotingObjects. server; using Microshaoft. remotingObjects. serviceContracts. share; public class remotinginclucemonitor: inclualbyrefobject, iremotinginclucemonitor {public string [] ReadAllInstancePe RformanceCounterNextValue (string categoryName, string [] instanceNamesFilter, string [] countersName) {try {PerformanceCounterCategory pcc = new PerformanceCounterCategory (categoryName); string [] instances = pcc. getInstanceNames (); List <string> list = new List <string> (); foreach (string instanceNameFilter in instanceNamesFilter) {// f = instanceNameFilter. toLower (); foreach (string s in instances) {String instance = ""; if (string. isNullOrEmpty (instanceNameFilter) {instance = s;} else {if (s. toLower (). indexOf (instanceNameFilter. toLower ()> = 0) {instance = s; Console. writeLine (instance) ;}} if (! String. isNullOrEmpty (instance) {foreach (string counterName in countersName) {string [] l = ReadInstancePerformanceCounterNextValue (categoryName, instance, counterName); if (l. length> 0) {list. addRange (l) ;}}} return list. toArray ();} catch (Exception e) {Console. writeLine (e); return null;} public string [] ReadAllInstanceAllPerformanceCounterNextValue (string categoryName, string insta NceNameFilter) {try {PerformanceCounterCategory pcc = new PerformanceCounterCategory (categoryName); string [] instances = pcc. getInstanceNames (); List <string> list = new List <string> (); instanceNameFilter = instanceNameFilter. toLower (); foreach (string s in instances) {string instance = ""; if (string. isNullOrEmpty (instanceNameFilter) {instance = s;} else {Console. writeLine (s); if (s. toLower (). IndexOf (instanceNameFilter)> = 0) {instance = s ;}} if (! String. isNullOrEmpty (instance) {string [] l = ReadInstanceAllPerformanceCounterNextValue (categoryName, instance); if (l. length> 0) {list. addRange (l) ;}} return list. toArray ();} catch // (Exception e) {return null;} public string [] ReadInstanceAllPerformanceCounterNextValue (string categoryName, string instanceName) {PerformanceCounterCategory pcc = new PerformanceCounterCategory (categoryName ); performanceCounter [] counters = pcc. getCounters (instanceName); List <string> list = new List <string> (); foreach (PerformanceCounter counter in counters) {list. add (string. format ("Machine [{0}]-Category [{1}]-Instance [{2}]-Counter [{3}]: {4: dddd. dddd} ", counter. machineName, categoryName, counter. instanceName, counter. counterName, counter. nextValue ();} return list. toArray ();} public string [] values (string categoryName, string instanceName, string counterName) {nation pcc = new PerformanceCounterCategory (categoryName); PerformanceCounter counter = new PerformanceCounter (categoryName, counterName, instanceName); List <string> list = new List <string> (); // foreach (PerformanceCounter counter in counters) /// {// NumberFormatInfo nfi = new NumberFormatInfo (); // nfi. numberGroupSizes = new int [] {3, 3, 3, 3}; // nfi. numberGroupSeparator = ","; // string nextValueString = counter. nextValue (); list. add (string. format ("Machine [{1}] {0} DateTime [{2}] {0} Category [{3}] {0} Instance [{4}] {0} Counter [{5}]: {6: N} ","-", counter. machineName, DateTime. now. toString ("yyyy-MM-dd HH: mm: ss. fffff "), categoryName, counter. instanceName, counter. counterName, counter. nextValue (); //} return list. toArray () ;}}// Share. cs ============================================== ========/microshaoft ==================================== ============/// Microshaoft Remoting Object Client Local Proxynamespace Microshaoft. remotingObjects. serviceContracts. share {// using System; // using System. collections. generic; public interface IRemotingPerformanceMonitor {string [] values (string categoryName, string instanceNameFilter); string [] values (string categoryName, string [] instanceNamesFilter, string [] countersName );}} namespace Microshaoft {using System; using System. collections; using System. collections. generic; using System. runtime. remoting; using System. runtime. remoting. channels; using System. runtime. remoting. channels. tcp; using System. runtime. serialization. formatters; using System. text; public static class RemotingHelper {public static void StartRemoting (Type RemotingType, string Url, int Port) {BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider (); provider. typeFilterLevel = TypeFilterLevel. full; IDictionary ht = new Hashtable (); ht ["port"] = Port; TcpChannel tc = new TcpChannel (ht, null, provider); ChannelServices. registerChannel (tc, false); RemotingConfiguration. registerWellKnownServiceType (RemotingType, Url, WellKnownObjectMode. singleton); Console. writeLine ("Remoting Object Started... ");} public static void StartRemoting <T> (string Url, int Port) {StartRemoting (typeof (T), Url, Port );} public static T GetRemotingLocalClientProxyObject <T> (string Url) {return (T) Activator. getObject (typeof (T), Url //, "tcp: // 127.0.0.1: 8080/queueUrl") ;}}// Client. cs ============================================== ========================================================== ============= namespace Microshaoft. remotingObjects. client {using System; using System. collections; using System. runtime. remoting; using System. runtime. remoting. channels; using System. runtime. remoting. channels. tcp; using System. runtime. serialization. formatters; using System. threading; using System. collections. generic; using Microshaoft. remotingObjects. serviceContracts. share; public class Class1 {public static void Main () {Console. title = "Client"; Console. writeLine (Environment. version. toString (); Class1 a = new Class1 ();. run ();} public void Run () {iremotingtransfercemonitor monitor = RemotingHelper. getRemotingLocalClientProxyObject <iremotingeffeccemonitor> ("tcp: // 127.0.0.1: 8082/perfmonurl"); string [] ss = monitor. readAllInstancePerformanceCounterNextValue ("Process", new string [] {"devenv"}, new string [] {"Working Set"}); foreach (string s in ss) {Console. writeLine (s );}}}}