如何在Java程序中获取、监控服务器负载值、CPU、内存、硬盘、网络情况?

如何在Java程序中获取、监控服务器负载值、CPU、内存、硬盘、网络情况?,第1张

SUM服务器监控软件吧
可以监控所有品牌的服务器的CPU\内存、磁盘、流量、网络、数据库、中间件,还能监控网络设备
有啥情况可以短信和邮件通知,比较方便
你看看吧,我们用的就是这个,只是温度不能监控,其他都可以

你可以在远程 WEB 写一个 JSP 页面,然后在该JSP页面调用 一个 LINUX本地的 SHELL(该SHELL实际上就是执行CPU、内存等占用情况的命令),然后将该 SHELL 执行完的流直接通过 JSP OUTPRINTF 输出即可。

public static String getCpuRatioForWindows() { 
         try { 
             String procCmd = Systemgetenv("windir") + "\\system32\\wbem\\wmicexe process get Caption,CommandLine,KernelModeTime,ReadOperationCount,ThreadCount,UserModeTime,WriteOperationCount"; 
             // 取进程信息 
             long[] c0 = readCpu(RuntimegetRuntime()exec(procCmd)); 
             Threadsleep(CPUTIME); 
             long[] c1 = readCpu(RuntimegetRuntime()exec(procCmd)); 
             if (c0 != null && c1 != null) { 
                 long idletime = c1[0] - c0[0]; 
                 long busytime = c1[1] - c0[1]; 
                 return "CPU使用率:"+DoublevalueOf(PERCENT  (busytime)10 / (busytime + idletime))intValue()+"%"; 
             } else { 
                 return "CPU使用率:"+0+"%"; 
             } 
         } catch (Exception ex) { 
             exprintStackTrace(); 
             return "CPU使用率:"+0+"%"; 
         } 
     }

The module - psutil is what you want
easy_install psutil
or
pip install psutil
-

RuntimegetRuntime()availableProcessors();    //CPU个数      
RuntimegetRuntime()totalMemory();    //虚拟机内存总量        
RuntimegetRuntime()freeMemory();    //虚拟机空闲内存量 
RuntimegetRuntime()maxMemory();    //虚拟机使用最大内存量


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/13488937.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-08-17
下一篇 2023-08-17

发表评论

登录后才能评论

评论列表(0条)

保存