Java 程序监视系统健康状况的最佳方式是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/117043/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 11:05:03  来源:igfitidea点击:

What is the best way for a Java program to monitor system health?

javasystem-monitoring

提问by Bob Cross

I would like to be able to monitor my major system health indicators from inside our Java-based system. Major points of interest include CPU temperature, motherboard temperature, fan speed, etc.

我希望能够从我们基于 Java 的系统内部监控我的主要系统健康指标。主要关注点包括 CPU 温度、主板温度、风扇速度等。

Is there a package available that:

是否有可用的软件包:

  1. Makes this sort of data available to Java?
  2. Works on Windows or Linux or both?
  3. Is open / free / cheap?
  1. 使此类数据可用于 Java?
  2. 适用于 Windows 或 Linux 或两者?
  3. 开放/免费/便宜吗?

采纳答案by shadit

There are MIBs supported by both Windows and Linux that expose the parameters you are looking for via SNMP. Also, most major vendors have special MIBs published for their server hardware.

Windows 和 Linux 都支持 MIB,它们通过 SNMP 公开您要查找的参数。此外,大多数主要供应商都为其服务器硬件发布了特殊的 MIB。

I have implemented SNMP MIBs and monitoring for Java applications using the commercial iReasoning SNMP APIand they worked great. There is also the open source SNMP4J, which I don't personally have experience with, but looks pretty good.

我已经使用商业iReasoning SNMP API实现了 SNMP MIB 和 Java 应用程序监控,并且它们运行良好。还有开源的SNMP4J,我个人没有经验,但看起来很不错。

So, for your needs, you would turn on the publishing of SNMP information for the hosts you want to monitor. No coding necessary. This is just a configuration issue.

因此,根据您的需要,您可以为要监视的主机打开 SNMP 信息的发布。无需编码。这只是一个配置问题。

For CPU temperature, for example, you must enable the MIB LM-SENSORS-MIB. Under Linux you can use the snmpwalk client to take a look at OID .1.3.6.1.4.1.2021.13.16.2.1.3 to see CPU temperature. Once you have that up and you know it's publishing data correctly, you can begin to implement your real monitoring solution.

例如,对于 CPU 温度,您必须启用 MIB LM-SENSORS-MIB。在 Linux 下,您可以使用 snmpwalk 客户端查看 OID .1.3.6.1.4.1.2021.13.16.2.1.3 以查看 CPU 温度。一旦完成并知道它正在正确发布数据,您就可以开始实施真正的监控解决方案。

You can use a Java SNMP library to poll and subscribe to SNMP traps for the hosts you want to monitor. You could also use any commercial or open-source monitoring tool (Google for SNMP console).

您可以使用 Java SNMP 库为要监控的主机轮询和订阅 SNMP 陷阱。您还可以使用任何商业或开源监控工具(用于SNMP 控制台的Google )。

回答by Alex Miller

The closest thing you'll find is the Hyperic Sigar library:

您会发现最接近的是 Hyperic Sigar 库:

http://www.hyperic.com/products/sigar.html

http://www.hyperic.com/products/sigar.html

It doesn't get down to temperatures AFAIK but does show you a number of native stats like CPU, memory, disk I/O, network I/O, etc. It's ported to most of the architectures people are deploying Java on today. License is GPL although I think you can buy commercial licenses as well.

它不会归结为温度 AFAIK,但会向您展示许多本机统计信息,例如 CPU、内存、磁盘 I/O、网络 I/O 等。它已移植到人们今天部署 Java 的大多数架构中。许可证是 GPL,尽管我认为您也可以购买商业许可证。

We use Sigar with Terracotta for cluster monitoring and have been very happy with it.

我们使用带有 Terracotta 的 Sigar 进行集群监控,并且对此非常满意。

回答by Tom Hawtin - tackline

I believe most of this sort of thing is usually done over SNMP (for professional system) is the usual way to make this sort of information available in a standards-based manner. JMX is also available over SNMP. The question then becomes, which are the better SNMP libraries for Java (and does your system support it)?

我相信大多数这类事情通常是通过 SNMP(对于专业系统)完成的,这是以基于标准的方式提供此类信息的常用方法。JMX 也可通过 SNMP 使用。那么问题就变成了,哪些是更好的 Java SNMP 库(您的系统是否支持它)?

回答by Andreas Holstenson

A few months ago I looked for such a library and I found nothing interesting. It is not impossible to create one, so I would recommend doing so. You'll probably need to access native libraries, to do that use JNA(it's easier than JNI). Start by adding support for a few things on one platform, then start adding support for other features and platforms.

几个月前,我寻找这样的图书馆,但没有发现任何有趣的东西。创建一个并非不可能,因此我建议您这样做。您可能需要访问本机库,以使用JNA(它比 JNI 更容易)来做到这一点。首先在一个平台上添加对一些东西的支持,然后开始添加对其他功能和平台的支持。

The share it with us! People will starts using it, maybe even help with development and soon you'll have a fully featured system monitoring library for Java.

与我们分享!人们将开始使用它,甚至可能有助于开发,很快您将拥有一个功能齐全的 Java 系统监控库。