Get resource status for a remote server

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.