Skip to content

Commit f34f9e9

Browse files
committed
Add time-since metrics for queues and channels
Add QMSTATUS and TPSTATUS fields
1 parent 508b6e1 commit f34f9e9

File tree

7 files changed

+866
-9
lines changed

7 files changed

+866
-9
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Changelog
22
Newest updates are at the top of this file.
33

4+
## April 03 2019
5+
* mqmetric - Added last put/get time metric for queues
6+
* mqmetric - Added last msg time metric for channels
7+
* mqmetric - Added fields from QMSTATUS and TPSTATUS
8+
49
## April 1 2019
510
* Added scripts to compile samples inside a container
611

mqmetric/channel.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/ibm-messaging/mq-golang/ibmmq"
3434
"regexp"
3535
"strings"
36+
"time"
3637
)
3738

3839
const (
@@ -47,6 +48,7 @@ const (
4748
ATTR_CHL_SUBSTATE = "substate"
4849
ATTR_CHL_TYPE = "type"
4950
ATTR_CHL_INSTANCE_TYPE = "instance_type"
51+
ATTR_CHL_SINCE_MSG = "time_since_msg"
5052

5153
SQUASH_CHL_STATUS_STOPPED = 0
5254
SQUASH_CHL_STATUS_TRANSITION = 1
@@ -74,13 +76,13 @@ func ChannelInitAttributes() {
7476
// These fields are used to construct the key to the per-channel map values and
7577
// as tags to uniquely identify a channel instance
7678
attr := ATTR_CHL_NAME
77-
ChannelStatus.Attributes[attr] = newStatusAttribute(attr, "Channel Name", -1)
79+
ChannelStatus.Attributes[attr] = newPseudoStatusAttribute(attr, "Channel Name")
7880
attr = ATTR_CHL_RQMNAME
79-
ChannelStatus.Attributes[attr] = newStatusAttribute(attr, "Remote Queue Manager Name", -1)
81+
ChannelStatus.Attributes[attr] = newPseudoStatusAttribute(attr, "Remote Queue Manager Name")
8082
attr = ATTR_CHL_JOBNAME
81-
ChannelStatus.Attributes[attr] = newStatusAttribute(attr, "MCA Job Name", -1)
83+
ChannelStatus.Attributes[attr] = newPseudoStatusAttribute(attr, "MCA Job Name")
8284
attr = ATTR_CHL_CONNNAME
83-
ChannelStatus.Attributes[attr] = newStatusAttribute(attr, "Connection Name", -1)
85+
ChannelStatus.Attributes[attr] = newPseudoStatusAttribute(attr, "Connection Name")
8486

8587
// These are the integer status fields that are of interest
8688
attr = ATTR_CHL_MESSAGES
@@ -104,6 +106,9 @@ func ChannelInitAttributes() {
104106
ChannelStatus.Attributes[attr] = newStatusAttribute(attr, "Channel Status - Simplified", ibmmq.MQIACH_CHANNEL_STATUS)
105107
ChannelStatus.Attributes[attr].squash = true
106108
chlAttrsInit = true
109+
110+
attr = ATTR_CHL_SINCE_MSG
111+
ChannelStatus.Attributes[attr] = newStatusAttribute(attr, "Time Since Msg", -1)
107112
}
108113

109114
// If we need to list the channels that match a pattern. Not needed for
@@ -285,6 +290,9 @@ func parseChlData(instanceType int32, cfh *ibmmq.MQCFH, buf []byte) string {
285290
startTime := ""
286291
key := ""
287292

293+
lastMsgDate := ""
294+
lastMsgTime := ""
295+
288296
parmAvail := true
289297
bytesRead := 0
290298
offset := 0
@@ -389,9 +397,20 @@ func parseChlData(instanceType int32, cfh *ibmmq.MQCFH, buf []byte) string {
389397
}
390398
}
391399
}
400+
} else {
401+
switch elem.Parameter {
402+
case ibmmq.MQCACH_LAST_MSG_TIME:
403+
lastMsgTime = strings.TrimSpace(elem.String[0])
404+
case ibmmq.MQCACH_LAST_MSG_DATE:
405+
lastMsgDate = strings.TrimSpace(elem.String[0])
406+
}
392407
}
393408
}
394409

