ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » General IBM MQ Support » Long Running Transaction Script

Post new topic  Reply to topic
 Long Running Transaction Script « View previous topic :: View next topic » 
Author Message
bobbee
PostPosted: Wed Jul 29, 2020 6:14 am    Post subject: Long Running Transaction Script Reply with quote

Knight

Joined: 20 Sep 2001
Posts: 541
Location: Tampa

A while back I asked on the subject title. I have taken the response and created a script. By no means am I the god of shell scripts. IF given a task I can get it done. Will not be the prettiest boat on the river.

I think it can be improved in maybe posting actual IP addresses for the specific connected app. I know you can get that fron CHS but how does one tie a CONN to a CHS.

Anyway, I hope you find this useful. I am, I currently have a client having issues in this area.

Code:

#!/usr/bin/bash
# *********************************************************
# * script to detect long-running UoWs                    *
# * Check for those older than 2 minutes (120 seconds)    *
# * If you want to look for the long UoWs, then you need  *
# * to compare the two fields UOWLOGDA and UOWLOGTI with  *
# * the current time to see how long they are.            *
# *********************************************************
#
# testa=`expr index "$test" C
#
if [ "$1" != "" ]; then
    echo "Positional parameter 1:QMGR Name 1 contains $1"
    qmgr="$1"
else
    echo "Positional parameter 1:QMGR Name is empty"
    exit 0
fi

if [ "$2" != "" ]; then
    echo "Positional parameter 2:LUW Length Seconds 2 contains $2"
    seconds=$2
else
    echo "Positional parameter 1:LUW Length Seconds is empty. Will default to 120 seconds"
    seconds=120
fi

countUoW=0
countlimit=1
DA=0
TI=0
PID=0
APPL=0

discmd="DISPLAY CONN(*) UOWLOGDA UOWLOGTI PID APPLTAG WHERE(UOWLOGTI NE ' ')"

echo $discmd | runmqsc $qmgr > /tmp/runmqsc.out
chmod ugo+rwx /tmp/runmqsc.out

while read p; do

# Bypass first line of report

if [ `echo $p | grep -c "DISPLAY" ` -gt 0 ]
   then
     p=" "
fi

# Lets grab the UOWLOGDA
if [ `echo $p | grep -c "UOWLOGDA" ` -gt 0 ]
   then
          if [ "$DA" = 1 ]
                then
                        echo "WE have an order issue on input"
                        echo "Input line = "
                        echo "$p"
                        echo "ending execution"
                exit 1
          fi
          DA=1
      uowlogda=`echo "$p"| awk -F'(' '{print $2}' | awk -F')' '{print $1}' `
#      echo "string1 (string2) string3" | awk -F '[()]' '{print $2}'
#      echo "string1 {string2} string3" | awk -F '[{}]' '{print $2}'
fi

# Lets grab the UOWLOGTI
if [ `echo $p | grep -c "UOWLOGTI" ` -gt 0 ]
            then
            TI=1
      uowlogti=`echo "$p"| awk -F'(' '{print $3}' | awk -F')' '{print $1}' `
      uowlogti=`echo $uowlogti | sed 's/\./\:/g'`
fi

# Lets grab the PID
if [ `echo $p | grep -c "PID" ` -gt 0 ]
   then
          PID=1
      uowlogpid=`echo "$p"| awk -F'(' '{print $2}' | awk -F')' '{print $1}' `
fi

# Lets grab the APPLTAG
if [ `echo $p | grep -c "APPLTAG" ` -gt 0 ]
   then
          APPL=1
      uowlogappltag=`echo "$p"| awk -F'(' '{print $3}' | awk -F')' '{print $1}' `
fi

if [ "$DA" = 1 ] && [ "$TI" = 1 ] && [ "$PID" = 1 ] && [ "$APPL" = 1 ]
   then
        DA=0
      TI=0
      PID=0
      APPL=0
# Calculate the current date and time in EPOC time
      E1=$(date +%'s')
      sp=" "
      E2date=$uowlogda$sp$uowlogti
# Calculate the UOW date and time in EPOC seconds
      E2=$(date -d "$E2date" +%s)
# Calculate the UOW age in seconds
      uowage=$(($E1 - E2))
# Is the UOW time longer than our set threshold (defaults to 120 seconds)
      if [ $uowage -gt $seconds ]
         then
         countUoW=$((countUoW+1))
         echo "Long-running UoW ("$uowage seconds, PID=$uowlogpid , APPLTAG=$uowlogappltag")"
      fi
