精心设计的 JMX MBean 有哪些特征
设计 JMX MBean 时有哪些最佳实践? 您认为有什么特别有用的例子吗?
What are some of the best practices in designing a JMX MBean? Any examples of ones you feel are especially useful?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
返回绝对计数而不是比率。 例如,返回数据库提交的总数,而不是得出速率。
通过这样做,您的客户可以在他们需要的任何时间段内自行监控和得出费率。 也许更重要的是,如果客户不经常连接,这可以保护他们免于错过费率激增的情况。
如果您主要通过 HTML 界面使用 JMX bean,那么我遵循一些实践。 下面的内容通常意味着您的 JMX bean 应该包装现有的 bean(而不是仅公开 JMX 的现有方法):
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):
toString()
output can be next to uselesstrim()
it to remove whitespace etc.)The above changes the emphasis from a bean simply exposed via JMX to something approaching a useable admin console.
让我使用第一个 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 :)
确保属性没有副作用并且在操作中是可预测的。
没有什么比看似无辜的属性执行耗时(或资源消耗)操作更糟糕的了。 我在我的时代见过一些嗡嗡声。
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..
不要使用 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.