Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an app that runs as a JVM in Windows 2008. I'd like to monitor it's memory usage and be sent an email if/when memory usage reaches a specific threshold. Is there a free utility or method for doing this?

share|improve this question
Can't you set the JVM max memory parameters to below whatever threshold would be "excessive" for the system? – Mat Jul 3 '12 at 18:18
@Mat Yup. But I'm looking for a way to be alerted if the memory usage is approaching the JVM max memory value I set. – Mike B Jul 3 '12 at 18:20
What would be your reaction if you received such an alert, how would it be actionable? Or would it be more for tracking/seeing how fast the thing uses up its allocation? (Just curious, sorry for the noise.) – Mat Jul 3 '12 at 18:24
@Mat Exactly. It would be an additional preventative safety measure to alert me if a JVM is using more memory than I would normally expect it to (but still under the JVM maximum value I set). – Mike B Jul 3 '12 at 18:27
up vote 4 down vote accepted

The Win2008 OS can send alerts for performance counter threshold conditions.

Part 1 # Perfmon
Launch Performance Monitor (perfmon.msc)
Create a new User Defined Data Collector Set
Choose to create manually after naming
Select Performance Counter Alert
Click Add - choose the Object, Counter and Instance to monitor. Process/Java.exe/Working Set
Specify the alert threshold
Choose "open properties for this data collector set"
Specify a start schedule if the server is on a reboot schedule
Change the sample interval. Alert repeats at this interval when value it above threshold
Under Alert task, give it a name (like sendMail)
Start the Data Collector Set

Part 2 # Schedule Tasks
Open up scheduled tasks (compmgmt.msc/configuration/task scheduler)
Create a task, not a basic task
Name it the exact same name you did in the above section (like sendMail)
Check "user is logged in or not" so that it runs all the time. Change username if necessary.
Create a new email action under the Action tab
Enter all the info for from, to, subject, etc.
Enter the SMTP server.
You will be prompt for the password to run the task when you are not logged on.
share|improve this answer
Thanks, this is exactly what I was looking for. – Mike B Jul 20 '12 at 15:46
This is definitely possible, but I'd like to point out here that setting up performance counter alerts/triggers is somewhat crude, since it will trigger an alert as soon as that threshold is met, even if it just met for 10 seconds. This may work somewhat well for counters that do not change often (like memory usage), but would not work very well for more volatile counters like CPU usage. Monitoring solutions like EventSentry are a bit smarter, and let you configure the time period over which the threshold has to exceed a limit before they trigger an alert. This helps reduce false positives. – Lucky Luke Apr 18 '13 at 19:01

In fact JVM memory boundaries are controlled by startup parameters like -Xmx2048m -Xms256m -XX:MaxPermSize=512m (it's example). JVM will use that allowed memory. Stable not leaking application will not go out of that boundaries.

Back to monitoring, it is possible to turn on JVM internal SNMP agent and then monitor memory usage of heaps and PermGen and through private SNMP community you can setup thresholds when exceeded JVM will send SNMP traps. In fact it is "enterprise solution of monitoring" by tools like HP OpenView. Cmdline parameters involved:

They are selfexplanatory. ACL file template is at JRE_HOME/lib/management/snmp.acl.template. To get readable anwers not just SNMP OIDs, download JVM-MANAGEMENT-MIB.mib. Some short explanation is here on Oracle site. When SNMP enabled, you can check returned gauges by running:

snmpwalk -v2c -c public YourWinHost:10001 -m JVM-MANAGEMENT-MIB jvmMgtMIB

It expect you already put JVM-MANAGEMENT-MIB.mib to default Net-SNMP MIB directory (Unix or CygWin commandline).

Not to forget mail sending, I'm doing JVM monitoring by Zabbix in conjunction with SNMP on cluster running nationwide backend cluster of Post Office. It covers all run time monitoring requirements. Zabbix can send you email or Jabber IM message in case of some trigger fired. Zabbix support SNMP agent monitoring and SNMP traps too. I ran month test of services in cloud, when monitored JVM was somewhere in USA and Zabbix server in Ireland... it worked well even for such distances/delays. Since version 2.0 there is JMX monitoring possible, but for secure environments it could be complicated, cause JMX-RMI setup some ports random.

In general SNMP is enough for JVM run time monitoring and JMX can more help on development/test machines cause it can monitor application nuances.

If you are in cloud with your Windows machine, you can use one of SaaS monitoring services. I was pretty impressed with NewRelic services. It is easy to setup and really helpful for development/test phases, cause can do things like thread dumps, slow SQL queries a.s.o. It can send emails when threshold reached.

share|improve this answer

Since Windows 2012 Server deprecated the "send email" task type you will now need a script that will send an email. For example, a VBScript:

Set Msg = CreateObject("CDO.Message")

With Msg

 .To = ""
 .From = ""
 .Subject = "low memory"
 .TextBody = "low memory, check the server now"
 .Configuration.Fields.Item("") = 2 
 .Configuration.Fields.Item("") = ""
 .Configuration.Fields.Item("") = cdoBasic
 .Configuration.Fields.Item("") = 25
 .Configuration.Fields.Item("") = False
 .Configuration.Fields.Item("") = "smtp-user"
 .Configuration.Fields.Item ("") = "smtp-password"

End With

The other steps are pretty much the same. Refer to this blog post for more info

share|improve this answer

You can setup monitoring with JMX.

Is this a server app running on Tomcat or a JEE application server? or is this a command line Java application? or a Windows Service Wrapped Java app? Which JVM? What settings? Oracle JDK Rockit has a great memory monitor, Oracle JRockit Mission Control 4.1 or

You could write a thread within your app that sleeps and awakens to check memory.

See these posts: or

share|improve this answer

You can run JMX, but it doesnt show e.g. garbage collector. You can also monitor the logfile. There is no utility to restart Java when it runs out of memory. But it's easy to code just in Java, and run as server, which checks for the apps if they are running OK, and the business logic you need to invent yourself, e.g. if(TotalCPUTime > 1d) restartJava();

Anyway, to restart Java remotely over JMX, requires access to the server, so there is no utility to do these two at the same time - to actually run, watch, restart and monitor the Java Process. You can run this Java on another Java as well, so it will do monitoring and restarting at the same time, and would run a small java.exe to do it.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.