fi

done < /tmp/runmqsc.out

if [ $countUoW -lt $countlimit ]
   then
   echo "No long-running UoW older than", $seconds, "seconds"
fi
Back to top
View user's profile Send private message Send e-mail AIM Address
bobbee
PostPosted: Wed Jul 29, 2020 6:44 am    Post subject: Reply with quote

Knight

Joined: 20 Sep 2001
Posts: 541
Location: Tampa

I updated the script from a few minutes ago. Customer found a bug. In testing I had only one CONN running. It did not reset properly for repeated CONNs. It was the placement of DA=0 and the other three switches.
Back to top
View user's profile Send private message Send e-mail AIM Address
fjb_saper
PostPosted: Wed Jul 29, 2020 1:42 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20695
Location: LI,NY

Thanks for sharing Bobbee
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
hughson
PostPosted: Thu Jul 30, 2020 7:16 pm    Post subject: Re: Long Running Transaction Script Reply with quote

Padawan

Joined: 09 May 2013
Posts: 1914
Location: Bay of Plenty, New Zealand

bobbee wrote:
I think it can be improved in maybe posting actual IP addresses for the specific connected app. I know you can get that fron CHS but how does one tie a CONN to a CHS.


Why not just take the IP Address from the DISPLAY CONN field called CONNAME?

This script seems familiar. Is it based off this?

Long Running UoWs

Makes for an interesting comparison between the two scripting languages.

Cheers,
Morag
_________________
Morag Hughson @MoragHughson
IBM MQ Technical Education Specialist
Get your IBM MQ training here!
MQGem Software
Back to top
View user's profile Send private message Visit poster's website
bobbee
PostPosted: Thu Aug 06, 2020 9:50 am    Post subject: Reply with quote

Knight

Joined: 20 Sep 2001
Posts: 541
Location: Tampa

"When will it end. When it's finished"

Famous quote but it is all to true. After running some tests at customer, the script was presented with some formats of the output it was not perp'd for. Went back and cleaned it up.

Code:
#!/usr/bin/bash
# *********************************************************
# * script to detect long-running UoWs                    *
# * Check for those older than 2 minutes (120 seconds)    *
# * If you want to look for the long UoWs, then you need  *
# * to compare the two fields UOWLOGDA and UOWLOGTI with  *
# * the current time to see how long they are.            *
# *********************************************************
#
# See if we were passed a Queue Manager name
if [ "$1" != "" ]; then
    echo "Positional parameter 1:QMGR Name 1 contains $1"
    qmgr="$1"
else
    echo "Positional parameter 1:QMGR Name is empty"
    exit 0
fi

# See if we were passed a time limit in seconds
if [ "$2" != "" ]; then
    echo "Positional parameter 2:LUW Length Seconds 2 contains $2"
    seconds=$2
else
    echo "Positional parameter 1:LUW Length Seconds is empty. Will default to 120 seconds"
    seconds=120
fi

# Switches

countUoW=0
countlimit=1
DA=0
TI=0
PID=0
APPL=0

# Search Literals

lit_uowlogda="UOWLOGDA"
lit_uowlogti="UOWLOGTI"
lit_pid="PID"
lit_appltag="APPLTAG"

# Set the runmqsc display command
discmd="DISPLAY CONN(*) UOWLOGDA UOWLOGTI PID APPLTAG WHERE(UOWLOGTI NE ' ')"

# Run the command and pipe the utput to a file
echo $discmd | runmqsc $qmgr > /tmp/runmqsc.out

# Make the output file useable
chmod ugo+rwx /tmp/runmqsc.out

# lets loop through the output file
while read p; do

# Bypass first line of report
if [ `echo $p | grep -c "DISPLAY" ` -gt 0 ]
   then
     p=" "
fi

# Lets look for UOWLOGDA parameter
if [ `echo $p | grep -c "UOWLOGDA" ` -gt 0 ]
   then
# Have we saw the UOWLOGDA parameter before reporting, yes, we have an issue         
       if [ "$DA" = 1 ]
          then
            echo "WE have an order issue on input"
            echo "Input line = "
            echo "$p"
            echo "ending execution"
            exit 1
       fi
# indicate we have the LOGDA parameter       
       DA=1
# Find the position of UOWLOGDA and go after the date
       position=`awk -v a="$p" -v b="$lit_uowlogda" 'BEGIN{print index(a,b)}'`
       position="$((position+8))"
       uowlogda="${p:$position:10}"