410+
now := time.Now()
411+
diff := statusTimeDiff(now, lastMsgDate, lastMsgTime)
412+
ChannelStatus.Attributes[ATTR_CHL_SINCE_MSG].Values[key] = newStatusValueInt64(diff)
413+
395414
return key
396415
}
397416

mqmetric/mqif.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ to be used for all responses including the publications
5959
*/
6060
func InitConnection(qMgrName string, replyQ string, cc *ConnectionConfig) error {
6161
var err error
62+
var errorString = ""
63+
6264
gocno := ibmmq.NewMQCNO()
6365
gocsp := ibmmq.NewMQCSP()
6466

@@ -80,6 +82,8 @@ func InitConnection(qMgrName string, replyQ string, cc *ConnectionConfig) error
8082
qMgr, err = ibmmq.Connx(qMgrName, gocno)
8183
if err == nil {
8284
qmgrConnected = true
85+
} else {
86+
errorString = "Cannot connect to queue manager " + qMgrName
8387
}
8488

8589
// Discover important information about the qmgr - its real name
@@ -109,6 +113,7 @@ func InitConnection(qMgrName string, replyQ string, cc *ConnectionConfig) error
109113
commandLevel = v[ibmmq.MQIA_COMMAND_LEVEL].(int32)
110114
if commandLevel < 900 && platform != ibmmq.MQPL_ZOS && platform != ibmmq.MQPL_APPLIANCE {
111115
err = fmt.Errorf("Queue manager must be at least V9.0 for monitoring.")
116+
errorString = "Unsupported system"
112117
}
113118
}
114119
// Don't need the qMgrObject any more
@@ -130,6 +135,9 @@ func InitConnection(qMgrName string, replyQ string, cc *ConnectionConfig) error
130135
}
131136

132137
cmdQObj, err = qMgr.Open(mqod, openOptions)
138+
if err != nil {
139+
errorString = "Cannot open queue " + mqod.ObjectName
140+
}
133141

134142
}
135143

@@ -144,6 +152,8 @@ func InitConnection(qMgrName string, replyQ string, cc *ConnectionConfig) error
144152
replyQBaseName = replyQ
145153
if err == nil {
146154
queuesOpened = true
155+
} else {
156+
errorString = "Cannot open queue " + replyQ
147157
}
148158
}
149159

@@ -154,10 +164,13 @@ func InitConnection(qMgrName string, replyQ string, cc *ConnectionConfig) error
154164
mqod.ObjectType = ibmmq.MQOT_Q
155165
mqod.ObjectName = replyQ
156166
statusReplyQObj, err = qMgr.Open(mqod, openOptions)
167+
if err != nil {
168+
errorString = "Cannot open queue" + replyQ
169+
}
157170
}
158171

159172
if err != nil {
160-
return fmt.Errorf("Cannot access queue manager. Error: %v", err)
173+
return fmt.Errorf(errorString+". Error: %v", err)
161174
}
162175

163176
return err
@@ -221,7 +234,7 @@ func getMessageWithHObj(wait bool, hObj ibmmq.MQObject) ([]byte, error) {
221234

222235
if wait {
223236
gmo.Options |= ibmmq.MQGMO_WAIT
224-
gmo.WaitInterval = 10 * 1000
237+
gmo.WaitInterval = 30 * 1000
225238
}
226239

227240
datalen, err = hObj.Get(getmqmd, gmo, getBuffer)
@@ -277,8 +290,7 @@ func GetPlatform() int32 {
277290
}
278291

279292
/*
280-
Return the current platform - the MQPL_* definition value. It
281-
can be turned into a string if necessary via ibmmq.MQItoString("PL"...)
293+
Return the current command level
282294
*/
283295
func GetCommandLevel() int32 {
284296
return commandLevel

0 commit comments

Comments
 (0)