Pages

Saturday, 29 August 2015

How to monitor SAP CPU using Excel Macro

Introduction
In previous documents we have seen
1. How to Login to SAP 
2. How to call function
In this document we will see how to monitor SAP CPU, Users, response time, database size etc




What do we need ?
We need CCMS configured either on the same server or an external system for example Solution Manager. Usally we have solution manger already configure to act as Central server for CCMS data and alerts.


Funition Module
We will use BAPI_SYSTEM_MT_GETPERFDATA fm to fetch CCMS data. We will use PERF_NODES as input table and CURRENT_VALUES as output table.

Field NameDescription
MTSYSIDName of the SAP R/3 System
MTCLASSType of the MTE (performance attribute, log attribute, text, and so on); the various types are defined in RSALBAPI in the constants MT_CLASS_*
MTNUMRANGENumber range (for detailed information about the number range, see the document “Creating a Data Supplier for the Alert Monitor” [DataSup])
MTMCNAMEName of a monitoring context
MTUIDUnique Identifier (UID) of the MTE, which always remains the same for an MTE, unlike the index (see below) (if, for example, a segment is restarted)
MTINDEXIndex (Number within the array for the general properties within the monitoring segment)
EXTINDEXExternal index; this refers to the index number in the array in which the MTE also appears. This means that, for example, a performance attribute has both general properties and specific performance attribute properties.

Structure for CURRENT_VALUES
Field NameDescription
MTSYSIDName of the SAP R/3 System
MTCLASSType of the MTE (performance attribute, log attribute, text, and so on); the various types are defined in RSALBAPI in the constants MT_CLASS_*
MTNUMRANGENumber range
MTMCNAMEName of a monitoring context
MTUIDUnique Identifier (UID) of the MTE, which always remains the same for an MTE, unlike the index (see below) (if, for example, a segment is restarted)
MTINDEXIndex (Number within the array for the general properties within the monitoring segment)
EXTINDEXExternal index; this refers to the index number in the array in which the MTE also appears. This means that, for example, a performance attribute has both general properties and specific performance attribute properties.
ALRELEVVALMeasured value that is used for the comparison with the threshold values. This can be the last measured value or an average value
ALRELVALDT ALRELVALTIDate(ALRELVALDT) and time (ALRELVALTI) of the measured value relevant for alert generation
LASTALSTATMost recent alert status of a monitoring attribute. The alert status can be green, yellow, or red. The latter two statuses can involve an alert.







Sample Code 

 Code to call fm


' calling func
Set myFuncMTE = R3.Add("BAPI_SYSTEM_MT_GETPERFDATA")
'loading SAP functions input parameters
Dim EXTERNAL_USER_NAME, CURRENT_VALUES, PERF_NODE As Object
Set EXTERNAL_USER_NAME = myFuncMTE.exports("EXTERNAL_USER_NAME")
EXTERNAL_USER_NAME.Value = "SAPUSER"
'Set CURRENT_VALUES = myFuncMTE.Tables("CURRENT_VALUES")
Set PERF_NODES = myFuncMTE.Tables("PERF_NODES")
Xrange = Sheets("MTE").Cells(1, 1)
' Setting values for PERF_NODES, reading from excel sheet MTE
For i = 1 To Xrange 
    j = i + 1
    PERF_NODES.Rows.Add
    PERF_NODES.Value(i, "MTSYSID") = Sheets("MTE").Cells(j, 4)
    PERF_NODES.Value(i, "MTMCNAME") = Sheets("MTE").Cells(j, 5)
    PERF_NODES.Value(i, "MTNUMRANGE") = Sheets("MTE").Cells(j, 6)
    PERF_NODES.Value(i, "MTUID") = Sheets("MTE").Cells(j, 7)
    PERF_NODES.Value(i, "MTCLASS") = Sheets("MTE").Cells(j, 8)
    PERF_NODES.Value(i, "MTINDEX") = Sheets("MTE").Cells(j, 9)
    PERF_NODES.Value(i, "EXTINDEX") = Sheets("MTE").Cells(j, 10)
Next
' calling SAP Func
If myFuncMTE.call = False Then
    MsgBox myFuncMTE.Exception
End If
Set CURRENT_VALUES = myFuncMTE.Tables("CURRENT_VALUES")
For i = 1 To Xrange
j = i + 1
'Reading and writing CURRENT_VALUES to excel sheet RAW
    Sheets("RAW").Cells(j, 4) = CURRENT_VALUES.Value(i, "MTSYSID")
    Sheets("RAW").Cells(j, 5) = CURRENT_VALUES.Value(i, "MTMCNAME")
    Sheets("RAW").Cells(j, 6) = (CURRENT_VALUES.Value(i, "MTNUMRANGE"))
    Sheets("RAW").Cells(j, 7) = (CURRENT_VALUES.Value(i, "MTUID"))
    Sheets("RAW").Cells(j, 8) = (CURRENT_VALUES.Value(i, "MTCLASS"))
    Sheets("RAW").Cells(j, 9) = (CURRENT_VALUES.Value(i, "MTINDEX"))
    Sheets("RAW").Cells(j, 10) = CURRENT_VALUES.Value(i, "EXTINDEX")
    Sheets("RAW").Cells(j, 11) = CURRENT_VALUES.Value(i, "ALRELEVVAL")
    Sheets("RAW").Cells(j, 12) = CURRENT_VALUES.Value(i, "LASTPERVAL")
    Sheets("RAW").Cells(j, 13) = CURRENT_VALUES.Value(i, "AVG05PVAL")
Next
Set myFuncMTE = Nothing



Sample of MTE Data
PRD\sapprd1_PRD_00\...\CPU\CPU_Utilization
PRD\sapprd1_PRD_00\...\Dialog\ResponseTime
PRD\sapprd1_PRD_00\...\Dialog\UsersLoggedIn
PRD\sapprd1_PRD_00\...\Memory\Configured Memory
PRD\sapprd1_PRD_00\...\Memory\Free Memory




If you need a sample please write to me
There is no way to attach excel with macros enabled here




























5 comments:

  1. Hi, please a link to downloads excel file Sap Cpu

    ReplyDelete
  2. Hi, ccms is no longer working....

    But we can get few stuff using other FMs

    I can share those standard FMs and how to call then from excel

    ReplyDelete
    Replies
    1. Hi Amit, thanks for your post. May you share me those FMs and the excel sample? Thanks a lot

      Delete
    2. Hi German, I can share some, DO you have any particular KPI in mind ?

      Delete
    3. Get_CPU_ALL ( use Intern)
      GET_MEM_ALL
      TH_Server_LIST
      SAPTUNE_BUFFER_STATISTICS - ST02

      TH_WP_DETAIL_INFO

      SMLG_GET_DEFINED_SERVERS
      SYSTEM_GET_LOGON_GROUP_INFO

      RSLG_FILEINFO_INIT_ALV - SM21
      /SDF/MON_TH_WPINFO - SM51
      TH_TEST_COMMIT - check update is active
      TR_SYS_PARAMS - SE06 / t000

      There are many more. I recommend looking it up on SAP server using SE37

      Delete