fi

# Lets look for the UOWLOGTI parameter
if [ `echo $p | grep -c "UOWLOGTI" ` -gt 0 ]
   then
# Indicate we have found it
     TI=1
# Lets extract the time and format it
     position=`awk -v a="$p" -v b="$lit_uowlogti" 'BEGIN{print index(a,b)}'`
     position="$((position+8))"
     uowlogti="${p:$position:8}"
     uowlogti=`echo $uowlogti | sed 's/\./\:/g'`
fi

# Lets look for the PID parameter
if [ `echo $p | grep -c "PID" ` -gt 0 ]
   then
# indicate we have found it      
     PID=1
# Let extract the value for PID
# is it at the beginning of the line or a second parameter on the same line     
     position=`awk -v a="$p" -v b="$lit_pid" 'BEGIN{print index(a,b)}'`
     if [ "$position" -lt 8 ]
        then
# First parameter
          uowlogpid=`echo "$p"| awk -F'(' '{print $2}' | awk -F')' '{print $1}' `
        else
# Second parameter       
          uowlogpid=`echo "$p"| awk -F'(' '{print $3}' | awk -F')' '{print $1}' `
     fi
fi

# Lets extract APPLTAG
if [ `echo $p | grep -c "APPLTAG" ` -gt 0 ]
   then
# we found it, lets indicate that      
     APPL=1
# Let extract the value for PID
# is it at the beginning of the line or a second parameter on the same line
     position=`awk -v a="$p" -v b="$lit_appltag" 'BEGIN{print index(a,b)}'`
     if [ "$position" -lt 8 ]
        then
# First parameter
          uowlogappltag=`echo "$p"| awk -F'(' '{print $2}' | awk -F')' '{print $1}' `
        else
# Second parameter
          uowlogappltag=`echo "$p"| awk -F'(' '{print $3}' | awk -F')' '{print $1}' `
     fi
#     echo "uowlogappltag = $uowlogappltag"
fi

# Have all 4 fields been found
if [ "$DA" = 1 ] && [ "$TI" = 1 ] && [ "$PID" = 1 ] && [ "$APPL" = 1 ]
   then
# They have been found, turn them off so we can get the next one after this
     DA=0
     TI=0
     PID=0
     APPL=0
# Calculate the current date and time in EPOC time
     E1=$(date +%'s')
     sp=" "
Concat Date and Time
     E2date=$uowlogda$sp$uowlogti
# Calculate the UOW date and time in EPOC seconds
     E2=$(date -d "$E2date" +%s)
# Calculate the UOW age in seconds
     uowage=$(($E1 - E2))
# Is the UOW time longer than our set threshold (defaults to 120 seconds)
     if [ $uowage -gt $seconds ]
        then
          countUoW=$((countUoW+1))
          echo "Long-running UoW ("$uowage seconds, PID=$uowlogpid , APPLTAG=$uowlogappltag")"
     fi
fi

done < /tmp/runmqsc.out

if [ $countUoW -lt $countlimit ]
   then
   echo "No long-running UoW older than", $seconds, "seconds"
fi
Back to top
View user's profile Send private message Send e-mail AIM Address
gbaddeley
PostPosted: Thu Aug 06, 2020 2:57 pm    Post subject: Reply with quote

Jedi

Joined: 25 Mar 2003
Posts: 2491
Location: Melbourne, Australia

To me, this is inefficient code:
Code:

     position=`awk -v a="$p" -v b="$lit_pid" 'BEGIN{print index(a,b)}'`
     if [ "$position" -lt 8 ]
        then
# First parameter
          uowlogpid=`echo "$p"| awk -F'(' '{print $2}' | awk -F')' '{print $1}' `
        else
# Second parameter       
          uowlogpid=`echo "$p"| awk -F'(' '{print $3}' | awk -F')' '{print $1}' `
     fi

Have you considered doing this in one awk command? ie. position is a variable inside an awk program, not a shell variable. You can then use the substr function to pull out the value.
_________________
Glenn
Back to top
View user's profile Send private message
bobbee
PostPosted: Fri Aug 07, 2020 3:30 am    Post subject: Reply with quote

Knight

Joined: 20 Sep 2001
Posts: 541
Location: Tampa

Anyone in the community can now take this and update it to their hearts content. I got the ball rolling down the hill. Thanks for the suggestion.
Back to top
View user's profile Send private message Send e-mail AIM Address
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » General IBM MQ Support » Long Running Transaction Script
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.