最近看到浪潮的猎鹰服务器管理软件,其中可以对远程服务器的CPU和内存使用率进行实时监视,就像任务管理器那样绘制一个报表。我推断他要么是使用SNMP协议从客户机拿到数据之后在传递给管理器,要么就是使用Windows提供的某些System Performence COM组件来抓数据。
   查MSDN,上有一个System Monitor的例子。居然是用VBScript来调一调控制面板-〉管理工具-〉性能-〉系统监视器。既然是用HTML嵌VBScript,那转换为应用程序到也方便,将文件后缀名改为.hta,即以HTML Application方式打开,由MSHTA.exe来解释执行就可以了。
   下面的程序就是从命令行中获取要监视的计算机IP地址后,启动System Monitor,监视之。
< HTML >
< HEAD >
< HTA:APPLICATION  ID ="oHTA"
    APPLICATIONNAME
="myApp" >
   
< meta  http-equiv ="Content-Type"  content ="text/html; charset=gb2312"   >
   
</ HEAD >
    
< BODY  BGCOLOR ="#C0C0C0" >
        
< SCRIPT  LANGUAGE ="VBScript" >
  
Sub Monitor_OnCounterAdded(index)
    Monitor.Counters.Item(
1).Width = 8
  
End Sub
        
</ SCRIPT >
        
< OBJECT  CLASSID ="clsid:C4D2D8E0-D1DD-11CE-940F-008029004347"  ID ="Monitor"  HEIGHT ="80%"  WIDTH ="100%"
            VIEWASTEXT
>
        
</ OBJECT >
        
< SCRIPT  LANGUAGE ="VBScript" >
        
  
Sub Window_OnLoad
    
On Error Resume Next
    Monitor.ShowValueBar 
= True
    Monitor.ShowHorizontalGrid 
= True
    
    Arg 
= Trim( oHTA.commandLine )

    IPArgPos 
= InStr(2, Arg, """"1)
    IPArg 
= Trimright( Arg, len(Arg)-IPArgPos) )
    
    IPStrings 
= split( IPArg, " "-11 )

    
for i = 0 to uBound(IPStrings)
    Monitor.Counters.Add( 
"\\" + IPStrings(i) + "\Processor(_Total)\% Processor Time" )
    Monitor.Counters.Add( 
"\\" + IPStrings(i) + "\Memory\Available MBytes" )
    Monitor.Counters.Add( 
"\\" + IPStrings(i) + "PhysicalDisk(_Total)\Avg. Disk Queue Length" )
    Monitor.Counters.Add( 
"\\" + IPStrings(i) + "\LogicalDisk(_Total)\% Free Space" )
    Monitor.Counters.Add( 
"\\" + IPStrings(i) + "\Network Interface(*)\Bytes Total/sec" )
    
Next

    
'Monitor.Counters.Add( "\Process(*)\% Processor Time")
    Monitor.DisplayType=sysmonLineGraph
    Monitor.GraphTitle
= "计算机系统性能监视"
  
End Sub
  
        
</ SCRIPT >
    
</ BODY >
</ HTML >
   不知道大家有没有使用过COM组件将这样的东西嵌到C++程序中。如果有的话,不妨发表上来看看。