Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds channel metrics #3360

Merged
merged 21 commits into from
Mar 25, 2019
2 changes: 2 additions & 0 deletions ibm_mq/datadog_checks/ibm_mq/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def __init__(self, instance):
self.queues = instance.get('queues', [])
self.queue_patterns = instance.get('queue_patterns', [])

self.channels = instance.get('channels', [])

self.custom_tags = instance.get('tags', [])

self.auto_discover_queues = is_affirmative(instance.get('auto_discover_queues', False))
Expand Down
6 changes: 6 additions & 0 deletions ibm_mq/datadog_checks/ibm_mq/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ instances:
# - 'DEV.*'
# - 'SYSTEM.*'

## @param channels - list of string - optional
## Check the status of the following channels
#
# channels:
# - '<CHANNEL_NAME>'

## @param auto_discover_queues - string - optional - default: false
## Autodiscover the queues to monitor
## Warning: this will lead to some warnings in your logs
Expand Down
51 changes: 51 additions & 0 deletions ibm_mq/datadog_checks/ibm_mq/ibm_mq.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class IbmMqCheck(AgentCheck):
QUEUE_MANAGER_SERVICE_CHECK = 'ibm_mq.queue_manager'
QUEUE_SERVICE_CHECK = 'ibm_mq.queue'

CHANNEL_SERVICE_CHECK = 'ibm_mq.channel'

def check(self, instance):
config = IBMMQConfig(instance)
config.check_properly_configured()
Expand All @@ -46,6 +48,8 @@ def check(self, instance):
self.service_check(self.SERVICE_CHECK, AgentCheck.CRITICAL, config.tags)
return

self.get_pcf_channel_metrics(queue_manager, config.tags, config)

self.discover_queues(queue_manager, config)

try:
Expand Down Expand Up @@ -160,3 +164,50 @@ def get_pcf_queue_metrics(self, queue_manager, queue_name, tags):
msg = "Unable to get {}, turn on queue level monitoring to access these metrics for {}"
msg = msg.format(mname, queue_name)
log.debug(msg)

def get_pcf_channel_metrics(self, queue_manager, tags, config):
args = {
pymqi.CMQCFC.MQCACH_CHANNEL_NAME: ensure_bytes('*')
}

try:
pcf = pymqi.PCFExecute(queue_manager)
response = pcf.MQCMD_INQUIRE_CHANNEL(args)
except pymqi.MQMIError as e:
self.log.warning("Error getting CHANNEL stats {}".format(e))
else:
channels = len(response)
mname = '{}.channel.channels'.format(self.METRIC_PREFIX)
self.gauge(mname, channels, tags=tags)

# grab all the discoverable channels
self._get_channel_status(queue_manager, '*', tags, config)

# check specific channels as well
# if a channel is not listed in the above one, a user may want to check it specifically,
# in this case it'll fail
for channel in config.channels:
self._get_channel_status(queue_manager, channel, tags, config)

def _get_channel_status(queue_manager, channel, tags, config):
channel_tags = tags + ["channel:{}".format(channel)]
try:
args = {
pymqi.CMQCFC.MQCACH_CHANNEL_NAME: ensure_bytes(channel)
}
pcf = pymqi.PCFExecute(queue_manager)
response = pcf.MQCMD_INQUIRE_CHANNEL_STATUS(args)
except pymqi.MQMIError as e:
self.log.warning("Error getting CHANNEL stats {}".format(e))
self.service_check(self.SERVICE_CHECK, AgentCheck.CRITICAL, channel_tags)
else:
for channel_info in response:
name = channel_info[pymqi.CMQCFC.MQCACH_CHANNEL_NAME]
name = name.strip()

# running = 3, stopped = 4
status = channel_info[pymqi.CMQCFC.MQIACH_CHANNEL_STATUS]
if status == 3:
self.service_check(self.SERVICE_CHECK, AgentCheck.OK, channel_tags)
elif status == 4:
self.service_check(self.SERVICE_CHECK, AgentCheck.WARNING, channel_tags)
1 change: 1 addition & 0 deletions ibm_mq/tests/test_ibm_mq.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
'ibm_mq.queue.depth_percent',
'ibm_mq.queue_manager.dist_lists',
'ibm_mq.queue_manager.max_msg_list',
'ibm_mq.channel.channels',
]

OPTIONAL_METRICS = [
Expand Down