Skip to Content
Technical Articles
Author's profile photo yasuyuki uno

Monitoring HANA Service: Custom Email Alerting

Background of this article

There are several options to monitor the SAP Cloud Platform HANA Service.

  1. Web interface (SAP HANA Cockpit)
  3. Combine SQL and scripts (Main subject)

However, there is no e-mail notification in the 1st and 2nd options. How do you notice system failure without notification? Do you want to monitor in front of your computer for 24 hours???

I think we need automated notification. (that’s 3rd option)

1st option (SAP HANA Cockpit)

SAP HANA Cockpit has an essential role in the Administration of SAP HANA. It is used for monitoring and managing checks such as:

  • Monitor overall database health
  • Monitor status and resource usage of individual database services
  • Analyze database performance across a range of key performance indicators related to memory, disk, and CPU usage
  • Monitor alerts occurring in the database and analyze patterns of occurrence
  • Configure the alerting mechanism, for example, change alert threshold values, switch alert checkers on/off, and check for alerts out of schedule

By using HANA Cockpit, we can check the database status, alerts, memory usage via web-based interface.

We can change the warning threshold value in cockpit view.

However, the alert is only displayed on Cockpit’s screen, and it does not notify outside.


2nd Option (SQL)

Embedded Statistics Service Views are part of the internal monitoring infrastructure of the SAP HANA database.

For example, if you refer to STATISTICS_CURRENT_ALERTS view, you can check the alerts that are currently happening.



3rd Option (Combine SQL and scripts)

If you want automatic email notification, you need to create a script and combine Statistics Service Views SQL.

Tools and services

Appendix: About SAP Cloud Platform Alert Notification

Alert Notification offers platform alerts and notifications for resources in the SAP Cloud Platform and gives you the possibility to create custom alerts for these resources.
This GA released at June 2019.
See this article for an overview of custom alerts.


Outline of the procedure

  1. Configure the Alert Notification.
  2. Create a Node.js project.
  3. Run the app locally.
  4. Deploy the app to CF.


1.Configure the Alert Notification.

Please refer the my previous article.

2.Create a Node.js project.

Open Command Prompt and move to your workspace directory. In my case, the workspace is “D:\html5”.

cd /d D:\html5

Make project folder. In this time, I named “hanamonitoring”.

mkdir hanamonitoring
cd hanamonitoring

Create package.json file like below.

  "name": "hanamonitoring",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node app.js"
  "dependencies": {
    "@sap/hana-client": "*",
    "node-schedule": "*",
    "request": "*"

Then install dependencies.

npm install

Create app.js file like below.
Please change <YOUR_PORT>  place to your HANA DB port number.
Please change <YOUR_DB_PASSWORD> place to your HANA DB SYSTEM user password.
Please change <YOUR_BASIC_USER>  place to your basic auth user id.
Please change <YOUR_BASIC_PASS> place to your basic auth password.


var schedule = require('node-schedule');
var hana = require('@sap/hana-client');
var conn = hana.createConnection();
var request = require('request');

var conn_params = {
    serverNode  : "<YOUR_PORT_NUMBER>", // Change here.
    encrypt     : true,
    schema      : "_SYS_STATISTICS",
    uid         : "SYSTEM",
    pwd     : "<YOUR_DB_PASSWORD>" // Change here.

var job = schedule.scheduleJob({
  second:  0 // Run as every minites.
}, function (fireTime) {

  conn.connect(conn_params, function(err) {
    if (err) {
      console.log("DB Error: DB Connection --- ", err);
      var msg = [{msg: "DB Error: DB Connection"}];
      res.json({searchResult: msg});

	// Run SQL Query 
	conn.exec(sql, function(err, result) {
      if (err) {
        console.log("DB Error: SQL Execution --- ", err);


      if (result.length == 0){
        // do nothing
        // send mail
		var options = {
		  url: '', // Endpoint URL + "/cf/producer/v1/resource-events"
		  method: 'POST',
		  auth: {
		    user: "<YOUR_BASIC_USER>", // Change here.
		    password: "<YOUR_BASIC_PASS>"  // Change here.
		  json: {
				  "eventType": "mycustomevent",
				  "resource": {
				    "resourceName": "Your Node.js App.",
				    "resourceType": "app",
				    "tags": {
				      "env": "HANA Service develop environment"
				  "severity": "FATAL",
				  "category": "ALERT",
				  "subject": "HANA Service Alert occured",
				  "body": result.length+" alerts occuring!!\n" + JSON.stringify(result)

		// Send Alert request.
		request(options, function (error, response, body) {

			console.log('Send E-mail Notification.');


3.Run the app locally.

Run the application by

npm start

You will receive an email from Alert Notification.

Next, we’ll deploy this app to your CF environment and run on cloud.


4.Deploy the app to CF.

Using CF CLI, login and deploy the app into Cloud Foundly.

cf api
cf login

# Deploy command.
cf push hanamonitoring
Pushing app hanamonitoring to org XXXXXXXX.XXXXXXXX / space dev as
Getting app info...
Updating app with these attributes...
  name:                hanamonitoring
  path:                D:\html5\hanamonitoring

Updating app hanamonitoring...
Mapping routes...
Comparing local files to remote cache...
Packaging files to upload...
Uploading files...
 1.50 MiB / 1.50 MiB [=====================================================================================] 100.00% 6s

Waiting for API to complete processing files...

Stopping app...

Staging app and tracing logs...
   Downloaded app package (1.8M)

Now it will works on your CF space.


Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Paolo Erhardt Sfilio
      Paolo Erhardt Sfilio

      Hey yasuyuki,

      many thanks for the great article. Good demonstration of how to use custom alerts.

      Despite the knowledge transfer and great written blog, my first thoughts were: I have to develop an application which is time-consuming and costs quota on CF to have a functionality which I would like to see in standard without a custom application in between.

      As I understood this is for the above scenario already possible in Neo with the Monitoring service (!?) and in CF a Dynatrace integration would be awesome.

      Nevertheless, I like the fact that we have to the possibility to send custom alerts, as it is quite difficult to cover everything in standard.


      Author's profile photo Paolo Erhardt Sfilio
      Paolo Erhardt Sfilio

      Seems that it is already available:

      Author's profile photo yasuyuki uno
      yasuyuki uno
      Blog Post Author

      Thanks for your comment.
      Yes, I know already possible in Neo and CF can integrate with Dynatrace. However, I wrote this blog thinking that I could use HANA DB external notification only with CF functions.

      I’ll try Dynatrace this weekend.

      Author's profile photo babu s
      babu s

      Thank you for the blog.

      Please suggest if there any way to receive an alert email if quota usage reaching 70% of total available quota on [NEO], in order to avoid last minute hassles we need an email alert comprising the consumption details.




      Author's profile photo Arne Feys
      Arne Feys

      Hi yasuyuki,

      Thank you for the interesting blog!

      I was just wondering, in the documentation, there is a scenario given for SAP HANA Events on Cloud Foundry. What is the different between this blog and the standard solution from the documentation?

      Thank you!



      Author's profile photo yasuyuki uno
      yasuyuki uno
      Blog Post Author

      Hi Arne,

      Sorry for the late reply. When I wrote this article, the documentation did not have this statement. So, it may be possible to notify the event externally by the standard function now.

      I will try it this weekend.