KMPETMRT ;SP/JML - Collect Cache Metrics for the Real-Time Error Trap Monitor ;2/1/2023
;;4.0;CAPACITY MANAGEMENT;**1,2,3,4**;3/1/2018;Build 36
;
; Reference to $$WORKDAY^XUWORKDY in ICR #10046
; Reference to $$HTFM^XLFDT in ICR #10103
; Reference to GETENV^%ZOSV, EC^%ZOSV and LGR^%ZOSV in ICR #10097
; Reference to $ESTACK, $ETRAP, ^%ZTER and UNWIND^%ZTER in ICR #1621
;
RUN ;
N $ESTACK,$ETRAP S $ETRAP="D ^%ZTER Q"
I $$GETVAL^KMPVCCFG("VETM","ONOFF",8969,"I") D RU^%ZOSVKR("KMP VETM DRIVER")
N KMPCHKH,KMPFMDAY,KMPH,KMPHANG,KMPINST,KMPNDTYP,KMPPARMS,KMPSINF,KMPSINT,KMPSTOP,KMPVNODE,KMPVTEST,KMPWORK,U,Y
N ZTDESC,ZTDTH,ZTRTN,ZTSAVE
;
; ALWAYS - verify data is not building past configured number of days - if so for any reason, delete it
D PURGEDLY^KMPVCBG("VETM")
; Quit if monitor is not turned on
I $$GETVAL^KMPVCCFG("VETM","ONOFF",8969)'="ON" D Q
.I $$GETVAL^KMPVCCFG("VETM","ONOFF",8969,"I") D RU^%ZOSVKR("KMP VETM DRIVER END")
; Environment Check
; if TEST system - quit if system is a front end OR allow test=no
; if PROD system - quit if system is a front end AND allow test=no
S KMPVTEST=$$GETVAL^KMPVCCFG("VETM","ALLOW TEST SYSTEM",8969,"I")
D GETENV^%ZOSV S KMPVNODE=$P(Y,U,3)_":"_$P($P(Y,U,4),":",2) ;supported by ICR #10097
I $$PROD^KMPVCCFG'="prod" I ($$ISBENODE^KMPVCCFG(KMPVNODE)=0)!(KMPVTEST=0) Q
I $$PROD^KMPVCCFG="prod" I ($$ISBENODE^KMPVCCFG(KMPVNODE)=0)&(KMPVTEST=0) Q
;
S U="^"
S KMPFMDAY=+$$HTFM^XLFDT($H,1) ;supported by ICR #10103
S KMPWORK=$$WORKDAY^XUWORKDY(KMPFMDAY) ;supported by ICR #10046
S KMPSINF=$$SITEINFO^KMPVCCFG() ; site name^fac num^mail domain^prod/test^site code
; Main loop - tasks off collection to keep interval intact
S ^KMPTMP("KMPV","VETM","TEMP")=0
S KMPSTOP=0,KMPCHKH=+$H
S KMPINST=$P(KMPVNODE,":",2),KMPNDTYP=$$NODETYPE^KMPUTLW(KMPINST)
S KMPPARMS("KMPFMDAY")=KMPFMDAY,KMPPARMS("KMPCHKH")=KMPCHKH
S KMPPARMS("KMPWORK")=KMPWORK,KMPPARMS("KMPSINF")=KMPSINF
S KMPPARMS("KMPINST")=KMPINST,KMPPARMS("KMPNDTYP")=KMPNDTYP
F D Q:KMPSTOP
.I $$GETVAL^KMPVCCFG("VETM","ONOFF",8969)'="ON" S KMPSTOP=1 Q ; RUN FLAG SET TO 0
.S KMPH=$H
.I KMPH>KMPCHKH SET KMPSTOP=1 Q
.S KMPSINT=$$GETVAL^KMPVCCFG("VETM","COLLECTION INTERVAL",8969)
.S KMPHANG=KMPSINT*60
.S KMPPARMS("KMPH")=KMPH,KMPPARMS("KMPSINT")=KMPSINT
.M ^KMPTMP("KMPV","VETM",KMPVNODE,"PARMS")=KMPPARMS
.J COLLECT(KMPVNODE)
.H KMPHANG
I $$GETVAL^KMPVCCFG("VETM","ONOFF",8969,"I") D RU^%ZOSVKR("KMP VETM DRIVER END")
Q
;
COLLECT(KMPVNODE) ;
N $ES,$ETRAP S $ETRAP="D ^%ZTER Q"
I $$GETVAL^KMPVCCFG("VETM","ONOFF",8969,"I") D RU^%ZOSVKR("KMP VETM COLLECTOR")
N B,KMPAJN,KMPDB,KMPCIO,KMPCNT,KMPDAT,KMPDBI,KMPDST,KMPEARR,KMPEDATA,KMPEDATE,KMPELINE,KMPENUM,KMPERR,KMPERRN
N KMPETSO,KMPH,KMPINODE,KMPINST,KMPJMSG,KMPJNODE,KMPJNUM,KMPJSON,KMPLGR,KMPNDTYP,KMPNT,KMPPNAM,KMPSLOT,KMPSTAT,KMPTIMES
N KMPTS,KMPUNAM,KMPUTCE,KMPUTCO,KMPZA,KMPZB,KMPZIO
;
M KMPPARMS=^KMPTMP("KMPV","VETM",KMPVNODE,"PARMS")
S KMPFMDAY=KMPPARMS("KMPFMDAY")
S KMPWORK=KMPPARMS("KMPWORK"),KMPSINF=KMPPARMS("KMPSINF")
S KMPCHKH=KMPPARMS("KMPCHKH"),U="^"
S KMPH=KMPPARMS("KMPH"),KMPSINT=KMPPARMS("KMPSINT")
S KMPINST=KMPPARMS("KMPINST"),KMPNDTYP=KMPPARMS("KMPNDTYP")
;
S KMPJSON=##class(%DynamicObject).%New()
S KMPJMSG=##class(%DynamicObject).%New()
S KMPEARR=##class(%DynamicArray).%New()
;
S KMPJSON.Function="VETM"
S KMPSLOT=$$SLOT^KMPVCCFG(KMPH,KMPSINT,"HOROLOG")
S $P(KMPH,",",2)=KMPSLOT
S KMPTIMES=$$TSTAMP^KMPUTLW(KMPH,"HOROLOG",1) ; yyy-mm-dd hh:mm:ssZts
S KMPETSO=$P(KMPTIMES,"^")
S KMPUTCO=$P(KMPTIMES,"^",2)
S KMPUTCE=$P(KMPTIMES,"^",3)
S KMPDST=$P(KMPTIMES,"^",4)
;
D SITE^KMPUTLW(KMPJSON)
S KMPJMSG.Timestamp=KMPETSO,KMPJMSG.UtcOdbc=KMPUTCO
S KMPJMSG.UtcEpoch=KMPUTCE,KMPJMSG.IsDst=KMPDST
S KMPJMSG.Node=$P(KMPVNODE,":"),KMPJMSG.NodeType=KMPNDTYP
S KMPJMSG.Instance=KMPINST,KMPJMSG.Workday=KMPWORK
S KMPJMSG.NodeType=KMPNDTYP
S KMPJMSG.Date=$$SHORTDAT^KMPUTLW(+$H,"HOROLOG")
S KMPJSON.MessageData=KMPJMSG
;
; Get metrics
S KMPDAT=+KMPH,KMPCNT=0
S KMPENUM=+$G(^KMPTMP("KMPV","VETM","TEMP"))
F S KMPENUM=$O(^%ZTER(1,KMPDAT,1,KMPENUM)) Q:+KMPENUM=0 D
.S KMPCNT=KMPCNT+1
.S KMPELINE="",B="|"
.S KMPJNODE=$G(^%ZTER(1,KMPDAT,1,KMPENUM,"J"))
.S KMPINODE=$G(^%ZTER(1,KMPDAT,1,KMPENUM,"I"))
.S KMPEDATE=$G(^%ZTER(1,KMPDAT,1,KMPENUM,"H"))
.S KMPTS=$P($$TSTAMP^KMPUTLW(KMPEDATE,"HOROLOG",1),"^")
.S KMPDBI=$P(KMPJNODE,"^",4),KMPDB=$P(KMPDBI,":",1)
.S KMPINST=$P(KMPDBI,":",2),KMPNT=$$NODETYPE^KMPUTLW(KMPINST)
.S KMPERRN=+$G(^%ZTER(1,KMPDAT,1,KMPENUM,0)),KMPERR=$G(^%ZTER(1,KMPDAT,1,KMPENUM,"ZE"))
.S KMPLGR=$G(^%ZTER(1,KMPDAT,1,KMPENUM,"GR"))
.S KMPLGR=$TR(KMPLGR,"|","b")
.S KMPCIO=$TR($P(KMPINODE,"^",1),"|","~"),KMPZA=$P(KMPINODE,"^",2)
.S KMPZB=$P(KMPINODE,"^",3),KMPZIO=$TR($P(KMPINODE,"^",4),"|","~")
.I KMPZA["|" S KMPZA=$REPLACE(KMPZA,"|","VerticalBar")
.I KMPZB["|" S KMPZB=$REPLACE(KMPZB,"|","VerticalBar")
.I KMPZIO["|" S KMPZIO=$REPLACE(KMPZIO,"|","VerticalBar")
.S KMPJNUM=$P(KMPJNODE,"^",1),KMPPNAM=$P(KMPJNODE,"^",2)
.S KMPUNAM=$P(KMPJNODE,"^",3),KMPAJN=$P(KMPJNODE,"^",5)
.S KMPELINE=$G(^%ZTER(1,KMPDAT,1,KMPENUM,"LINE"))
.S KMPEDATA=KMPERRN_B_KMPTS_B_KMPTS_B_KMPDB_B_KMPINST_B_KMPNT_B_KMPERR_B_KMPLGR_B_KMPCIO_B
.S KMPEDATA=KMPEDATA_KMPZA_B_KMPZB_B_KMPZIO_B_KMPJNUM_B_KMPPNAM_B_KMPUNAM_B_KMPAJN_B_KMPELINE
.D KMPEARR.%Push(KMPEDATA)
.S ^KMPTMP("KMPV","VETM","TEMP")=KMPENUM
S KMPJSON.Details=KMPEARR
I KMPCNT=0 D Q
.I $$GETVAL^KMPVCCFG("VETM","ONOFF",8969,"I") D RU^%ZOSVKR("KMP VETM COLLECTOR END")
;
S KMPSTAT=$$POST^KMPUTLW(KMPJSON,"/errortrap",,"VETM")
I +KMPSTAT'=200 H 30 S KMPSTAT=$$POST^KMPUTLW(KMPJSON,"/errortrap",,"VETM")
S ^XTMP("KMP "_KMPFMDAY,"VETM","HTTP",KMPVNODE,$P($H,",",2))=KMPSTAT
I $$GETVAL^KMPVCCFG("VETM","ONOFF",8969,"I") D RU^%ZOSVKR("KMP VETM COLLECTOR END")
I +KMPSTAT'=200 D SETRETRY
Q
;
SETRETRY ;
N KMPTEXT
S KMPTEXT("SUBJECT")="VSM FAILED SEND: VETM at "_KMPJSON.Site.SiteCode
S KMPTEXT(1)="Status Code: "_+KMPSTAT
S KMPTEXT(2)="Status Text: "_$P(KMPSTAT,"^",2)
S KMPTEXT(3)="Response Time: "_$P(KMPSTAT,"^",3)
S KMPTEXT(4)="Node: "_KMPVNODE
D INFOMSG^KMPUTLW(.KMPTEXT)
S ^KMPTMP("KMPV","VETM","RETRY",KMPVNODE,+$H,$H)=KMPJSON.%ToJSON()
Q
;
RETRY ; retry failed POSTS
N KMPDAY,KMPI,KMPJSON,KMPSTAT,KMPVNODE,Y
;
D GETENV^%ZOSV S KMPVNODE=$P(Y,"^",3)_":"_$P($P(Y,"^",4),":",2) ;supported by ICR #10097
S KMPDAY=""
F S KMPDAY=$O(^KMPTMP("KMPV","VETM","RETRY",KMPVNODE,KMPDAY)) Q:KMPDAY="" D
.S KMPI=""
.F S KMPI=$O(^KMPTMP("KMPV","VETM","RETRY",KMPVNODE,KMPDAY,KMPI)) Q:KMPI="" D
..S KMPJSON=$G(^KMPTMP("KMPV","VETM","RETRY",KMPVNODE,KMPDAY,KMPI))
..S KMPSTAT=$$POST^KMPUTLW({}.%FromJSON(KMPJSON),"/errortrap",,"VETM")
..I +KMPSTAT=200 K ^KMPTMP("KMPV","VETM","RETRY",KMPVNODE,KMPDAY,KMPI)
..H $R(10)
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HKMPETMRT 6917 printed Dec 13, 2024@01:41:25 Page 2
KMPETMRT ;SP/JML - Collect Cache Metrics for the Real-Time Error Trap Monitor ;2/1/2023
+1 ;;4.0;CAPACITY MANAGEMENT;**1,2,3,4**;3/1/2018;Build 36
+2 ;
+3 ; Reference to $$WORKDAY^XUWORKDY in ICR #10046
+4 ; Reference to $$HTFM^XLFDT in ICR #10103
+5 ; Reference to GETENV^%ZOSV, EC^%ZOSV and LGR^%ZOSV in ICR #10097
+6 ; Reference to $ESTACK, $ETRAP, ^%ZTER and UNWIND^%ZTER in ICR #1621
+7 ;
RUN ;
+1 NEW $ESTACK,$ETRAP
SET $ETRAP="D ^%ZTER Q"
+2 IF $$GETVAL^KMPVCCFG("VETM","ONOFF",8969,"I")
DO RU^%ZOSVKR("KMP VETM DRIVER")
+3 NEW KMPCHKH,KMPFMDAY,KMPH,KMPHANG,KMPINST,KMPNDTYP,KMPPARMS,KMPSINF,KMPSINT,KMPSTOP,KMPVNODE,KMPVTEST,KMPWORK,U,Y
+4 NEW ZTDESC,ZTDTH,ZTRTN,ZTSAVE
+5 ;
+6 ; ALWAYS - verify data is not building past configured number of days - if so for any reason, delete it
+7 DO PURGEDLY^KMPVCBG("VETM")
+8 ; Quit if monitor is not turned on
+9 IF $$GETVAL^KMPVCCFG("VETM","ONOFF",8969)'="ON"
Begin DoDot:1
+10 IF $$GETVAL^KMPVCCFG("VETM","ONOFF",8969,"I")
DO RU^%ZOSVKR("KMP VETM DRIVER END")
End DoDot:1
QUIT
+11 ; Environment Check
+12 ; if TEST system - quit if system is a front end OR allow test=no
+13 ; if PROD system - quit if system is a front end AND allow test=no
+14 SET KMPVTEST=$$GETVAL^KMPVCCFG("VETM","ALLOW TEST SYSTEM",8969,"I")
+15 ;supported by ICR #10097
DO GETENV^%ZOSV
SET KMPVNODE=$PIECE(Y,U,3)_":"_$PIECE($PIECE(Y,U,4),":",2)
+16 IF $$PROD^KMPVCCFG'="prod"
IF ($$ISBENODE^KMPVCCFG(KMPVNODE)=0)!(KMPVTEST=0)
QUIT
+17 IF $$PROD^KMPVCCFG="prod"
IF ($$ISBENODE^KMPVCCFG(KMPVNODE)=0)&(KMPVTEST=0)
QUIT
+18 ;
+19 SET U="^"
+20 ;supported by ICR #10103
SET KMPFMDAY=+$$HTFM^XLFDT($HOROLOG,1)
+21 ;supported by ICR #10046
SET KMPWORK=$$WORKDAY^XUWORKDY(KMPFMDAY)
+22 ; site name^fac num^mail domain^prod/test^site code
SET KMPSINF=$$SITEINFO^KMPVCCFG()
+23 ; Main loop - tasks off collection to keep interval intact
+24 SET ^KMPTMP("KMPV","VETM","TEMP")=0
+25 SET KMPSTOP=0
SET KMPCHKH=+$HOROLOG
+26 SET KMPINST=$PIECE(KMPVNODE,":",2)
SET KMPNDTYP=$$NODETYPE^KMPUTLW(KMPINST)
+27 SET KMPPARMS("KMPFMDAY")=KMPFMDAY
SET KMPPARMS("KMPCHKH")=KMPCHKH
+28 SET KMPPARMS("KMPWORK")=KMPWORK
SET KMPPARMS("KMPSINF")=KMPSINF
+29 SET KMPPARMS("KMPINST")=KMPINST
SET KMPPARMS("KMPNDTYP")=KMPNDTYP
+30 FOR
Begin DoDot:1
+31 ; RUN FLAG SET TO 0
IF $$GETVAL^KMPVCCFG("VETM","ONOFF",8969)'="ON"
SET KMPSTOP=1
QUIT
+32 SET KMPH=$HOROLOG
+33 IF KMPH>KMPCHKH
SET KMPSTOP=1
QUIT
+34 SET KMPSINT=$$GETVAL^KMPVCCFG("VETM","COLLECTION INTERVAL",8969)
+35 SET KMPHANG=KMPSINT*60
+36 SET KMPPARMS("KMPH")=KMPH
SET KMPPARMS("KMPSINT")=KMPSINT
+37 MERGE ^KMPTMP("KMPV","VETM",KMPVNODE,"PARMS")=KMPPARMS
+38 JOB COLLECT(KMPVNODE)
+39 HANG KMPHANG
End DoDot:1
if KMPSTOP
QUIT
+40 IF $$GETVAL^KMPVCCFG("VETM","ONOFF",8969,"I")
DO RU^%ZOSVKR("KMP VETM DRIVER END")
+41 QUIT
+42 ;
COLLECT(KMPVNODE) ;
+1 NEW $ESTACK,$ETRAP
SET $ETRAP="D ^%ZTER Q"
+2 IF $$GETVAL^KMPVCCFG("VETM","ONOFF",8969,"I")
DO RU^%ZOSVKR("KMP VETM COLLECTOR")
+3 NEW B,KMPAJN,KMPDB,KMPCIO,KMPCNT,KMPDAT,KMPDBI,KMPDST,KMPEARR,KMPEDATA,KMPEDATE,KMPELINE,KMPENUM,KMPERR,KMPERRN
+4 NEW KMPETSO,KMPH,KMPINODE,KMPINST,KMPJMSG,KMPJNODE,KMPJNUM,KMPJSON,KMPLGR,KMPNDTYP,KMPNT,KMPPNAM,KMPSLOT,KMPSTAT,KMPTIMES
+5 NEW KMPTS,KMPUNAM,KMPUTCE,KMPUTCO,KMPZA,KMPZB,KMPZIO
+6 ;
+7 MERGE KMPPARMS=^KMPTMP("KMPV","VETM",KMPVNODE,"PARMS")
+8 SET KMPFMDAY=KMPPARMS("KMPFMDAY")
+9 SET KMPWORK=KMPPARMS("KMPWORK")
SET KMPSINF=KMPPARMS("KMPSINF")
+10 SET KMPCHKH=KMPPARMS("KMPCHKH")
SET U="^"
+11 SET KMPH=KMPPARMS("KMPH")
SET KMPSINT=KMPPARMS("KMPSINT")
+12 SET KMPINST=KMPPARMS("KMPINST")
SET KMPNDTYP=KMPPARMS("KMPNDTYP")
+13 ;
+14 SET KMPJSON=##class(%DynamicObject).%New()
+15 SET KMPJMSG=##class(%DynamicObject).%New()
+16 SET KMPEARR=##class(%DynamicArray).%New()
+17 ;
+18 SET KMPJSON.Function="VETM"
+19 SET KMPSLOT=$$SLOT^KMPVCCFG(KMPH,KMPSINT,"HOROLOG")
+20 SET $PIECE(KMPH,",",2)=KMPSLOT
+21 ; yyy-mm-dd hh:mm:ssZts
SET KMPTIMES=$$TSTAMP^KMPUTLW(KMPH,"HOROLOG",1)
+22 SET KMPETSO=$PIECE(KMPTIMES,"^")
+23 SET KMPUTCO=$PIECE(KMPTIMES,"^",2)
+24 SET KMPUTCE=$PIECE(KMPTIMES,"^",3)
+25 SET KMPDST=$PIECE(KMPTIMES,"^",4)
+26 ;
+27 DO SITE^KMPUTLW(KMPJSON)
+28 SET KMPJMSG.Timestamp=KMPETSO
SET KMPJMSG.UtcOdbc=KMPUTCO
+29 SET KMPJMSG.UtcEpoch=KMPUTCE
SET KMPJMSG.IsDst=KMPDST
+30 SET KMPJMSG.Node=$PIECE(KMPVNODE,":")
SET KMPJMSG.NodeType=KMPNDTYP
+31 SET KMPJMSG.Instance=KMPINST
SET KMPJMSG.Workday=KMPWORK
+32 SET KMPJMSG.NodeType=KMPNDTYP
+33 SET KMPJMSG.Date=$$SHORTDAT^KMPUTLW(+$HOROLOG,"HOROLOG")
+34 SET KMPJSON.MessageData=KMPJMSG
+35 ;
+36 ; Get metrics
+37 SET KMPDAT=+KMPH
SET KMPCNT=0
+38 SET KMPENUM=+$GET(^KMPTMP("KMPV","VETM","TEMP"))
+39 FOR
SET KMPENUM=$ORDER(^%ZTER(1,KMPDAT,1,KMPENUM))
if +KMPENUM=0
QUIT
Begin DoDot:1
+40 SET KMPCNT=KMPCNT+1
+41 SET KMPELINE=""
SET B="|"
+42 SET KMPJNODE=$GET(^%ZTER(1,KMPDAT,1,KMPENUM,"J"))
+43 SET KMPINODE=$GET(^%ZTER(1,KMPDAT,1,KMPENUM,"I"))
+44 SET KMPEDATE=$GET(^%ZTER(1,KMPDAT,1,KMPENUM,"H"))
+45 SET KMPTS=$PIECE($$TSTAMP^KMPUTLW(KMPEDATE,"HOROLOG",1),"^")
+46 SET KMPDBI=$PIECE(KMPJNODE,"^",4)
SET KMPDB=$PIECE(KMPDBI,":",1)
+47 SET KMPINST=$PIECE(KMPDBI,":",2)
SET KMPNT=$$NODETYPE^KMPUTLW(KMPINST)
+48 SET KMPERRN=+$GET(^%ZTER(1,KMPDAT,1,KMPENUM,0))
SET KMPERR=$GET(^%ZTER(1,KMPDAT,1,KMPENUM,"ZE"))
+49 SET KMPLGR=$GET(^%ZTER(1,KMPDAT,1,KMPENUM,"GR"))
+50 SET KMPLGR=$TRANSLATE(KMPLGR,"|","b")
+51 SET KMPCIO=$TRANSLATE($PIECE(KMPINODE,"^",1),"|","~")
SET KMPZA=$PIECE(KMPINODE,"^",2)
+52 SET KMPZB=$PIECE(KMPINODE,"^",3)
SET KMPZIO=$TRANSLATE($PIECE(KMPINODE,"^",4),"|","~")
+53 IF KMPZA["|"