java 我们可以将 JMX 用于警报/通知吗

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/303613/
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:51:10  来源:igfitidea点击:

Can we use JMX for Alerts/Notification

javanotificationsjmxalerts

提问by a-sak

Here are the specs that I'm trying to implement in a nutshell:

简而言之,以下是我试图实现的规范:

1) Some Alerts have to be sent on certain events in the application.

1) 必须针对应用程序中的某些事件发送一些警报。

2) These Alerts have Users subscribe to them.

2) 这些警报让用户订阅它们。

3) And the Users have set their own Notification preferences (e.g. Email and/or SMS).

3) 并且用户已经设置了他们自己的通知首选项(例如电子邮件和/或短信)。

I have not been able to find an open source solution in Java so far.

到目前为止,我还没有在 Java 中找到开源解决方案。

Is JMX Notifications an option? The more I read about JMX, the more I feel that it is trying to achieve something different that my problem.

JMX 通知是一个选项吗?我对 JMX 了解得越多,我就越觉得它正在尝试解决与我的问题不同的问题。

Any help would be useful.

任何帮助都会有用。

回答by Will Hartung

JMX can be a mechanism to solve this problem, but it's not the complete solution.

JMX 可以作为解决这个问题的一种机制,但它不是完整的解决方案。

JMX provides facilities and services to your programs to allow clients to access monitoring data as well as allowing clients to make control calls to the application.

JMX 为您的程序提供设施和服务,以允许客户端访问监控数据以及允许客户端对应用程序进行控制调用。

As you mentioned, one aspect of JMX is the notification system. What this system provides is infrastructure to make it easy for your program to make alerts and notifications available to clients, and modern JVMs also provide a free JMX server to allow client to connect to your application remotely and subscribe to those events.

正如您提到的,JMX 的一个方面是通知系统。该系统提供的是基础设施,使您的程序可以轻松地向客户端提供警报和通知,现代 JVM 还提供免费的 JMX 服务器,以允许客户端远程连接到您的应用程序并订阅这些事件。

But its one thing to make a JMX alert, and it's another thing completely to act on it.

但是发出 JMX 警报是一回事,完全采取行动又是另一回事。

What you would need to do is have some JMX client, somewhere, "subscribe" to the JMX notifications of your programs, and then THAT client can act upon those notification by sending emails, or whatever.

您需要做的是在某处拥有一些 JMX 客户端,“订阅”您程序的 JMX 通知,然后该客户端可以通过发送电子邮件或其他方式对这些通知采取行动。

The JMX client can be a remote client talking to your application via TCP, or it can be an internal JMX client within the program, running in a thread, say, and it can act on the notifications.

JMX 客户端可以是通过 TCP 与您的应用程序通信的远程客户端,也可以是程序中的内部 JMX 客户端,在线程中运行,例如,它可以对通知采取行动。

So, basically, JMX provides the plumbing and infrastructure for what you want to do, but doesn't take it "the last mile" to converting alerts in to emails.

因此,基本上,JMX 为您想要做的事情提供了管道和基础设施,但不会将警报转换为电子邮件的“最后一英里”。

As @fawce mentioned, there are some "generic" JMX clients of various sophistication that can act upon JMX data and may do what you want (I'm not familiar with them, so I can not say first hand), or you can code your own system to monitor the JMX data.

正如@fawce 提到的,有一些各种复杂的“通用”JMX 客户端可以对 JMX 数据进行操作,并且可以做你想做的事情(我不熟悉它们,所以我不能直接说),或者你可以编码您自己的系统来监控 JMX 数据。

回答by fawce

If you mean JMX, there is a JBoss/Nagios bridge called monjuthat has a generlized JMX hook.

如果您指的是 JMX,则有一个名为monju的 JBoss/Nagios 桥接,它具有通用的JMX 钩子。

回答by stili

I would suggest using JMX notifications and SNMP which should support your scenario, 2) and 3) being covered by the SNMP software.

我建议使用 JMX 通知和 SNMP,它们应该支持您的场景,2) 和 3) 被 SNMP 软件覆盖。

You could also code it in Java yourself as long as you have access to a SMS gateway with some API. Using javax.mail is straightforward as long as you have access to a SMTP host allowing anonymous access. A flexible publish-subscribe mechanism for 2) can be used to connect 1) and 3).

只要您可以使用某些 API 访问 SMS 网关,您也可以自己用 Java 对其进行编码。只要您可以访问允许匿名访问的 SMTP 主机,使用 javax.mail 就很简单。2) 的灵活发布-订阅机制可用于连接 1) 和 3)。

回答by simbo1905

here is a good article with sample code for using jms in your app to raise alerts link text. once you have that working with local monitoring you need to set the -Dom.sun.management.jmxremote.port=9999 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false so that you can connect from a remote machine. a nice simple program to monitor jmx enabled java which can plot webpages of moving graphs and email out alerts when thresholds change is link text. it will also let you remote control your apps via the webpages. nice and simple. of course if you are using jmx you can easily swap up to use something more complex such as nagios or some expensive commercial tool. the key points about those tools is that they have workflow and rotas and stuff to manage a big team of people wanting to look after lots of things (databases, servers, java, etc) - which may be too much complexity if you just starting out with getting the java side of jmx working.

这是一篇很好的文章,其中包含在您的应用程序中使用 jms 来引发警报链接文本的示例代码。一旦你使用本地监控,你需要设置 -Dom.sun.management.jmxremote.port=9999 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false 所以您可以从远程机器连接。一个很好的简单程序来监视启用了 jmx 的 java,它可以绘制移动图形的网页并在阈值更改时通过电子邮件发送警报是链接文本. 它还可以让您通过网页远程控制您的应用程序。很好很简单。当然,如果您使用的是 jmx,您可以轻松切换到使用更复杂的东西,例如 nagios 或一些昂贵的商业工具。这些工具的关键点在于它们有工作流和轮值表和东西来管理一个想要照顾很多事情(数据库、服务器、Java 等)的大团队——如果你刚开始,这可能太复杂了让 jmx 的 java 端工作。

回答by TikiTavi

Solarwindsis a commercial enterprise monitoring tool that has the ability to hook into JMX for monitoring. It has the ability to generate SMS and Email alerts.

Solarwinds是一种商业企业监控工具,能够连接到 JMX 进行监控。它能够生成短信和电子邮件警报。

回答by eishay

Do you mean JMS (instead of JMX)? JMS is an messaging API while JMX is a monitoring/administration API. Using JMS as the back end is a good way to implement the back-end messages, it will take care of decoupaging, load balancing, and persistency. But you still have to have a component that receives the messages and send them on to the user.

你的意思是 JMS(而不是 JMX)?JMS 是一个消息传递 API,而 JMX 是一个监控/管理 API。使用 JMS 作为后端是实现后端消息的好方法,它将负责解耦、负载平衡和持久性。但是您仍然必须有一个组件来接收消息并将它们发送给用户。