jetty.project icon indicating copy to clipboard operation
jetty.project copied to clipboard

JMX listener/logging

Open sbordet opened this issue 5 years ago • 12 comments

Would be great to introduce a JMX listener, or at least logging (which can be implemented as a logging listener), when the JMX infrastructure invokes Jetty's MBeans.

Applications can then know when JMX methods are invoked (and possibly by whom or at least know the stack trace) and log that activity.

The listener would be invoked for getAttribute(), setAttribute() and invoke() JMX methods, and multiple listeners could be attached to MBeanContainer.

sbordet avatar Mar 30 '19 15:03 sbordet

Seems like this already exists in the JVM ...

joakime avatar Mar 30 '19 16:03 joakime

@joakime those are not good as they only convey information for bean property changes. For JMX we would need JMX metadata and cover the invoke() semantic.

sbordet avatar Mar 30 '19 16:03 sbordet

for JMX Attributes there's already ...

For a JMX Operation, that would just be a normal Notification and NotificationListener

Wouldn't it make more sense to ensure support for what's already there vs creating a new API that only works with our MBean layer?

joakime avatar Apr 01 '19 15:04 joakime

I'll look into this.

sbordet avatar Apr 01 '19 16:04 sbordet

I just tried it, it would require each MBean that we care to listen to, to implement the javax.management.NotificationBroadcaster. These exist, but it's not like it's all that easy to use.

joakime avatar Apr 01 '19 16:04 joakime

No, AttributeChangeNotification must be emitted by the MBean implementation itself.

We don't do that in ObjectMBean ourselves.

There is no standard for operation notifications. It would be impossible to detect if a notification is emitted as a result of a JMX invocation (e.g. carrying method name and the result if the invocation), or as a result of some other event emitted by the MBean (e.g. timer events or other events that follow an invocation).

Both AttributeChangeNotification and OperationInvocationNotification could be implemented in a listener.

For non-ObjectMBeans, unfortunately, we won't have these new events.

sbordet avatar Apr 01 '19 16:04 sbordet

This issue has been automatically marked as stale because it has been a full year without activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Mar 31 '20 16:03 stale[bot]

There are 2 approaches:

  1. Introduce ObjectMBean.Listener as a custom interface so that application can register listeners and be notified of attribute events or invocation
  2. Use JMX built-in NotificationEmitter support and base as much as possible on JMX classes such as AttributeChangeNotification. Unfortunately there is no event for operation invocation, which means that the API has be to based on Notification.getUserData() to be a Map with a number of predefined keys for objects that applications may need (e.g. the invoked method name, parameters list, invocation result, etc.)

While would be nice to base the implementation of already existing JMX support, it is really too basic and cumbersome. However, it may be supported by tooling that understand JMX notifications so there would be some merit using JMX notifications.

sbordet avatar Apr 13 '20 13:04 sbordet

See also comments in #3517.

sbordet avatar Jul 02 '20 07:07 sbordet

This issue has been automatically marked as stale because it has been a full year without activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 21 '21 02:07 stale[bot]

Also, I think MBeanServer supports interceptors, it could be an alternative way of supporting this feature.

sbordet avatar Jul 21 '21 13:07 sbordet

This issue has been automatically marked as stale because it has been a full year without activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Jul 22 '22 00:07 github-actions[bot]

This issue has been closed due to it having no activity.

github-actions[bot] avatar Aug 23 '22 00:08 github-actions[bot]