精心设计的 JMX MBean 有哪些特征

发布于 2024-07-15 20:49:15 字数 46 浏览 2 评论 0原文

设计 JMX MBean 时有哪些最佳实践? 您认为有什么特别有用的例子吗?

What are some of the best practices in designing a JMX MBean? Any examples of ones you feel are especially useful?

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

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

发布评论

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

评论(4

金兰素衣 2024-07-22 20:49:15

返回绝对计数而不是比率。 例如,返回数据库提交的总数,而不是得出速率。

通过这样做,您的客户可以在他们需要的任何时间段内自行监控和得出费率。 也许更重要的是,如果客户不经常连接,这可以保护他们免于错过费率激增的情况。

如果您主要通过 HTML 界面使用 JMX bean,那么我遵循一些实践。 下面的内容通常意味着您的 JMX bean 应该包装现有的 bean(而不是仅公开 JMX 的现有方法):

  1. 输出表示返回对象的格式正确的字符串。 获取默认的 toString() 输出可能会导致无用的
  2. 捕获和显示异常。 否则,您可能会得到一个空白页面,并且必须转到日志文件来确定出了什么问题
  3. ,如果您显示不同的字符集,您可能必须适当地转义输出以防止显示问题(我遇到了这个问题)显示我们的中文数据的 JMX 控件)
  4. 暴露方法的输入应该正确清理(例如,如果您输入 id 作为操作的一部分,您可能希望 trim() 它以删除空格等)

。将重点从简单地通过 JMX 公开的 bean 更改为接近可用管理控制台的内容。

Return absolute counts instead of rates. e.g. return total number of db commits, rather than deriving a rate.

By doing this, your clients can monitor and derive rates themselves, over whatever time periods they require. Perhaps more importantly, this protects the clients from missing surges in rates if they only connect infrequently.

If you're using JMX beans primarily via the HTML interface, then there are several practises I follow. The below often means that your JMX bean should wrap an existing bean (as opposed to just JMX-exposing existing methods):

  1. output properly formatted strings representing returned objects. Getting a default toString() output can be next to useless
  2. capture and display exceptions. Otherwise you'll likely get a blank page and have to go to the log files to determine what went wrong
  3. if you're displaying different character sets, you may have to escape the output appropriately to prevent display problems (I ran into this with a JMX control displaying our Chinese data)
  4. inputs to exposed methods should be sanitised properly (e.g. if you input a id as part of an operation you may wish to trim() it to remove whitespace etc.)

The above changes the emphasis from a bean simply exposed via JMX to something approaching a useable admin console.

痴梦一场 2024-07-22 20:49:15

让我使用第一个 JMX bean 的第一件事是返回类型 - 如果你的方法返回字符串,那就容易多了 - 这样你的客户端就可以轻松地显示响应(我主要使用 JConsole) - 如果你不这样做,您会得到诸如 com.mycompany.Response@xxxx 之类的响应,这没有多大意义:)

The first thing that got me with my first JMX bean was return types - it's a lot easier if your methods return Strings - that way your client can easily display the response (I was mainly working with JConsole) - if you don't do this, you get things like com.mycompany.Response@xxxx as a response, which doesn't mean much :)

悍妇囚夫 2024-07-22 20:49:15

确保属性没有副作用并且在操作中是可预测的。

没有什么比看似无辜的属性执行耗时(或资源消耗)操作更糟糕的了。 我在我的时代见过一些嗡嗡声。

Make sure that attributes have no side effects and are predictable in operation.

There is nothing worse than an innocent looking attribute that executes a time-consuming (or resource-consuming) operation. I've seen some humdingers in my time..

腹黑女流氓 2024-07-22 20:49:15

不要使用 JMX 进行日志记录,因此,例如,不要使用返回自启动以来所有连接的详细信息的 MBean 函数。

人们应该记住,JMX 是用于监控的。 含义 - 仅显示与当前时刻相关的数据。

Do not use JMX for logging so, for example, don't use an MBean function that returns details of all the connections since startup.

One should remember that JMX is meant for monitoring. Meaning - Display only data that is relevant to the current moment.

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