** – Users can only attach to JVMs owned by them.For example, Hive user can only attach to hive JVM’s. Publish the memory units as JSON enabling java script widgets to chart them. Integrating with mobile notification APIsĢ. The application monitors memory usage continuously and when it exceeds a certain threshold, a one time alert is triggered and following email is sent to your configured email Id.ġ. Run the application using following syntax java -cp $/lib/tools.jar:heap-0.0.1-SNAPSHOT-jar-with-dependencies.jar sample.properties Compile using “mvn clean compile assembly:single”Ģ. The application uses maven build framework.ġ. Threshold specifies the threshold for triggering alert when memory usage crosses (threshold/100)*totalHeap.
#JAVA MEMORY MONITOR CODE#
Provide your SMTP server details using smtp_* variables. Understand the health of your JVM with key Java tuning and profiling metrics, including: response times, throughput, exception rate, garbage collection time, code deadlocks, and more. Users specify the memory usage thresholds (in percentage) for triggering alerts and SMTP server details to send the notifications in a property file.įollowing is a snippet from a sample properties file procId=3124 smtp_host= smtp_port=465 stmp_password=testing123 threshold=10 procId is the process Id of JVM to be attached and monitored**. More details about MemoryMXBean can be found in the java documentation Properties File for Parameters Using the memory object (bean) returned we can retrieve stats like used, allocated and max memory. One of the advantages of attach API is you can retrieve the JMX url from JVM and fetch various statistics, one of them is memory consumption as shown in following code snippet VirtualMachine virtualMachine = VirtualMachine.attach(virtualMachineDescriptor) String propertyValue = agentProperties.getProperty(".localConnectorAddress") c.getMBeanServerConnection().getAttribute(new ObjectName("java.lang:type=Memory"), "HeapMemoryUsage")
The JVM could be hosting NodeManagers, HiveServer2 or any other process. Java Attach API’s allows user program to attach to running JVM’s. The project is uploaded to my git repo and can be accessed using the following link
#JAVA MEMORY MONITOR HOW TO#
Although there are several monitoring and notification applications available in the market, in this article I have made an attempt to highlight how to build our own monitoring and notification application with the ability to customize it. SolarWinds SAM provides JVM monitoring tools that can help you effectively monitor key performance indicators like memory heap size, the number of database. The primary reason for such a requirement was Hiveserver2 aborting due to out of memory while running large queries, and it was hard for customer to tell the cause for query failure unless the process terminated and they reviewed the logs.Īmbari provides robust alerting and monitoring capabilities, but currently there is limited out of box support in monitoring and notifying memory consumption of Hive. Recently, I have been asked by customers for a way to monitor memory consumption and alert if it exceeds a certain threshold.