how can i generate mail alert/notification if memory consumption in jvm exceeds some thrsold, by using jmx -
Ways to generate mail alerts for the following changes in jvm
1) memory 2) threads 3 )
thanks
I will answer your question: The memory pool given to receive a notification at any time is more than a threshold, to do something like the below, to get the list of all memory pools, ManagementFactory.getMemoryPoolMXBeans Call (). Then you choose (things) that are important to you. One of my machines, is the list:
Code cache eden space server space tenrayed general perm General Perm General [shared-RO] perm General [shared-RW] < P> But I think there is no deliberate standard on this and they differ between versions and implementation. So first you get a pool interested in it: MemoryPoolMXBean memPool = ...; // Get a MemoryPoolMXBean Then, check whether the usage threshold is allowed or not. If so, set one (in bytes)
if (memPool.isUsageThreshold supported)) {memPool.setUsageThreshold (5000000); } functions when it went across the border, (actually passing a NotificationListener to addNotificationListener a MemoryMXBean, you have to do it before NotificationEmitter to cast) request Of notifications. In the example, Notification Listener is an anonymous internal class, but whatever you want may be, as long as it implements javax.management. The notification listener interface In fact, what I've done is stdout / stderr, a print stupid message, depending on how much memory is being used. . Of course, you can send a mail instead hook in the mail structure JavaMail or a third party
NotificationEmitter memBean = (NotificationEmitter) (ManagementFactory.getMemoryMXBean ()); memBean.addNotificationListener (New NotificationListener () {public void handleNotification (notification n, object handback) {CompositeData CD = (CompositeData) n.getUserData (); MemoryNotificationInfo mni = MemoryNotificationInfo.from (CD); MemoryUsage memUsage = mni.getUsage () ; long bytesUsed = memUsage.getUsed (); if (bytesUsed & gt; 512,000,000) System.err.println ( "Oh, no, we are using more than 512 M!"); else println ( "that's right is.. we are only using the "+ bytesUsed +" bytes ") are,}} as far as threads, the relevant bean is obviously ThreadMXBean, which you ManagementFactory.getThreadMXBean Meets (). What it does not have to look for a way to set a limit like there or built to connect the audience, you. You must vote yes, you can get thread count getAllThreadIds (just ManagementFactory.getThreadMXBean ().). Length Of course, more information is available in Bean.
Finally, "DB Connection" is just ambiguous. Using the database system? JVM server or customer in question, etc.
I advise you to ask a new question if you need more information on the following two resources.
Comments
Post a Comment