ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Retrieve % Interactive CPU usage

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Retrieve % Interactive CPU usage

    Dear all,

    Do you have any idea about the way to retrieve % interactive CPU usage in CLP ?

    I've tried with QWCRSSTS API but i just could get the % current interactive performance ( for my iseries 270 = 100%)...

    Thanks in advance !

    Nick

  • #2
    Re: Retrieve % Interactive CPU usage

    You could do a WRKACTJOB with *PRINT option, then convert the spool file to a flat file (CPYSPLF) and then parse/read that. I've done that with WRKSYSSTS before to get the disc usage.

    Comment


    • #3
      Re: Retrieve % Interactive CPU usage

      Here is the description of the returned variables


      use format SSTS0200
      as input parameter

      Field Descriptions
      % DB capability. The percentage of processor database capability (in tenths) that was used during the elapsed time. Database capability is the maximum CPU utilization available for database processing on this server. -1 is returned if this server does not report the amount of CPU used for database processing. For example, a value of 411 in binary would be 41.1 percent.

      % permanent addresses. The percentage (in thousandths) of the maximum possible addresses for permanent objects that have been used. For example, a value of 41123 in binary would be 41.123.

      % processing unit used. The average (in tenths) of the elapsed time during which the processing units were in use. For example, a value of 411 in binary would be 41.1.

      % system ASP used. The percentage (in 10 thousandths) of the system storage pool currently in use. For example, a value of 41123 in binary would be 4.1123.

      % temporary addresses. The percentage (in thousandths) of the maximum possible addresses for temporary objects that have been used. For example, a value of 41123 in binary would be 41.123.


      and here is the program
      Code:
           D Inf_Len         S              4B 0
      
            * API Error Data Structure
           D API_Err         DS
           d  ErrBytes               1      4b 0
           d  ErrBytesAva            5      8b 0
           d  Exception              9     15
           d  Reserved              16     16
           d  Data                  17    271
      
            * The following data structures are returned from the API
      
           D Fmt_001         DS           256
           d  F001DateTime                  8    overlay(Fmt_001:9)
           d  F001System                    8    overlay(Fmt_001:17)
           d  SignedOn              25     28b 0
           d  TempSignOff           29     32b 0
           d  UserSuspSReq          33     36b 0
           D  UserSuspGJob          37     40b 0
           D  SignOffPrt            41     44b 0
           D  BJobMsgW              45     48b 0
           D  BJobRun               49     52b 0
           D  BJobRunHld            53     56b 0
           D  BJobEnd               57     60b 0
           D  BJobSched             61     64b 0
           D  BJobHldJQ             65     68b 0
           D  BJobJQHld             69     72b 0
           d  BJobUnAsJQ            73     76b 0
           D  BJobEndPrt            77     80b 0
      
           D Fmt_002         DS           256
           d  F002DateTime                  8    overlay(Fmt_002:9)
           d  F002System                    8    overlay(Fmt_002:17)
           d  F002ElapTime          25     30
           d  RstStateFlg           31     31
           d  Res_002               32     32
           D  PCProcUnit            33     36b 0
           D  JobsInSys             37     40b 0
           D  PCPermAddr            41     44b 0
           D  PCTempAddr            45     48b 0
           D  SystemASP             49     52b 0
           D  PCAsp                 53     56b 0
           D  TotAuxStg             57     60b 0
           D  CurUnpStg             61     64b 0
           D  MaxUnpStg             65     68b 0
      
           D Fmt_003         DS          2048
           d  F003DateTime                  8    overlay(Fmt_003:9)
           d  F003System                    8    overlay(Fmt_003:17)
           d  F003ElapTime          25     30
           d  Res_003               31     32
           D  NumPools              33     36b 0
           D  OffSetPool            37     40b 0
           D  PoolInfLen            41     44b 0
           D  PoolData                   1024    overlay(Fmt_003:45)
      
           d Store_Data      s            256    dim(4000)
           d StartPos        s             15  0 inz(0)
           d Count           s             15  0 inz(0)
      
           d Pool_Inf        ds
           d  A_SysPool              1      4b 0
           d  A_PoolSiz              5      8b 0
           d  A_ResSiz               9     12b 0
           d  A_MaxAct              13     16b 0
           d  A_DBFault             17     20b 0
           d  A_DBPage              21     24b 0
           d  A_NDBFault            25     28b 0
           d  A_NDBPage             29     32b 0
           d  A_ActToWait           33     36b 0
           d  A_WaitInel            37     40b 0
           d  A_ActInel             41     44b 0
           d  A_PoolName                   10    Overlay(Pool_Inf:45)
           d  A_SbsName                    10    Overlay(Pool_Inf:55)
           d  A_SbsLib                     10    Overlay(Pool_Inf:65)
           d  A_PagOpt                     10    Overlay(Pool_Inf:75)
      
           C     *entry        plist
           c                   parm                    Format            8
      
           c                   select
           c                   when      Format = 'SSTS0100'
           c                             or Format = 'SSTS0200'
           C                   Z-ADD     256           INF_LEN
           c                   other
           C                   Z-ADD     2048          INF_LEN
           c                   endsl
      
            * Format SSTS0100 = DSPSYSSTS Basic
            * Format SSTS0200 = DSPSYSSTS Disk Information (Int/Adv)
            * Format SSTS0300 = DSPSYSSTS Pool Information (Int/Adv)
            * Call the API to retrieve the DSPSYSSTS info for this SYS:
           C                   call      'QWCRSSTS'
           C                   parm                    Sys_Inf        2048
           C                   parm                    INF_Len
           C                   parm      Format        Api_Format        8
           C                   parm      '*NO'         Stat_Reset       10
           C                   parm                    Api_Err
      
           c                   select
           c                   when      Format = 'SSTS0100'
           c                   eval      Fmt_001 = Sys_Inf
           c                   when      Format = 'SSTS0200'
           c                   eval      Fmt_002 = Sys_Inf
           c                   when      Format = 'SSTS0300'
           c                   eval      Fmt_003 = Sys_Inf
           c                   eval      StartPos = OffsetPool + 1
           c                   do        NumPools
           c                   eval      Count = Count + 1
           c                   eval      Store_Data(count) =
           c                             %subst(Fmt_003:StartPos:PoolInfLen)
           c                   eval      Pool_Inf = Store_Data(Count)
           c                   eval      StartPos = StartPos + PoolInfLen
           c                   enddo
           c                   other
           c                   endsl
      
      
           c                   eval      *inlr = *on
           c                   return
      Attached Files
      All my answers were extracted from the "Big Dummy's Guide to the As400"
      and I take no responsibility for any of them.

      www.code400.com

      Comment


      • #4
        Re: Retrieve % Interactive CPU usage

        Thanks for your help !

        I just want to get the % interactive CPU usage but in your program, you can only get % global CPU usage (batch+interactive jobs)...

        It doesn't seem to be so easy... (my OS version is V5R2)

        Nick

        Comment


        • #5
          Re: Retrieve % Interactive CPU usage

          Hello, I've been looking for some info on using API (QWCRSSTS) with the SST0200 format. This looks perfect. Let me see if I get this right. To use this program I would have to call this program with a parm of SSTS0200, right? And then change the pool loop and loop until RstStateFlg = '1'? Would this be correct?

          Comment


          • #6
            Re: Retrieve % Interactive CPU usage

            just call with format...program loops thru pools on its own.
            cant remember where it came from...i do remember i did test it

            jamie
            All my answers were extracted from the "Big Dummy's Guide to the As400"
            and I take no responsibility for any of them.

            www.code400.com

            Comment


            • #7
              Re: Retrieve % Interactive CPU usage

              Just call this to get the processor utilization (from System iNetwork by Bruce Vining)
              PHP Code:
              h dftactgrp(*no)                                                

              dMATRMD           pr                  extproc('_MATRMD')        
              d RcvVar                      4096                              
              d Control                        8                              

              dRcvVar           ds          4096                              
              d BytPrv                        10i 0 inz
              (%size(RcvVar))        
              d BytAvl                        10i 0                           
              d TimeOfDay                      8                              
              d MaxPrcCount                    5u 0                           
              d ActPrcCount                    5u 0                           
              d PrcCount                       5u 0                           
              d ReservedHdr                   26                              

              dPrcInfo          ds            48    based
              (PrcInfoPtr)         
              d TimeUsed                      20u 0                           
              d TimeAvl                       20u 0                           
              d UncAvl                        20u 0                           
              d PrcID                          5u 0                                   
              d StsFlags                       1                                      
              d ReservedDet                   21   
                                                 
              dControl          s              8    inz
              (x'2800000000000000')          
              dPctUsed          s              7  4                                   
              dMsg              s             50  
                                                  
              c                   callp     MATRMD
              (RcvVar :Control)                   
              c                   eval      PrcInfoPtr = %addr(RcvVar) + 48           
              c                   
              do        PrcCount                                  
              c                   
              eval      PctUsed = (TimeUsed/TimeAvl) * 100        
              c                   
              eval      Msg = ('Proc ' + %char(PrcID) +           
              c                                    ' used ' +                         
              c                                    %editw(PctUsed :'  0.    ') + '%'
              c     Msg           dsply                                               
              c                   
              eval      PrcInfoPtr PrcInfoPtr + %size(PrcInfo)  
              c                   enddo                                               
              c                   
              eval      *inlr = *on                               
              c                   
              return 
              Philippe

              Comment


              • #8
                Re: Retrieve % Interactive CPU usage

                Originally posted by jamief View Post
                just call with format...program loops thru pools on its own.
                cant remember where it came from...i do remember i did test it

                jamie
                Thanks. Modified and it seems to work.

                Comment


                • #9
                  Re: Retrieve % Interactive CPU usage

                  Originally posted by jamief View Post
                  Here is the description of the returned variables


                  use format SSTS0200
                  as input parameter

                  Field Descriptions
                  % DB capability. The percentage of processor database capability (in tenths) that was used during the elapsed time. Database capability is the maximum CPU utilization available for database processing on this server. -1 is returned if this server does not report the amount of CPU used for database processing. For example, a value of 411 in binary would be 41.1 percent.

                  % permanent addresses. The percentage (in thousandths) of the maximum possible addresses for permanent objects that have been used. For example, a value of 41123 in binary would be 41.123.

                  % processing unit used. The average (in tenths) of the elapsed time during which the processing units were in use. For example, a value of 411 in binary would be 41.1.

                  % system ASP used. The percentage (in 10 thousandths) of the system storage pool currently in use. For example, a value of 41123 in binary would be 4.1123.

                  % temporary addresses. The percentage (in thousandths) of the maximum possible addresses for temporary objects that have been used. For example, a value of 41123 in binary would be 41.123.


                  and here is the program
                  Code:
                       D Inf_Len         S              4B 0
                  
                        * API Error Data Structure
                       D API_Err         DS
                       d  ErrBytes               1      4b 0
                       d  ErrBytesAva            5      8b 0
                       d  Exception              9     15
                       d  Reserved              16     16
                       d  Data                  17    271
                  
                        * The following data structures are returned from the API
                  
                       D Fmt_001         DS           256
                       d  F001DateTime                  8    overlay(Fmt_001:9)
                       d  F001System                    8    overlay(Fmt_001:17)
                       d  SignedOn              25     28b 0
                       d  TempSignOff           29     32b 0
                       d  UserSuspSReq          33     36b 0
                       D  UserSuspGJob          37     40b 0
                       D  SignOffPrt            41     44b 0
                       D  BJobMsgW              45     48b 0
                       D  BJobRun               49     52b 0
                       D  BJobRunHld            53     56b 0
                       D  BJobEnd               57     60b 0
                       D  BJobSched             61     64b 0
                       D  BJobHldJQ             65     68b 0
                       D  BJobJQHld             69     72b 0
                       d  BJobUnAsJQ            73     76b 0
                       D  BJobEndPrt            77     80b 0
                  
                       D Fmt_002         DS           256
                       d  F002DateTime                  8    overlay(Fmt_002:9)
                       d  F002System                    8    overlay(Fmt_002:17)
                       d  F002ElapTime          25     30
                       d  RstStateFlg           31     31
                       d  Res_002               32     32
                       D  PCProcUnit            33     36b 0
                       D  JobsInSys             37     40b 0
                       D  PCPermAddr            41     44b 0
                       D  PCTempAddr            45     48b 0
                       D  SystemASP             49     52b 0
                       D  PCAsp                 53     56b 0
                       D  TotAuxStg             57     60b 0
                       D  CurUnpStg             61     64b 0
                       D  MaxUnpStg             65     68b 0
                  
                       D Fmt_003         DS          2048
                       d  F003DateTime                  8    overlay(Fmt_003:9)
                       d  F003System                    8    overlay(Fmt_003:17)
                       d  F003ElapTime          25     30
                       d  Res_003               31     32
                       D  NumPools              33     36b 0
                       D  OffSetPool            37     40b 0
                       D  PoolInfLen            41     44b 0
                       D  PoolData                   1024    overlay(Fmt_003:45)
                  
                       d Store_Data      s            256    dim(4000)
                       d StartPos        s             15  0 inz(0)
                       d Count           s             15  0 inz(0)
                  
                       d Pool_Inf        ds
                       d  A_SysPool              1      4b 0
                       d  A_PoolSiz              5      8b 0
                       d  A_ResSiz               9     12b 0
                       d  A_MaxAct              13     16b 0
                       d  A_DBFault             17     20b 0
                       d  A_DBPage              21     24b 0
                       d  A_NDBFault            25     28b 0
                       d  A_NDBPage             29     32b 0
                       d  A_ActToWait           33     36b 0
                       d  A_WaitInel            37     40b 0
                       d  A_ActInel             41     44b 0
                       d  A_PoolName                   10    Overlay(Pool_Inf:45)
                       d  A_SbsName                    10    Overlay(Pool_Inf:55)
                       d  A_SbsLib                     10    Overlay(Pool_Inf:65)
                       d  A_PagOpt                     10    Overlay(Pool_Inf:75)
                  
                       C     *entry        plist
                       c                   parm                    Format            8
                  
                       c                   select
                       c                   when      Format = 'SSTS0100'
                       c                             or Format = 'SSTS0200'
                       C                   Z-ADD     256           INF_LEN
                       c                   other
                       C                   Z-ADD     2048          INF_LEN
                       c                   endsl
                  
                        * Format SSTS0100 = DSPSYSSTS Basic
                        * Format SSTS0200 = DSPSYSSTS Disk Information (Int/Adv)
                        * Format SSTS0300 = DSPSYSSTS Pool Information (Int/Adv)
                        * Call the API to retrieve the DSPSYSSTS info for this SYS:
                       C                   call      'QWCRSSTS'
                       C                   parm                    Sys_Inf        2048
                       C                   parm                    INF_Len
                       C                   parm      Format        Api_Format        8
                       C                   parm      '*NO'         Stat_Reset       10
                       C                   parm                    Api_Err
                  
                       c                   select
                       c                   when      Format = 'SSTS0100'
                       c                   eval      Fmt_001 = Sys_Inf
                       c                   when      Format = 'SSTS0200'
                       c                   eval      Fmt_002 = Sys_Inf
                       c                   when      Format = 'SSTS0300'
                       c                   eval      Fmt_003 = Sys_Inf
                       c                   eval      StartPos = OffsetPool + 1
                       c                   do        NumPools
                       c                   eval      Count = Count + 1
                       c                   eval      Store_Data(count) =
                       c                             %subst(Fmt_003:StartPos:PoolInfLen)
                       c                   eval      Pool_Inf = Store_Data(Count)
                       c                   eval      StartPos = StartPos + PoolInfLen
                       c                   enddo
                       c                   other
                       c                   endsl
                  
                  
                       c                   eval      *inlr = *on
                       c                   return
                  Hi Jamie,

                  when I am trying to get CPU% from the PCProcUnit field of Fmt_002, its throwing error at calculating the value "StartPos = OffsetPool + 1" as target value is low to hold the result. As OffsetPool is having a system defined type. So I changed StartPos field but I cant go beyond 9 digits for binary. Please Suggest.

                  My requirement is to monitor the CPU% utilisation, if its exceeds the certain limit I need to send a message to all active users to take appropriate action for the job(s) which are comsuming more CPU%.

                  Thanks,
                  Moin

                  Comment


                  • #10
                    Re: Retrieve % Interactive CPU usage

                    Define all your fields as Integer (instead of Binary). Within the data structures you can simply replace the B with an I (because FROM/TO notification is used).

                    For the stand alone field replace the 4B 0 (which was wrong in either way, 9B 0 would have been the correct definition) definition with 10I 0.

                    Birgitta

                    Comment


                    • #11
                      Re: Retrieve % Interactive CPU usage

                      also you need to check the API_ERR after the call to the API. if any error occurred it's highly likely that the return DS will contain default values (which will give you the results you are getting...)
                      I'm not anti-social, I just don't like people -Tommy Holden

                      Comment


                      • #12
                        Re: Retrieve % CPU and %ASP usage

                        Originally posted by tomholden View Post
                        also you need to check the API_ERR after the call to the API. if any error occurred it's highly likely that the return DS will contain default values (which will give you the results you are getting...)
                        Hello All,

                        I am a newbabie to rpg. I want the ASP % of the system checked every four hours and send email if the ASP is greater then 75%.
                        Guys, I tried the above programs and got the error.
                        Pointer or parameter error (C G D F).

                        Thanks in advance.

                        Regards
                        Nilesh

                        Comment

                        Working...
                        X