使用 Java 进行简单的服务器监控

发布于 2024-08-04 07:33:16 字数 1536 浏览 5 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

日裸衫吸 2024-08-11 07:33:16

您可以选择将监控委托给专用工具,例如 CactiCentreon,或 Zenoss 但对于单个应用程序来说这可能有点过大了。

对于简单的解决方案,JMX 确实可能是更好的解决方案。作为起点,我建议阅读以下文章: 监控本地和使用 JMX 1.2 和 JConsole 的远程应用程序。然后,看看使用 JConsole 监控应用程序,这是一个非常详细的文章展示了如何使用 JConsole 访问多个核心监控和
Java平台提供的管理功能包括:

  • 检测内存不足
  • 启用或禁用 GC 和类加载详细跟踪
  • 检测死锁
  • 控制应用程序中任何记录器的日志级别
  • 访问操作系统资源 - Sun 的平台扩展
  • 管理应用程序的托管 Bean (MBean)

但是,据我所知,JMX 不会为您提供访问权限网络 IO,因此您可能需要这些工具的组合。幸运的是,许多工具(例如 Cacti、SmokePing)都使用 RDD 格式,您可以使用 Java 轻松操作该格式API,如 JRobinrdd4j

You could choose to delegate the monitoring to a dedicated tool like Cacti, Centreon, or Zenoss but this might be a bit overkill for a single application.

For a simple solution, JMX might indeed be a better solution. As starting point, I suggest reading the following article: Monitoring Local and Remote Applications Using JMX 1.2 and JConsole. Then, have a look at Using JConsole to Monitor Applications, a very detailed article that shows how to use JConsole to access several core monitoring and
management functionalities provided by the Java platform including:

  • Detect low memory
  • Enable or disable GC and class loading verbose tracing
  • Detect deadlocks
  • Control the log level of any loggers in an application
  • Access OS resources—Sun's platform extension
  • Manage an application's Managed Beans (MBeans)

But, AFAIK, JMX won't give you access to network IO so you might need a combination of these tools. Luckily, many tools (e.g. Cacti, SmokePing) use the RDD format that you can easily manipulate with Java APIs like JRobin or rdd4j.

赏烟花じ飞满天 2024-08-11 07:33:16

我越来越喜欢 collectd,这是一个模块化的 C 守护进程,专注于通过大量 插件

似乎有几个选项可以将指标纳入 Java 代码:

  • 进程中、使用前面提到的 Java 插件 注册一个写入回调以接收来自其他各种数据的数据 插件
  • 通过网络
  • ,通过将 jcollectd (collectd 协议的 Java 实现)嵌入到您的应用程序中间接地,通过写入 CSV 或 RRD 文件并使用 Java 的各种 RRD 实现之一

I'm growing fond of collectd, a modular C daemon focusing on monitoring (rather than graphing) with a multitude of plugins:

There would seem to be several options for getting metrics into your Java code:

  • in-process, using the aforementioned Java plugin to register a write callback to receive data from the various other plugins
  • over the network, by embedding jcollectd (a Java implementation of collectd's protocol) into your app
  • indirectly, by writing to a CSV or RRD file and using one of the various RRD implementations for Java
探春 2024-08-11 07:33:16

只是想将 RHQ (http://rhq-project.org/) 加入其中:-)

Just want to throw RHQ (http://rhq-project.org/ ) in the mix :-)

月下凄凉 2024-08-11 07:33:16

您可以考虑使用 Ganglia 监控工具。它使用 XML 进行数据表示,因此我想从 Java 访问数据会相当简单,而且它还有一个额外的优点,那就是它被设计为高度可扩展的,有可能记录大量的服务器指标。机器。

You could look into using the Ganglia monitoring tool. It uses XML for its data representation and so I imagine it would be fairly straightforward to access the data from Java, and there are the added advantages that it's been designed to be highly scaleable, with the potential to record server metrics across a large number of machines.

梦与时光遇 2024-08-11 07:33:16

您最好的选择可能是在 /proc 中查找所有系统资源使用情况 /proc/cpuinfo 和 /proc/net/ 是一个很好的起点。

Your best bet would probably look in /proc for all your systems resource usage /proc/cpuinfo and /proc/net/ are a good place to start.

土豪我们做朋友吧 2024-08-11 07:33:16

Runtime.exec(“某个命令”)有什么问题?

What's wrong with Runtime.exec("some command")?

独闯女儿国 2024-08-11 07:33:16

我不确定这是否有助于您的查询。恕我直言,Cacti 和 Centreon 似乎太复杂,无法投入时间来满足像您这样简单的需求。
有一些更简单的服务器监控工具,例如 New Relic海狮。海狮是我目前最喜欢的。它提供了简单的默认命令,涵盖了最基本的要求(也可能涵盖您的要求)。它的设置也非常简单并且免费。你可以尝试一下这些。

I am not sure if this would assist in your query. IMHO Cacti and Centreon seem to be too complex to invest time into for a requirement as simple as yours.
There are simpler tools out there for server monitoring such as New Relic and SeaLion. SeaLion is the my current favourite. It gives simple default commands which cover most basic requirements (will probably cover yours as well). It's also extremely simple to setup and is free. You could try these out.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文