1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 6 usingSystem.Management;7 usingSystem.Diagnostics;8 usingNewtonsoft.json;9 usingNewtonsoft.Json.Linq;Ten One namespaceGH. IMS A { - Public classSystemmonit - { the PrivateManagementscope Ms; - - PublicSystemmonit () - { +Ms =NewManagementscope (); - } + A Publicsystemmonit (String IP, String userName, string password) at { -ConnectionOptions Conn =Newconnectionoptions (); -Conn.username =UserName; -Conn.password =password; -Ms =NewManagementscope (String.Format ("\\\\{0}\\root\\cimv2", IP), Conn); - in Ms.connect (); - } to + - PublicJarray Getlogicaldisk () the { * returnGETINFOFROMWMI ("Win32_LogicalDisk","Deviceid,size,freespace"); $ }Panax Notoginseng - PublicJarray getnaconfigurationinfo () the { + returnGETINFOFROMWMI ("Win32_NetworkAdapterConfiguration", A "ipaddress,defaultipgateway,dnsserversearchorder,ipsubnet,macaddress"); the } + - $ PublicJarray getprocessorinfo () $ { - returnGETINFOFROMWMI ("Win32_Processor", - "Name,family,l2cachesize,manufacturer,maxclockspeed,processorid,loadpercentage"); the } - Wuyi PublicJarray getphysicalmemoryinfo () the { -Jarray jarrayavailable = GETINFOFROMWMI ("win32_perfrawdata_perfos_memory", Wu "availablembytes"); -Jarray jarraytotal = GETINFOFROMWMI ("win32_logicalmemoryconfiguration", About "TotalPhysicalMemory"); $Jarray result=NewJarray (); - result. ADD (jarrayavailable); - result. ADD (jarraytotal); - returnresult; A } + /// <summary> the ///finding relevant information through WMI - /// </summary> $ /// <param name= "name" >name of the system configuration</param> the /// <param name= "Fields" >fields to query, multiple fields separated by ","</param> the /// <returns></returns> the PublicJarray getinfofromwmi (string name, string fields) the { -Jarray Jarray =NewJarray (); in Try the { theManagementobjectcollection mocobj = About NewManagementObjectSearcher (Ms, the NewObjectQuery ( theString.Format ("Select {0} from {1}", fields, name )). the Get (); + jobject jobj; - foreach(ManagementObject moinchmocobj) the {BayiJobj =Newjobject (); the foreach(String FieldNameinchFields. Split (',')) the { - if(Mo[fieldname]! =NULL) -Jobj.add (NewJproperty (FieldName, Mo[fieldname])); the } the Jarray. ADD (jobj); the } the } - Catch the { theJarray =NULL; the }94 returnJarray; the } the the Private enumUnit {B, KB, MB, GB, ER}98 Private stringFormatbytes (Doublebytes) About { - intUnit =0;101 while(Bytes >1024x768)102 {103Bytes/=1024x768;104++Unit; the }106 return string. Format ("{0} {1}", 107bytes. ToString ("F"), 108 (unit). ToString ());109 } the }111}
Get resource status for a remote server