Skip to Content

Implement a Notification Application for Monitoring Java Apps

Create an application that notifies you of critical metrics via e-mail or SMS, using SAP Monitoring service.
You will learn
  • How to configure a custom application to notify you of critical metrics of Java applications via e-mail or SMS.
  • How to use the custom application to take self-healing actions by restarting the specified Java applications running in the Neo environment.
nikolasimeonov77Nikola SimeonovSeptember 15, 2022
Created by
December 1, 2020


In this tutorial, you implement a notification application that requests the metrics of the following Java applications (running in SAP BTP, Neo environment):

  • app1 located in a1 subaccount and Europe (Rot/Germany) region

  • app2 located in a2 subaccount and US East region

Since the requests are sent to only two applications, the Maven project that you import in Eclipse only spawns two threads. However, you can change this number in the MetricsWatcher class, where the ScheduledThreadPoolExecutor(2) method is called. Furthermore, if you decide to change the list of applications, you also need to correct the list in the Demo class of the imported project.

When the notification application receives the Java application metrics, it checks for critical metrics. The application then sends an e-mail or SMS, depending on whether the metrics are received as critical once or three times. In addition, the notification application restarts the Java application when the metrics are detected as critical three times.

To learn more about the whole scenario, read the Notification Scenario blog post.

If a Java application isn’t started yet, the notification application automatically triggers the start process.

  • Step 1

    Download the cloud-metricswatcher project as a ZIP file from

  • Step 2

    Extract the files into a local folder and import the folder in Eclipse as an existing Maven project.

    You can also upload your project by copying the URL from GitHub and pasting it as a Git repository path or URI after you switch to the Git perspective. Remember to switch back to a Java perspective afterward.

    How did you import the folder in Eclipse?

  • Step 3

    Open the class and update the following information:

    • Your e-mail

    • Your SMS

    • Your logon credentials

    • Your Java applications, and their subaccounts and regions

    String mail_to = "";
    String mail_to_sms = "";
    private final String auth_user = "my_user";
    private final String auth_pass = "my_password";
    String landscapeFqdn1 = "";
    String account1 = "a1";
    String application1 = "app1";
    String landscapeFqdn2 = "";
    String account2 = "a2";
    String application2 = "app2";

    What parameters have you set the values for in the `` class?

  • Step 4

    Open the class and update your e-mail account settings.

    private static final String FROM = "";
    final String userName = "my_email_account";
    final String password = "my_email_password";
    public static void sendEmail(String to, String subject, String body) throws AddressException, MessagingException {
                // Set up the mail server
                Properties properties = new Properties();
                properties.setProperty("mail.transport.protocol", "smtp");
                properties.setProperty("mail.smtp.auth", "true");
                properties.setProperty("mail.smtp.starttls.enable", "true");
                properties.setProperty("mail.smtp.port", "587");
                properties.setProperty("", "");
                properties.setProperty("", "");

    What parameters have you set the values for in the `` class?

  • Step 5
    1. Open the SAP BTP cockpit and find your Java applications.

    2. Configure your Java applications to return critical metrics.

      To do this, you can create a JMX check with a low critical threshold for HeapMemoryUsage so that the check is always received in a critical state.

      For more information, see create-jmx-check.


      neo create-jmx-check -a mysubaccount -b demo -u p1234567 -n "JMX Check Test - Heap Memory" -O java.lang:type=Memory -A HeapMemoryUsage -K used -U B -C 20000000 -h

      To use the console commands, you need to set up the console client. For more information, see Set Up the Console Client.

    3. Run your notification application in Eclipse and check the following:

      • You receive an e-mail with subject A metric has reached a critical state. and body Metric HeapMemoryUsage for application app1 has reached а critical state. when a critical metric is received.

      • You receive an SMS with text Metric HeapMemoryUsage for application app1 has reached critical state 3 times. The application will be restarted. when a critical metric is received three times.

      • Your Java application is restarted when its critical metric is received three times.

    You can check the status of your Java applications in the SAP BTP cockpit.

    What have you verified for the dashboard application?

Back to top