Create Custom Metrics for HANA Monitoring With SAP Solution Manager 7.1 Introduction: When monitoring SAP HANA, most metrics are metrics stored in SAP HANA alert tables. However these tables do not include all the metrics you might be interested in. Some information is never written to these alert tables, because the SAP HANA administrator could use SAP HANA Studio to manually monitor these metrics, e.g. landscape information. To automate the monitoring for this kind of metrics we developed a data collector that pulls this information directly from the corresponding table in HANA. This guide describes how customers can create an own data collector implementation based on the SAP delivered data collector to collect own metrics from the SAP HANA database. Contents ..................................................................................................................................................................................1 Prerequistes ............................................................................................................................................................2 Connect SAP HANA to SAP Solution Manager .......................................................................................................2 Create Custom Data Provider Implementation ....................................................................................................2 Security Considerations ............................................................................................................................................2 Copy SAP Data Provider Implementation ................................................................................................................3 Adjust Custom Data Provider Implementation..........................................................................................................5 Declare Result Table ................................................................................................................................................5 Retrieve and filter result from HANA DB ..................................................................................................................7 Handle Result .........................................................................................................................................................10 Create Custom Data Collector for Monitoring and Alerting .............................................................................13 Copy SAP standard Data Collector Template ........................................................................................................13 Create Custom Metric and Alert ..........................................................................................................................18 Create a Custom Metric ..........................................................................................................................................18 Create a Custom Alert ............................................................................................................................................22 Result .....................................................................................................................................................................24 Appendix ...............................................................................................................................................................26 Coding for Z_HANA_METRIC_EXTRACTOR ........................................................................................................26
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Create Custom Metrics for HANA Monitoring
With SAP Solution Manager 7.1
Introduction: When monitoring SAP HANA, most metrics are metrics stored in SAP HANA alert tables.
However these tables do not include all the metrics you might be interested in. Some information is
never written to these alert tables, because the SAP HANA administrator could use SAP HANA Studio
to manually monitor these metrics, e.g. landscape information. To automate the monitoring for this
kind of metrics we developed a data collector that pulls this information directly from the corresponding
table in HANA. This guide describes how customers can create an own data collector implementation
based on the SAP delivered data collector to collect own metrics from the SAP HANA database.
Copy SAP Data Provider Implementation ................................................................................................................ 3
Adjust Custom Data Provider Implementation.......................................................................................................... 5
Declare Result Table ................................................................................................................................................ 5
Retrieve and filter result from HANA DB .................................................................................................................. 7
Handle Result .........................................................................................................................................................10
Create Custom Data Collector for Monitoring and Alerting .............................................................................13
Copy SAP standard Data Collector Template ........................................................................................................13
Create Custom Metric and Alert ..........................................................................................................................18
Create a Custom Metric ..........................................................................................................................................18
Create a Custom Alert ............................................................................................................................................22
Result .....................................................................................................................................................................24
Coding for Z_HANA_METRIC_EXTRACTOR ........................................................................................................26
Copyright/Trademark
PREREQUISTES
Connect SAP HANA to SAP Solution Manager
To enable technical monitoring with SAP Solution Manager for SAP HANA the first step is to connect the SAP HANA database to SAP Solution Manager via the managed system configuration.
For a detailed description how to connect SAP HANA database to SAP Solution Manager please follow the guide in the SMSETUP wiki:
The newest data provider to collect HANA metrics is shipped with ST-PI SP10. This data collector collects metrics via SELECT statements that are sent into the HANA database.
Security Considerations
For security reasons we couldn’t create a completely generic data collector, which accepts SQL statements as input. We rather have to hard-code the SELECT statement in the data provider implementation. For your own SELECT statements you will copy the SAP delivered data collector and adjust it to your needs.
The user used to run the SELECT statement against the HANA database is the user maintained in the DBA Cockpit connection for SAP HANA created during the managed systems configuration.
This user should have been created in SAP HANA as part of the managed system setup as described in the SMSETUP wiki page. The recommended granted roles for this user are the roles MONITORING and PUBLIC. With this roles the user has read-only access only to the schemas SYS and _SYS_STATISTICS.
By using this user to establish the connection to SAP HANA you can make sure that no business data can be pulled out of HANA during the monitoring.
To create and send you own SELECT statement you first have to copy the function module /SDF/HANA_METRIC_EXTRACTOR in customer namespace.
At first you have to create a function group for your function module. The easiest way to do this is in transaction SE80. Select “Function Group” from the drop-down box and enter a name for your function group. When you click the display button it will guide you thru the creation of the function group if it doesn’t exist yet.
If you want to transport the function module later on, please make sure to select a Z-package for you code.
Call transaction SE37 and enter /SDF/HANA_METRIC_EXTRACTOR in the input field. Click the “Copy” button to copy the function module.
You can reuse most of the data provide implementation, like e.g. the establishment of the DB connection, the import and export parameter and most of the error handling. But some parts are specific to the key figures you plan to collect and hence have to be adjusted.
In this guide we will implement two additional key figures.
“HANA Services Status” – the key figure lists the status of all HANA services. The result is already rated by the data collector.
“Number of Trace Files” – the key figure returns the number of trace files by host.
Examples for HANA SQL statements that could build the basis for your custom metrics can be found attached the SAP note “1969700 - SQL statement collection for SAP HANA” and SAP knowledge base article “1999993 - SAP HANA Mini Checks”.
You find a complete listing of the coding in the appendix of this document.
Declare Result Table
The result table is the table in which the result of the SELECT statement is written. Hence this data structure depends on your SELECT statement. You have to declare the columns exactly as you specify them in the SELECT statement.
Example 1: “HANA Services Status”
The data declaration area begins roundabout in code line 60+. Everything before doesn’t have to be changed. For the first example I use this select statement:
SELECT HOST, SERVICE_NAME, COORDINATOR_TYPE TYPE, ACTIVE_STATUS FROM M_SERVICES S ORDER BY S.HOST, S.SERVICE_NAME
The result structure I declare contains the fields host, service_name, type and active_status:
" data declarations for metric Service Status
types: begin of st_services,
host(64) type c,
service_name(128) type c,
type(128) type c,
active_status(64) type c,
end of st_services.
data: services_iterator type st_services.
data: services_list type table of st_services.
Example 2: “Number of Trace Files”
The second example is an example for a metric with returns a numeric value.
I use the following SELECT statement retrieve this metric:
SELECT HOST, COUNT(*) No_of_tracefiles FROM M_TRACEFILES T GROUP BY T.HOST
The result is this table. In my case only one host is ONLINE. Hence I only have one entry. If you have a multi-node HANA DB, you would find one entry per host.
The result structure contains the two columns host and no_of_tracefiles.
" data declarations for metric id 1501
types: begin of st_tracefiles,
host(64) type c,
no_of_tracefiles TYPE string,
end of st_tracefiles.
data: tracefiles_iterator type st_tracefiles.
data: tracefiles_list type table of st_tracefiles.
Now you have to create the SELECT statement and handle the result set. Depending on the type of your key figure you can return a value or a rating. Technically you could return both, but this doesn’t necessarily make sense.
The coding for the key figure starts around code line 210+ in the original coding. You can also filter for the string
“here plays the music” … this will take you directly to the first key figure
Each key figure is identified by a number; this is just for the coding, as you can have more than one key figure in your HANA data provider implementation. In order to avoid confusion with the HANA alert IDs you should not use 000 to 999. We suggest using 1000 to 2000 for this extractor.
The easiest way is to copy the coding from the original key figures and adjust it to your needs.
Example 1: “HANA Services Status”
For this key figure I want to return a rating. As also the key figure 1000 is an already rated key figure, I copied this piece of code.
Now you have to adjust the coding. I will go thru the coding step by step and highlight the areas that have to be adjusted.
1. Replace the name of the result table with the name from your own data declaration:
when '1500'. "Service Status List - available filter parameters: HOST and SERVICE
As I mentioned before make sure that your result data structure and the column names match the returned fields.
You can test your select statement in HANA Studio using the SQL Console. This way you see if your SELECT statement is syntactically correct, but also how the result looks like. Knowing what the result looks like helps with the next step.
3. Filter the result set
The standard data provider has 3 parameters. DBCNAME is the DB connection name and will be prefilled by the monitoring infrastructure. KEY_FIGURE is the ID for the key figure you want to select. ALERT_TEXT is used if you want to filter your result set.
The parameters DBCNAME and KEY_FIGURE are set should not be changed in the coding. But if you want, you can do something about ALERT_TEXT. I rather wanted to have the parameters HOST and SERVICE as filter parameters for my key figure. This way I can filter for the hosts I’m interested in, as well as put an additional filter on the service name.
loop at e_selopt_para-selection_parameter assigning <selection_parameter>
where param = 'HOST'.
sel_opt_table = <selection_parameter>-t_ranges.
exit.
endloop.
delete services_list where host not in sel_opt_table.
loop at e_selopt_para-selection_parameter assigning <selection_parameter>
where param = 'SERVICE'.
sel_opt_table = <selection_parameter>-t_ranges.
exit.
endloop.
delete services_list where service_name not in sel_opt_table.
Example 2: “Number of Trace Files”
For this key figure I want to return the number of trace files per host. I copied key figure 1001 as template, as this key figure also returns a numeric value. The steps here are the same as for example 1.
1. Replace the name of the result table with the name from your own data declaration:
when '1501'. "Number of trace files per host - available filter parameters: HOST
Now you have to fill the export parameter RESULT. You don’t have to worry about RETURN_STATUS, this is already done in the original implementation.
You result table will consist of a text and also a rating or a value. Based on the returned values you will then create thresholds for your metrics.
Example 1: “HANA Services Status”
For this metric we will use an already rated value. So we basically check the result table and return a rating (green, red, yellow or grey) and a text for the metric. In the monitoring we set up this metric with the threshold type already rated.
The code below will produce the following result:
At first we create the right side of the picture above. To make sure we can use the metric in a metric group later on, we have to create one entry for each parameter in the parameter table.
refresh t_parameter.
" produce result table (one metric per host:service in services_list)
The last 2 lines of code fill the numeric return table fields with the value 0. As we will create an already rated metric, we will not use these fields.
In the last step we have to assign the numeric value to the respective field in the result array. In this case I assign the same value to min, max and average. This way I make sure, that the implementation is a bit more error tolerant when it comes to the selection of the value that is compared in the threshold (you’ll see this later).
CREATE CUSTOM DATA COLLECTOR FOR MONITORING AND ALERTING
To use your custom data provider implementation you have to create data collector template to be able to use it in the monitoring and alerting templates. The data collector template serves as the interface between your implementation and the template maintenance. It provides the possible input fields for the parameters in the template maintenance and hands the input values over to the data provider implementation it uses.
As the basis for the data collector template we use the data collector template “Hana Database Metrics”, which uses the original SAP delivered data provider implementation.
Then find the data collector “Hana Database Metrics” under the RFC (Pull) collector types.
Adjust the name of the data collector. Make sure the name starts with ZZ, as this is going to be a table entry, you have to use double-Z to protect it against overwrite during a content update.
Save you data collector template. It will ask for a transport request at this point.
Now we have to change the parameters.
As mentioned before the parameters DBCNAME and KEY_FIGURE are set. But as I changed the parameters in my data provider implementation I have to adjust them here too. I also want to hardcode the key figure to make sure the user uses the correct key figure for my parameters. So in a first step I change the parameter usage to HIDDEN, to avoid that users can change it and also enter 1500 as value. I also remove the flag for “Ext. Context”.
Now I add two new parameters HOST and SERVICE.
Now I delete ALERT_TEXT, as I don’t want to use it anymore.
Done, now I can use this data collector template in a custom metric.
Right now we are creating one data collector template per metric. This is the most user-friendly way but also the one with the most effort. If you want to cut down the number of created data collector templates you could also create e.g. one template for all metrics with just one filter value, one for all metrics with two filter values, and so on.
You would have to address this already in the coding. So instead of using specific parameter names like HOST and SERVICE, you would use your generic parameter names, e.g. FILTER1, FILTER2 etc. in your code, when you filter the result:
refresh sel_opt_table.
loop at e_selopt_para-selection_parameter assigning <selection_parameter>
where param = 'FILTER1'.
sel_opt_table = <selection_parameter>-t_ranges.
exit.
endloop.
delete tracefiles_list where <host> not in sel_opt_table.
In this example FILTER1 = host.
But be careful. You have to document very well, which filter parameter filter on which field in your result (e.g. for “HANA Services Status” FILTER1 = host, FILTER2 = service). Only this way you can make sure that later on during the setup of the metric in the template management the right parameter value are set.
If the same data collector template is used for several key figures, it is also recommendable to add an input help for the KEY_FIGURE field. And certainly this field cannot be HIDDEN
The last step in this guide is to create a custom metric and alert that uses our new data provider implementation. I already created a custom template. The template should be created as custom template from the ”SAP HANA DB (NEW)” template.
Create a Custom Metric
Example 1: “HANA Services Status”
Switch to expert mode and click the “Edit” button to be able to add you custom metric. Click “Create” → Metric to create the metric.
Enter the name and the category for your metric. Make sure to create it as a “Metric Group” if you plan to use no filter or a filter that returns more than one line.
Select you data collector from the list. As we create a metric group, you have to create a variant. In this case I do not restrict by hostname or service name. To enter the values for host name and service name, click on the
green in the columns. It’s OK that it changes to a when you add a pattern
On the next tab you can decide if you want to use the metric only for alerting or also for reporting. I didn’t change anything here. On the Threshold tab you have to select “Already Rated” as threshold type to make sure your rating value that you return is taken into account.
Click “Next”. You could assign the metric to an already existing alert. But I want to create an own alert for this.
Click “Finish” and save your work.
Example 2: “Number of Trace Files”
Create a custom metric and enter name, category and a technical name.
Select the data collector template and enter a variant for the host filter.
In the tab Threshold you have to choose a numeric threshold. As we fill the result value in the min, max and the average value, it luckily doesn’t matter which one you choose as “Monitored Value”.