From d9ee8b08ef157601368734c2dfd7b4384d2d91fe Mon Sep 17 00:00:00 2001 From: Darshancisco Date: Thu, 18 Jul 2024 17:56:15 +0530 Subject: [PATCH 1/2] Changes to show all metrics --- .../webspheremq/WMQMonitorTask.java | 48 ++---- .../webspheremq/common/WMQUtil.java | 85 +++++++++++ .../ChannelMetricsCollector.java | 52 ++++--- .../InquireQCmdCollector.java | 12 +- .../InquireQStatusCmdCollector.java | 12 +- .../InquireTStatusCmdCollector.java | 11 +- .../ListenerMetricsCollector.java | 47 +++--- .../metricscollector/MetricsCollector.java | 133 ++++++++++++++--- .../QueueManagerMetricsCollector.java | 41 ++++-- .../QueueMetricsCollector.java | 105 +++++-------- .../ResetQStatsCmdCollector.java | 12 +- .../TopicMetricsCollector.java | 68 +++------ src/main/resources/conf/config.yml | 139 +++--------------- .../ChannelMetricsCollectorTest.java | 5 +- .../ListenerMetricsCollectorTest.java | 5 +- .../QueueManagerMetricsCollectorTest.java | 11 +- .../QueueMetricsCollectorTest.java | 9 +- .../TopicMetricsCollectorTest.java | 5 +- 18 files changed, 399 insertions(+), 401 deletions(-) diff --git a/src/main/java/com/appdynamics/extensions/webspheremq/WMQMonitorTask.java b/src/main/java/com/appdynamics/extensions/webspheremq/WMQMonitorTask.java index 9f6ec9e..b64b022 100644 --- a/src/main/java/com/appdynamics/extensions/webspheremq/WMQMonitorTask.java +++ b/src/main/java/com/appdynamics/extensions/webspheremq/WMQMonitorTask.java @@ -25,7 +25,9 @@ import com.singularity.ee.agent.systemagent.api.exception.TaskExecutionException; import org.slf4j.Logger; +import java.io.File; import java.math.BigDecimal; +import java.util.Arrays; import java.util.Hashtable; import java.util.List; import java.util.Map; @@ -129,48 +131,22 @@ private PCFMessageAgent initPCFMesageAgent(MQQueueManager ibmQueueManager) { private void extractAndReportMetrics(PCFMessageAgent agent) { Map> metricsMap = WMQUtil.getMetricsToReportFromConfigYml((List) configMap.get("mqMetrics")); - CountDownLatch countDownLatch = new CountDownLatch(metricsMap.size()); - Map qMgrMetricsToReport = metricsMap.get(Constants.METRIC_TYPE_QUEUE_MANAGER); - if (qMgrMetricsToReport != null) { - MetricsCollector qMgrMetricsCollector = new QueueManagerMetricsCollector(qMgrMetricsToReport, this.monitorContextConfig, agent, queueManager, metricWriteHelper, countDownLatch); - monitorContextConfig.getContext().getExecutorService().execute("QueueManagerMetricsCollector", qMgrMetricsCollector); - } else { - logger.warn("No queue manager metrics to report"); - } + MetricsCollector qMgrMetricsCollector = new QueueManagerMetricsCollector(this.monitorContextConfig, agent, queueManager, metricWriteHelper, countDownLatch); + monitorContextConfig.getContext().getExecutorService().execute("QueueManagerMetricsCollector", qMgrMetricsCollector); - Map channelMetricsToReport = metricsMap.get(Constants.METRIC_TYPE_CHANNEL); - if (channelMetricsToReport != null) { - MetricsCollector channelMetricsCollector = new ChannelMetricsCollector(channelMetricsToReport, this.monitorContextConfig, agent, queueManager, metricWriteHelper, countDownLatch); - monitorContextConfig.getContext().getExecutorService().execute("ChannelMetricsCollector", channelMetricsCollector); - } else { - logger.warn("No channel metrics to report"); - } + MetricsCollector channelMetricsCollector = new ChannelMetricsCollector(this.monitorContextConfig, agent, queueManager, metricWriteHelper, countDownLatch); + monitorContextConfig.getContext().getExecutorService().execute("ChannelMetricsCollector", channelMetricsCollector); - Map queueMetricsToReport = metricsMap.get(Constants.METRIC_TYPE_QUEUE); - if (queueMetricsToReport != null) { - MetricsCollector queueMetricsCollector = new QueueMetricsCollector(queueMetricsToReport, this.monitorContextConfig, agent, queueManager, metricWriteHelper, countDownLatch); - monitorContextConfig.getContext().getExecutorService().execute("QueueMetricsCollector", queueMetricsCollector); - } else { - logger.warn("No queue metrics to report"); - } + MetricsCollector queueMetricsCollector = new QueueMetricsCollector(this.monitorContextConfig, agent, queueManager, metricWriteHelper, countDownLatch); + monitorContextConfig.getContext().getExecutorService().execute("QueueMetricsCollector", queueMetricsCollector); - Map listenerMetricsToReport = metricsMap.get(Constants.METRIC_TYPE_LISTENER); - if (listenerMetricsToReport != null) { - MetricsCollector listenerMetricsCollector = new ListenerMetricsCollector(listenerMetricsToReport, this.monitorContextConfig, agent, queueManager, metricWriteHelper, countDownLatch); - monitorContextConfig.getContext().getExecutorService().execute("ListenerMetricsCollector", listenerMetricsCollector); - } else { - logger.warn("No listener metrics to report"); - } + MetricsCollector listenerMetricsCollector = new ListenerMetricsCollector(this.monitorContextConfig, agent, queueManager, metricWriteHelper, countDownLatch); + monitorContextConfig.getContext().getExecutorService().execute("ListenerMetricsCollector", listenerMetricsCollector); - Map topicMetricsToReport = metricsMap.get(Constants.METRIC_TYPE_TOPIC); - if (topicMetricsToReport != null) { - MetricsCollector topicsMetricsCollector = new TopicMetricsCollector(topicMetricsToReport, this.monitorContextConfig, agent, queueManager, metricWriteHelper, countDownLatch); - monitorContextConfig.getContext().getExecutorService().execute("TopicMetricsCollector", topicsMetricsCollector); - } else { - logger.warn("No topic metrics to report"); - } + MetricsCollector topicsMetricsCollector = new TopicMetricsCollector(this.monitorContextConfig, agent, queueManager, metricWriteHelper, countDownLatch); + monitorContextConfig.getContext().getExecutorService().execute("TopicMetricsCollector", topicsMetricsCollector); try { countDownLatch.await(); diff --git a/src/main/java/com/appdynamics/extensions/webspheremq/common/WMQUtil.java b/src/main/java/com/appdynamics/extensions/webspheremq/common/WMQUtil.java index 269c080..51c6d91 100644 --- a/src/main/java/com/appdynamics/extensions/webspheremq/common/WMQUtil.java +++ b/src/main/java/com/appdynamics/extensions/webspheremq/common/WMQUtil.java @@ -8,17 +8,36 @@ package com.appdynamics.extensions.webspheremq.common; import com.appdynamics.extensions.logging.ExtensionsLoggerFactory; +import com.appdynamics.extensions.metrics.Metric; import com.appdynamics.extensions.webspheremq.config.QueueManager; import com.appdynamics.extensions.webspheremq.config.WMQMetricOverride; +import com.appdynamics.extensions.webspheremq.metricscollector.MetricsCollector; import com.google.common.base.Strings; +import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import com.ibm.mq.pcf.MQCFIL; +import com.ibm.mq.pcf.MQCFIN; +import com.ibm.mq.pcf.MQCFST; +import com.ibm.mq.pcf.PCFParameter; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; +import java.text.ParseException; +import java.time.LocalDate; +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; import java.util.List; import java.util.Map; +import java.util.regex.Pattern; public class WMQUtil { public static final Logger logger = ExtensionsLoggerFactory.getLogger(WMQUtil.class); + + private static Pattern METRIC_DATE_PATTERN = Pattern.compile("^\\d{4}-\\d{2}-\\d{2}$"); + + private static Pattern METRIC_TIME_PATTERN = Pattern.compile("^\\d{2}\\.\\d{2}\\.\\d{2}$"); + /** * Returns master data structure,This map will contain only those metrics which are to be reported to controller.
* It contains metric type as key and a map of metric and WMQMetricOverride as value,
@@ -38,6 +57,36 @@ public static Map> getMetricsToReportFrom return metricsMap; } + /** + * Returns master data structure,This map will contain only those metrics which are to be excluded.
+ * It contains metric type as key and a list of metric keys to be excluded. + */ + public static List getMetricsToExcludeFromConfigYml(List mqMetrics, String metricType) { + List excludeMetrics = null; + for (Map mqMetric : mqMetrics) { + if (StringUtils.equalsIgnoreCase(metricType, (String) mqMetric.get("metricsType"))) { + excludeMetrics = (List) ((Map) mqMetric.get("metrics")).get("exclude"); + break; + } + } + return excludeMetrics; + } + + public static boolean isMetricExcluded(String metricKey, List excludedMetrics) { + boolean excluded = false; + metricKey = metricKey.trim(); + if (excludedMetrics == null || excludedMetrics.isEmpty()) { + return false; + } + for (String excludedMetric : excludedMetrics) { + if (StringUtils.equalsIgnoreCase(metricKey, excludedMetric)) { + excluded = true; + break; + } + } + return excluded; + } + private static Map gatherMetricNamesByApplyingIncludeFilter(List includeMetrics) { Map overrideMap = Maps.newHashMap(); for (Object inc : includeMetrics) { @@ -69,4 +118,40 @@ public static String getQueueManagerNameFromConfig(QueueManager queueManager) { return queueManager.getName(); } } + + /** + * converts input date value to integer value representing the number of days lapsed from current date + * expects the DATE format as following:'yyyy-MM-dd' + * @param metricValue + * @return + * @throws ParseException + */ + public static int getDateDifferenceInDays(String metricValue) throws ParseException { + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + LocalDate currentDate = LocalDate.now(); + LocalDate inputDate = LocalDate.parse(metricValue.trim(), dtf); + return (int) ChronoUnit.DAYS.between(inputDate, currentDate); + } + + /** + * converts input time value to integer value representing the number of hours lapsed from current time + * expects the Time format as following:'hh.mm.ss' + * @param metricValue + * @return + * @throws ParseException + */ + public static int getTimeDifferenceInHours(String metricValue) throws ParseException { + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("HH.mm.ss"); + LocalTime dayStartTime = LocalTime.of(0,0,0); + LocalTime inputTime = LocalTime.parse(metricValue.trim(), dtf); + return (int) ChronoUnit.SECONDS.between(dayStartTime, inputTime); + } + + public static boolean isDateValue(String value) { + return METRIC_DATE_PATTERN.matcher(value).matches(); + } + + public static boolean isTimeValue(String value) { + return METRIC_TIME_PATTERN.matcher(value).matches(); + } } diff --git a/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/ChannelMetricsCollector.java b/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/ChannelMetricsCollector.java index 7d93f15..0ad66fe 100644 --- a/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/ChannelMetricsCollector.java +++ b/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/ChannelMetricsCollector.java @@ -11,6 +11,7 @@ import com.appdynamics.extensions.conf.MonitorContextConfiguration; import com.appdynamics.extensions.logging.ExtensionsLoggerFactory; import com.appdynamics.extensions.metrics.Metric; +import com.appdynamics.extensions.webspheremq.common.Constants; import com.appdynamics.extensions.webspheremq.common.WMQUtil; import com.appdynamics.extensions.webspheremq.config.ExcludeFilters; import com.appdynamics.extensions.webspheremq.config.QueueManager; @@ -22,6 +23,7 @@ import com.ibm.mq.pcf.PCFException; import com.ibm.mq.pcf.PCFMessage; import com.ibm.mq.pcf.PCFMessageAgent; +import com.ibm.mq.pcf.PCFParameter; import com.singularity.ee.agent.systemagent.api.exception.TaskExecutionException; import org.slf4j.Logger; @@ -44,8 +46,7 @@ public class ChannelMetricsCollector extends MetricsCollector implements Runnabl * The Channel Status values are mentioned here http://www.ibm.com/support/knowledgecenter/SSFKSJ_7.5.0/com.ibm.mq.ref.dev.doc/q090880_.htm */ - public ChannelMetricsCollector(Map metricsToReport, MonitorContextConfiguration monitorContextConfig, PCFMessageAgent agent, QueueManager queueManager, MetricWriteHelper metricWriteHelper, CountDownLatch countDownLatch) { - this.metricsToReport = metricsToReport; + public ChannelMetricsCollector(MonitorContextConfiguration monitorContextConfig, PCFMessageAgent agent, QueueManager queueManager, MetricWriteHelper metricWriteHelper, CountDownLatch countDownLatch) { this.monitorContextConfig = monitorContextConfig; this.agent = agent; this.metricWriteHelper = metricWriteHelper; @@ -67,12 +68,7 @@ public void run() { protected void publishMetrics() throws TaskExecutionException { long entryTime = System.currentTimeMillis(); - if (getMetricsToReport() == null || getMetricsToReport().isEmpty()) { - logger.debug("Channel metrics to report from the config is null or empty, nothing to publish"); - return; - } - - int[] attrs = getIntAttributesArray(CMQCFC.MQCACH_CHANNEL_NAME, CMQCFC.MQCACH_CONNECTION_NAME); + int[] attrs = new int[] { CMQCFC.MQIACF_ALL }; logger.debug("Attributes being sent along PCF agent request to query channel metrics: " + Arrays.toString(attrs)); Set channelGenericNames = this.queueManager.getChannelFilters().getInclude(); @@ -98,19 +94,35 @@ protected void publishMetrics() throws TaskExecutionException { Set excludeFilters = this.queueManager.getChannelFilters().getExclude(); if(!isExcluded(channelName,excludeFilters)) { //check for exclude filters logger.debug("Pulling out metrics for channel name {}",channelName); - Iterator itr = getMetricsToReport().keySet().iterator(); + Enumeration pcfParameters = response[i].getParameters(); List metrics = Lists.newArrayList(); - while (itr.hasNext()) { - String metrickey = itr.next(); - WMQMetricOverride wmqOverride = getMetricsToReport().get(metrickey); - int metricVal = response[i].getIntParameterValue(wmqOverride.getConstantValue()); - Metric metric = createMetric(queueManager, metrickey, metricVal, wmqOverride, getAtrifact(), channelName, metrickey); - metrics.add(metric); - if ("Status".equals(metrickey)) { - if (metricVal == 3) { - activeChannels.add(channelName); + List mqMetrics = (List) this.monitorContextConfig.getConfigYml().get("mqMetrics"); + List excludedMetrics = WMQUtil.getMetricsToExcludeFromConfigYml(mqMetrics, Constants.METRIC_TYPE_CHANNEL); + while (pcfParameters.hasMoreElements()) { + PCFParameter pcfParam = pcfParameters.nextElement(); + String metrickey = pcfParam.getParameterName(); + if (!WMQUtil.isMetricExcluded(metrickey, excludedMetrics)) { + try { + if (pcfParam != null) { + // create metric objects from PCF parameter + metrics.addAll(createMetrics(queueManager, channelName, pcfParam)); + + if ("MQIACH_CHANNEL_STATUS".equals(metrickey)) { + Metric metric = getMetricByKey("MQIACH_CHANNEL_STATUS", metrics); + if (metric.getMetricValue() != null && Integer.parseInt(metric.getMetricValue()) == 3) { + activeChannels.add(channelName); + } + } + } else { + logger.warn("PCF parameter is null in response for Channel: {} for metric: {}", channelName, metrickey); + } + } catch (Exception pcfe) { + logger.error("Exception caught while collecting metric for Channel: {} for metric: {}", channelName, metrickey, pcfe); } } + else { + logger.debug("Channel metric key {} is excluded.",metrickey); + } } publishMetrics(metrics); } @@ -146,8 +158,4 @@ protected void publishMetrics() throws TaskExecutionException { public String getAtrifact() { return artifact; } - - public Map getMetricsToReport() { - return this.metricsToReport; - } } \ No newline at end of file diff --git a/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/InquireQCmdCollector.java b/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/InquireQCmdCollector.java index 01146fb..9bf37d2 100644 --- a/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/InquireQCmdCollector.java +++ b/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/InquireQCmdCollector.java @@ -17,6 +17,7 @@ import org.slf4j.Logger; import java.util.Arrays; +import java.util.List; import java.util.Map; import java.util.Set; @@ -26,8 +27,8 @@ class InquireQCmdCollector extends QueueMetricsCollector implements Runnable { protected static final String COMMAND = "MQCMD_INQUIRE_Q"; - public InquireQCmdCollector(QueueMetricsCollector collector, Map metricsToReport){ - super(metricsToReport,collector.monitorContextConfig,collector.agent,collector.queueManager, collector.metricWriteHelper, collector.countDownLatch); + public InquireQCmdCollector(QueueMetricsCollector collector){ + super(collector.monitorContextConfig,collector.agent,collector.queueManager, collector.metricWriteHelper, collector.countDownLatch); } public void run() { @@ -45,12 +46,7 @@ protected void publishMetrics() throws TaskExecutionException { */ long entryTime = System.currentTimeMillis(); - if (getMetricsToReport() == null || getMetricsToReport().isEmpty()) { - logger.debug("Queue metrics to report from the config is null or empty, nothing to publish"); - return; - } - - int[] attrs = getIntAttributesArray(CMQC.MQCA_Q_NAME); + int[] attrs = new int[] { CMQCFC.MQIACF_ALL }; logger.debug("Attributes being sent along PCF agent request to query queue metrics: {} for command {}",Arrays.toString(attrs),COMMAND); Set queueGenericNames = this.queueManager.getQueueFilters().getInclude(); diff --git a/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/InquireQStatusCmdCollector.java b/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/InquireQStatusCmdCollector.java index eea1823..f535e01 100644 --- a/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/InquireQStatusCmdCollector.java +++ b/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/InquireQStatusCmdCollector.java @@ -17,6 +17,7 @@ import org.slf4j.Logger; import java.util.Arrays; +import java.util.List; import java.util.Map; import java.util.Set; @@ -26,8 +27,8 @@ class InquireQStatusCmdCollector extends QueueMetricsCollector implements Runnab protected static final String COMMAND = "MQCMD_INQUIRE_Q_STATUS"; - public InquireQStatusCmdCollector(QueueMetricsCollector collector, Map metricsToReport){ - super(metricsToReport,collector.monitorContextConfig,collector.agent,collector.queueManager,collector.metricWriteHelper, collector.countDownLatch); + public InquireQStatusCmdCollector(QueueMetricsCollector collector){ + super(collector.monitorContextConfig,collector.agent,collector.queueManager,collector.metricWriteHelper, collector.countDownLatch); } public void run() { @@ -45,12 +46,7 @@ protected void publishMetrics() throws TaskExecutionException { */ long entryTime = System.currentTimeMillis(); - if (getMetricsToReport() == null || getMetricsToReport().isEmpty()) { - logger.debug("Queue metrics to report from the config is null or empty, nothing to publish for command {}",COMMAND); - return; - } - - int[] attrs = getIntAttributesArray(CMQC.MQCA_Q_NAME); + int[] attrs = new int[] { CMQCFC.MQIACF_ALL }; logger.debug("Attributes being sent along PCF agent request to query queue metrics: {} for command {}",Arrays.toString(attrs),COMMAND); Set queueGenericNames = this.queueManager.getQueueFilters().getInclude(); diff --git a/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/InquireTStatusCmdCollector.java b/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/InquireTStatusCmdCollector.java index 878e113..c995433 100644 --- a/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/InquireTStatusCmdCollector.java +++ b/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/InquireTStatusCmdCollector.java @@ -16,6 +16,7 @@ import com.singularity.ee.agent.systemagent.api.exception.TaskExecutionException; import org.slf4j.Logger; +import java.util.List; import java.util.Map; import java.util.Set; @@ -25,8 +26,8 @@ class InquireTStatusCmdCollector extends TopicMetricsCollector implements Runnab protected static final String COMMAND = "MQCMD_INQUIRE_TOPIC_STATUS"; - public InquireTStatusCmdCollector(TopicMetricsCollector collector, Map metricsToReport){ - super(metricsToReport,collector.monitorContextConfig,collector.agent,collector.queueManager,collector.metricWriteHelper, collector.countDownLatch); + public InquireTStatusCmdCollector(TopicMetricsCollector collector){ + super(collector.monitorContextConfig,collector.agent,collector.queueManager,collector.metricWriteHelper, collector.countDownLatch); } public void run() { @@ -41,10 +42,6 @@ public void run() { protected void publishMetrics() throws TaskExecutionException { long entryTime = System.currentTimeMillis(); - if (getMetricsToReport() == null || getMetricsToReport().isEmpty()) { - logger.debug("Topic metrics to report from the config is null or empty, nothing to publish for command {}",COMMAND); - return; - } Set topicGenericNames = this.queueManager.getTopicFilters().getInclude(); for(String topicGenericName : topicGenericNames){ // Request: https://www.ibm.com/support/knowledgecenter/SSFKSJ_8.0.0/com.ibm.mq.ref.adm.doc/q088140_.htm @@ -55,7 +52,7 @@ protected void publishMetrics() throws TaskExecutionException { try { processPCFRequestAndPublishQMetrics(topicGenericName, request,COMMAND); } catch (PCFException pcfe) { - logger.error("PCFException caught while collecting metric for Queue: {} for command {}",topicGenericName,COMMAND, pcfe); + logger.error("PCFException caught while collecting metric for Topic: {} for command {}",topicGenericName,COMMAND, pcfe); PCFMessage[] msgs = (PCFMessage[]) pcfe.exceptionSource; for (int i = 0; i < msgs.length; i++) { logger.error(msgs[i].toString()); diff --git a/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/ListenerMetricsCollector.java b/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/ListenerMetricsCollector.java index cc19f18..137fe12 100644 --- a/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/ListenerMetricsCollector.java +++ b/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/ListenerMetricsCollector.java @@ -11,6 +11,8 @@ import com.appdynamics.extensions.conf.MonitorContextConfiguration; import com.appdynamics.extensions.logging.ExtensionsLoggerFactory; import com.appdynamics.extensions.metrics.Metric; +import com.appdynamics.extensions.webspheremq.common.Constants; +import com.appdynamics.extensions.webspheremq.common.WMQUtil; import com.appdynamics.extensions.webspheremq.config.ExcludeFilters; import com.appdynamics.extensions.webspheremq.config.QueueManager; import com.appdynamics.extensions.webspheremq.config.WMQMetricOverride; @@ -18,6 +20,7 @@ import com.ibm.mq.constants.CMQCFC; import com.ibm.mq.pcf.PCFMessage; import com.ibm.mq.pcf.PCFMessageAgent; +import com.ibm.mq.pcf.PCFParameter; import com.singularity.ee.agent.systemagent.api.exception.TaskExecutionException; import org.slf4j.Logger; @@ -30,8 +33,7 @@ public class ListenerMetricsCollector extends MetricsCollector implements Runnab public static final Logger logger = ExtensionsLoggerFactory.getLogger(ListenerMetricsCollector.class); private final String artifact = "Listeners"; - public ListenerMetricsCollector(Map metricsToReport, MonitorContextConfiguration monitorContextConfig, PCFMessageAgent agent, QueueManager queueManager, MetricWriteHelper metricWriteHelper, CountDownLatch countDownLatch) { - this.metricsToReport = metricsToReport; + public ListenerMetricsCollector(MonitorContextConfiguration monitorContextConfig, PCFMessageAgent agent, QueueManager queueManager, MetricWriteHelper metricWriteHelper, CountDownLatch countDownLatch) { this.monitorContextConfig = monitorContextConfig; this.agent = agent; this.metricWriteHelper = metricWriteHelper; @@ -52,12 +54,7 @@ public void run() { protected void publishMetrics() throws TaskExecutionException { long entryTime = System.currentTimeMillis(); - if (getMetricsToReport() == null || getMetricsToReport().isEmpty()) { - logger.debug("Listener metrics to report from the config is null or empty, nothing to publish"); - return; - } - - int[] attrs = getIntAttributesArray(CMQCFC.MQCACH_LISTENER_NAME); + int[] attrs = new int[] { CMQCFC.MQIACF_ALL }; logger.debug("Attributes being sent along PCF agent request to query channel metrics: " + Arrays.toString(attrs)); Set listenerGenericNames = this.queueManager.getListenerFilters().getInclude(); @@ -80,14 +77,28 @@ protected void publishMetrics() throws TaskExecutionException { Set excludeFilters = this.queueManager.getListenerFilters().getExclude(); if(!isExcluded(listenerName,excludeFilters)) { //check for exclude filters logger.debug("Pulling out metrics for listener name {}",listenerName); - Iterator itr = getMetricsToReport().keySet().iterator(); + Enumeration pcfParameters = response[i].getParameters(); List metrics = Lists.newArrayList(); - while (itr.hasNext()) { - String metrickey = itr.next(); - WMQMetricOverride wmqOverride = getMetricsToReport().get(metrickey); - int metricVal = response[i].getIntParameterValue(wmqOverride.getConstantValue()); - Metric metric = createMetric(queueManager, metrickey, metricVal, wmqOverride, getAtrifact(), listenerName, metrickey); - metrics.add(metric); + List mqMetrics = (List) this.monitorContextConfig.getConfigYml().get("mqMetrics"); + List excludedMetrics = WMQUtil.getMetricsToExcludeFromConfigYml(mqMetrics, Constants.METRIC_TYPE_LISTENER); + while (pcfParameters.hasMoreElements()) { + PCFParameter pcfParam = pcfParameters.nextElement(); + String metrickey = pcfParam.getParameterName(); + if (!WMQUtil.isMetricExcluded(metrickey, excludedMetrics)) { + try { + if (pcfParam != null) { + // create metric objects from PCF parameter + metrics.addAll(createMetrics(queueManager, listenerName, pcfParam)); + } else { + logger.warn("PCF parameter is null in response for Listener: {} for metric: {}", listenerName, metrickey); + } + } catch (Exception pcfe) { + logger.error("Exception caught while collecting metric for Listener: {} for metric: {}", listenerName, metrickey, pcfe); + } + } + else { + logger.debug("Listener metric key {} is excluded.",metrickey); + } } publishMetrics(metrics); } @@ -97,7 +108,7 @@ protected void publishMetrics() throws TaskExecutionException { } } catch (Exception e) { - logger.error("Unexpected Error occoured while collecting metrics for listener " + listenerGenericName, e); + logger.error("Unexpected Error occurred while collecting metrics for listener " + listenerGenericName, e); } } long exitTime = System.currentTimeMillis() - entryTime; @@ -108,8 +119,4 @@ protected void publishMetrics() throws TaskExecutionException { public String getAtrifact() { return artifact; } - - public Map getMetricsToReport() { - return this.metricsToReport; - } } diff --git a/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/MetricsCollector.java b/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/MetricsCollector.java index 7fd840e..bbc3a46 100644 --- a/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/MetricsCollector.java +++ b/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/MetricsCollector.java @@ -16,10 +16,14 @@ import com.appdynamics.extensions.webspheremq.config.QueueManager; import com.appdynamics.extensions.webspheremq.config.WMQMetricOverride; import com.google.common.base.Strings; -import com.ibm.mq.pcf.PCFMessageAgent; +import com.google.common.collect.Lists; +import com.ibm.mq.pcf.*; import com.singularity.ee.agent.systemagent.api.exception.TaskExecutionException; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; +import java.text.ParseException; +import java.time.format.DateTimeParseException; import java.util.*; import java.util.concurrent.CountDownLatch; @@ -33,7 +37,6 @@ */ public abstract class MetricsCollector implements Runnable { - protected Map metricsToReport; protected MonitorContextConfiguration monitorContextConfig; protected PCFMessageAgent agent; protected MetricWriteHelper metricWriteHelper; @@ -46,8 +49,6 @@ public abstract class MetricsCollector implements Runnable { public abstract String getAtrifact(); - public abstract Map getMetricsToReport(); - /** * Applies include and exclude filters to the artifacts (i.e queue manager, q, or channel),
* extracts and publishes the metrics to controller @@ -80,6 +81,113 @@ protected Metric createMetric(QueueManager queueManager, String metricName, int return metric; } + protected Metric createMetric(QueueManager queueManager, String metricName, String metricValue, WMQMetricOverride wmqOverride, String... pathelements) { + String metricPath = getMetricsName(WMQUtil.getQueueManagerNameFromConfig(queueManager), pathelements); + Metric metric; + if (wmqOverride != null && wmqOverride.getMetricProperties() != null) { + metric = new Metric(metricName, String.valueOf(metricValue), metricPath, wmqOverride.getMetricProperties()); + } else { + metric = new Metric(metricName, String.valueOf(metricValue), metricPath); + } + return metric; + } + + protected List createMetrics(QueueManager queueManager, String mqObjectName, PCFParameter pcfParam) { + List metrics = Lists.newArrayList(); + + String metrickey = pcfParam.getParameterName(); + String metricValueString = pcfParam.getStringValue(); + + // ignore the metric if the metric value is NULL + if (metricValueString == null) { + return metrics; + } else { + metricValueString = metricValueString.trim(); + } + + if(pcfParam instanceof MQCFIN || pcfParam instanceof MQCFST){ + int metricVal = 0; + + // if value type is 'String i.e. MQCFST', process only if the String value represents DATE or TIME + // ignore the metric if the value is not valid DATE or TIME value + if (pcfParam instanceof MQCFST) { + try { + if (WMQUtil.isDateValue(metricValueString)) { + metricVal = WMQUtil.getDateDifferenceInDays(metricValueString); + } else if (WMQUtil.isTimeValue(metricValueString)) { + metricVal = WMQUtil.getTimeDifferenceInHours(metricValueString); + } else { + logger.info("Found string metric value:{}, ignoring the metric {} for {}: {}",metricValueString, metrickey, getAtrifact(), mqObjectName != null ? mqObjectName:queueManager.getName()); + return metrics; + } + } + catch (Exception parseException) { + logger.error("Exception parsing the date or time metric value:{} for metric {} for {}: {}",metricValueString, metrickey, getAtrifact(), mqObjectName != null ? mqObjectName:queueManager.getName()); + return metrics; + } + } else { + // ignore the metric if the metric value is negative + metricVal = ((MQCFIN) pcfParam).getIntValue(); + if (metricVal < 0) { + logger.info("Found negative metric value:{}, ignoring the metric {} for {}: {}",metricValueString, metrickey, getAtrifact(), mqObjectName != null ? mqObjectName:queueManager.getName()); + return metrics; + } + } + if (logger.isDebugEnabled()) { + logger.debug("Metric: " + metrickey + "=" + metricVal); + } + // 'mqObjectName' would be null if the metric is related to 'Queue Manager' + Metric metric = null; + if (mqObjectName != null) { + // used for all MQ objects metrics other than 'QueueManager' + metric = createMetric(queueManager, metrickey, metricVal, null, getAtrifact(), mqObjectName, metrickey); + } else { + // used for 'QueuMmanager' metrics + metric = createMetric(queueManager, metrickey, metricVal, null, metrickey); + } + metrics.add(metric); + } + else if(pcfParam instanceof MQCFIL){ + int[] metricVals = ((MQCFIL) pcfParam).getValues(); + if(metricVals != null){ + int count=0; + for(int val : metricVals){ + if (val < 0) { + logger.info("Found negative metric value:{}, ignoring the metric {} for {}: {}", val, metrickey, getAtrifact(), mqObjectName != null ? mqObjectName : queueManager.getName()); + continue; + } + count++; + String metricKey = metrickey+ "_" + Integer.toString(count); + String metricVal = String.valueOf(val); + if (logger.isDebugEnabled()) { + logger.debug("Metric: " + metrickey + "=" + metricVal); + } + Metric metric = createMetric(queueManager, metricKey, metricVal, null, getAtrifact(), mqObjectName, metricKey); + metrics.add(metric); + } + } + } + + return metrics; + } + + protected Metric getMetricByKey(String metricKey, List metrics) { + Metric foundMetric = null; + + if (metrics == null || metrics.isEmpty()) { + return foundMetric; + } + + for (Metric metric : metrics) { + if (StringUtils.equalsIgnoreCase(metricKey, metric.getMetricName())) { + foundMetric = metric; + break; + } + } + + return foundMetric; + } + protected void publishMetrics(List metrics) { metricWriteHelper.transformAndPrintMetrics(metrics); } @@ -234,21 +342,4 @@ public List evalIncludeFilter(String type, List artifactList, Se return filteredList; } - - protected int[] getIntAttributesArray(int... inputAttrs) { - int[] attrs = new int[inputAttrs.length+getMetricsToReport().size()]; - // fill input attrs - for(int i=0 ; i< inputAttrs.length; i++){ - attrs[i]=inputAttrs[i]; - } - //fill attrs from metrics to report. - Iterator overrideItr = getMetricsToReport().keySet().iterator(); - for (int count = inputAttrs.length; overrideItr.hasNext() && count < attrs.length; count++) { - String metrickey = overrideItr.next(); - WMQMetricOverride wmqOverride = (WMQMetricOverride) getMetricsToReport().get(metrickey); - attrs[count] = wmqOverride.getConstantValue(); - } - return attrs; - - } } diff --git a/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/QueueManagerMetricsCollector.java b/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/QueueManagerMetricsCollector.java index 682722a..d67784b 100644 --- a/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/QueueManagerMetricsCollector.java +++ b/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/QueueManagerMetricsCollector.java @@ -11,15 +11,19 @@ import com.appdynamics.extensions.conf.MonitorContextConfiguration; import com.appdynamics.extensions.logging.ExtensionsLoggerFactory; import com.appdynamics.extensions.metrics.Metric; +import com.appdynamics.extensions.webspheremq.common.Constants; +import com.appdynamics.extensions.webspheremq.common.WMQUtil; import com.appdynamics.extensions.webspheremq.config.QueueManager; import com.appdynamics.extensions.webspheremq.config.WMQMetricOverride; import com.google.common.collect.Lists; import com.ibm.mq.constants.CMQCFC; import com.ibm.mq.pcf.PCFMessage; import com.ibm.mq.pcf.PCFMessageAgent; +import com.ibm.mq.pcf.PCFParameter; import com.singularity.ee.agent.systemagent.api.exception.TaskExecutionException; import org.slf4j.Logger; +import java.util.Enumeration; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -37,8 +41,7 @@ public class QueueManagerMetricsCollector extends MetricsCollector implements Ru public static final Logger logger = ExtensionsLoggerFactory.getLogger(QueueManagerMetricsCollector.class); private final String artifact = "Queue Manager"; - public QueueManagerMetricsCollector(Map metricsToReport, MonitorContextConfiguration monitorContextConfig, PCFMessageAgent agent, QueueManager queueManager, MetricWriteHelper metricWriteHelper, CountDownLatch countDownLatch) { - this.metricsToReport = metricsToReport; + public QueueManagerMetricsCollector(MonitorContextConfiguration monitorContextConfig, PCFMessageAgent agent, QueueManager queueManager, MetricWriteHelper metricWriteHelper, CountDownLatch countDownLatch) { this.monitorContextConfig = monitorContextConfig; this.agent = agent; this.metricWriteHelper = metricWriteHelper; @@ -80,17 +83,29 @@ public void publishMetrics() throws TaskExecutionException { logger.debug("Unexpected Error while PCFMessage.send(), response is either null or empty"); return; } - Iterator overrideItr = getMetricsToReport().keySet().iterator(); + + Enumeration pcfParameters = responses[0].getParameters(); List metrics = Lists.newArrayList(); - while (overrideItr.hasNext()) { - String metrickey = overrideItr.next(); - WMQMetricOverride wmqOverride = getMetricsToReport().get(metrickey); - int metricVal = responses[0].getIntParameterValue(wmqOverride.getConstantValue()); - if (logger.isDebugEnabled()) { - logger.debug("Metric: " + metrickey + "=" + metricVal); + List mqMetrics = (List) this.monitorContextConfig.getConfigYml().get("mqMetrics"); + List excludedMetrics = WMQUtil.getMetricsToExcludeFromConfigYml(mqMetrics, Constants.METRIC_TYPE_QUEUE_MANAGER); + while (pcfParameters.hasMoreElements()) { + PCFParameter pcfParam = pcfParameters.nextElement(); + String metrickey = pcfParam.getParameterName(); + if (!WMQUtil.isMetricExcluded(metrickey, excludedMetrics)) { + try { + if (pcfParam != null) { + // create metric objects from PCF parameter + metrics.addAll(createMetrics(queueManager, null, pcfParam)); + } else { + logger.warn("PCF parameter is null in response for Queue Manager: {} for metric: {}", agent.getQManagerName(), metrickey); + } + } catch (Exception pcfe) { + logger.error("Exception caught while collecting metric for Queue Manager: {} for metric: {}", agent.getQManagerName(), metrickey, pcfe); + } + } + else { + logger.debug("Queue Manager metric key {} is excluded.",metrickey); } - Metric metric = createMetric(queueManager, metrickey, metricVal, wmqOverride, metrickey); - metrics.add(metric); } publishMetrics(metrics); } catch (Exception e) { @@ -101,8 +116,4 @@ public void publishMetrics() throws TaskExecutionException { logger.debug("Time taken to publish metrics for queuemanager is {} milliseconds", exitTime); } } - - public Map getMetricsToReport() { - return metricsToReport; - } } diff --git a/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/QueueMetricsCollector.java b/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/QueueMetricsCollector.java index 4bf264e..c604bf9 100644 --- a/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/QueueMetricsCollector.java +++ b/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/QueueMetricsCollector.java @@ -11,6 +11,8 @@ import com.appdynamics.extensions.conf.MonitorContextConfiguration; import com.appdynamics.extensions.logging.ExtensionsLoggerFactory; import com.appdynamics.extensions.metrics.Metric; +import com.appdynamics.extensions.webspheremq.common.Constants; +import com.appdynamics.extensions.webspheremq.common.WMQUtil; import com.appdynamics.extensions.webspheremq.config.ExcludeFilters; import com.appdynamics.extensions.webspheremq.config.QueueManager; import com.appdynamics.extensions.webspheremq.config.WMQMetricOverride; @@ -23,10 +25,8 @@ import org.slf4j.Logger; import java.io.IOException; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.text.ParseException; +import java.util.*; import java.util.concurrent.*; public class QueueMetricsCollector extends MetricsCollector implements Runnable { @@ -34,8 +34,7 @@ public class QueueMetricsCollector extends MetricsCollector implements Runnable public static final Logger logger = ExtensionsLoggerFactory.getLogger(QueueMetricsCollector.class); private final String artifact = "Queues"; - public QueueMetricsCollector(Map metricsToReport, MonitorContextConfiguration monitorContextConfig, PCFMessageAgent agent, QueueManager queueManager, MetricWriteHelper metricWriteHelper, CountDownLatch countDownLatch) { - this.metricsToReport = metricsToReport; + public QueueMetricsCollector(MonitorContextConfiguration monitorContextConfig, PCFMessageAgent agent, QueueManager queueManager, MetricWriteHelper metricWriteHelper, CountDownLatch countDownLatch) { this.monitorContextConfig = monitorContextConfig; this.agent = agent; this.metricWriteHelper = metricWriteHelper; @@ -57,18 +56,9 @@ public void run() { protected void publishMetrics() throws TaskExecutionException { logger.info("Collecting queue metrics..."); List futures = Lists.newArrayList(); - Map metricsForInquireQCmd = getMetricsToReport(InquireQCmdCollector.COMMAND); - if(!metricsForInquireQCmd.isEmpty()){ - futures.add(monitorContextConfig.getContext().getExecutorService().submit("InquireQCmdCollector", new InquireQCmdCollector(this,metricsForInquireQCmd))); - } - Map metricsForInquireQStatusCmd = getMetricsToReport(InquireQStatusCmdCollector.COMMAND); - if(!metricsForInquireQStatusCmd.isEmpty()){ - futures.add(monitorContextConfig.getContext().getExecutorService().submit("InquireQStatusCmdCollector", new InquireQStatusCmdCollector(this,metricsForInquireQStatusCmd))); - } - Map metricsForResetQStatsCmd = getMetricsToReport(ResetQStatsCmdCollector.COMMAND); - if(!metricsForResetQStatsCmd.isEmpty()){ - futures.add(monitorContextConfig.getContext().getExecutorService().submit("ResetQStatsCmdCollector", new ResetQStatsCmdCollector(this,metricsForResetQStatsCmd))); - } + futures.add(monitorContextConfig.getContext().getExecutorService().submit("InquireQCmdCollector", new InquireQCmdCollector(this))); + futures.add(monitorContextConfig.getContext().getExecutorService().submit("InquireQStatusCmdCollector", new InquireQStatusCmdCollector(this))); + futures.add(monitorContextConfig.getContext().getExecutorService().submit("ResetQStatsCmdCollector", new ResetQStatsCmdCollector(this))); for(Future f: futures){ try { long timeout = 20; @@ -86,33 +76,11 @@ protected void publishMetrics() throws TaskExecutionException { } } - private Map getMetricsToReport(String command) { - Map commandMetrics = Maps.newHashMap(); - if (getMetricsToReport() == null || getMetricsToReport().isEmpty()) { - logger.debug("There are no metrics configured for {}",command); - return commandMetrics; - } - Iterator itr = getMetricsToReport().keySet().iterator(); - while (itr.hasNext()) { - String metrickey = itr.next(); - WMQMetricOverride wmqOverride = getMetricsToReport().get(metrickey); - if(wmqOverride.getIbmCommand().equalsIgnoreCase(command)){ - commandMetrics.put(metrickey,wmqOverride); - } - } - return commandMetrics; - } - @Override public String getAtrifact() { return artifact; } - @Override - public Map getMetricsToReport() { - return this.metricsToReport; - } - protected void processPCFRequestAndPublishQMetrics(String queueGenericName, PCFMessage request, String command) throws MQException, IOException { PCFMessage[] response; logger.debug("sending PCF agent request to query metrics for generic queue {} for command {}",queueGenericName,command); @@ -129,39 +97,44 @@ protected void processPCFRequestAndPublishQMetrics(String queueGenericName, PCFM Set excludeFilters = this.queueManager.getQueueFilters().getExclude(); if(!isExcluded(queueName,excludeFilters)) { //check for exclude filters logger.debug("Pulling out metrics for queue name {} for command {}",queueName,command); - Iterator itr = getMetricsToReport().keySet().iterator(); + Enumeration pcfParameters = response[i].getParameters(); List metrics = Lists.newArrayList(); - while (itr.hasNext()) { - String metrickey = itr.next(); - WMQMetricOverride wmqOverride = getMetricsToReport().get(metrickey); - try{ - PCFParameter pcfParam = response[i].getParameter(wmqOverride.getConstantValue()); - if (pcfParam != null) { - if(pcfParam instanceof MQCFIN){ - int metricVal = response[i].getIntParameterValue(wmqOverride.getConstantValue()); - Metric metric = createMetric(queueManager, metrickey, metricVal, wmqOverride, getAtrifact(), queueName, metrickey); - metrics.add(metric); - } - else if(pcfParam instanceof MQCFIL){ - int[] metricVals = response[i].getIntListParameterValue(wmqOverride.getConstantValue()); - if(metricVals != null){ - int count=0; - for(int val : metricVals){ - count++; - Metric metric = createMetric(queueManager, metrickey+ "_" + Integer.toString(count), val, wmqOverride, getAtrifact(), queueName, metrickey+ "_" + Integer.toString(count)); - metrics.add(metric); - } + List mqMetrics = (List) this.monitorContextConfig.getConfigYml().get("mqMetrics"); + List excludedMetrics = WMQUtil.getMetricsToExcludeFromConfigYml(mqMetrics, Constants.METRIC_TYPE_QUEUE); + List allFoundMetrics = new ArrayList<>(); + while (pcfParameters.hasMoreElements()) { + PCFParameter pcfParam = pcfParameters.nextElement(); + String metrickey = pcfParam.getParameterName(); + allFoundMetrics.add(metrickey); + if (!WMQUtil.isMetricExcluded(metrickey, excludedMetrics)) { + try { + if (pcfParam != null) { + // create metric objects from PCF parameter + metrics.addAll(createMetrics(queueManager, queueName, pcfParam)); + + // Below code adds current queue managers 'dead letter queue' depth. Metric key:'DLQ Depth' + // Added the logic here to avoid issuing PCF Queue Status command in 'Queue manger collector' class + if (queueName.equalsIgnoreCase("DEV.DEAD.LETTER.QUEUE") && metrickey.equalsIgnoreCase("MQIA_CURRENT_Q_DEPTH")) { + Metric metric = getMetricByKey(metrickey, metrics); + logger.info("DLQ Depth for queueManager {} is {}", WMQUtil.getQueueManagerNameFromConfig(queueManager), metric.getMetricValue()); + Metric dlqDepthmetric = createMetric(queueManager, "DLQ Depth", metric.getMetricValue(), null, "DLQ Depth"); + metrics.add(dlqDepthmetric); } + } else { + logger.warn("PCF parameter is null in response for Queue: {} for metric: {} in command {}", queueName, metrickey, command); } - } else { - logger.warn("PCF parameter is null in response for Queue: {} for metric: {} in command {}", queueName, wmqOverride.getIbmCommand(),command); + } catch (Exception pcfe) { + logger.error("Exception caught while collecting metric for Queue: {} for metric: {} in command {}", queueName, metrickey, command, pcfe); } } - catch (PCFException pcfe) { - logger.error("PCFException caught while collecting metric for Queue: {} for metric: {} in command {}",queueName, wmqOverride.getIbmCommand(),command, pcfe); + else { + logger.debug("Queue metric key {} is excluded.",metrickey); } - } + Collections.sort(allFoundMetrics); + logger.debug("start of metrics printing..."); + logger.debug(allFoundMetrics.toString()); + logger.debug("end of metrics printing..."); publishMetrics(metrics); } else{ diff --git a/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/ResetQStatsCmdCollector.java b/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/ResetQStatsCmdCollector.java index e9c6b72..05b6ded 100644 --- a/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/ResetQStatsCmdCollector.java +++ b/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/ResetQStatsCmdCollector.java @@ -18,6 +18,7 @@ import org.slf4j.Logger; import java.util.Arrays; +import java.util.List; import java.util.Map; import java.util.Set; @@ -27,8 +28,8 @@ class ResetQStatsCmdCollector extends QueueMetricsCollector implements Runnable{ protected static final String COMMAND = "MQCMD_RESET_Q_STATS"; - public ResetQStatsCmdCollector(QueueMetricsCollector collector, Map metricsToReport){ - super(metricsToReport,collector.monitorContextConfig,collector.agent,collector.queueManager,collector.metricWriteHelper, collector.countDownLatch); + public ResetQStatsCmdCollector(QueueMetricsCollector collector){ + super(collector.monitorContextConfig,collector.agent,collector.queueManager,collector.metricWriteHelper, collector.countDownLatch); } public void run() { @@ -46,12 +47,7 @@ protected void publishMetrics() throws TaskExecutionException { */ long entryTime = System.currentTimeMillis(); - if (getMetricsToReport() == null || getMetricsToReport().isEmpty()) { - logger.debug("Queue metrics to report from the config is null or empty, nothing to publish for command {}",COMMAND); - return; - } - - int[] attrs = getIntAttributesArray(CMQC.MQCA_Q_NAME); + int[] attrs = new int[] { CMQCFC.MQIACF_ALL }; logger.debug("Attributes being sent along PCF agent request to query queue metrics: {} for command {}", Arrays.toString(attrs),COMMAND); Set queueGenericNames = this.queueManager.getQueueFilters().getInclude(); diff --git a/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/TopicMetricsCollector.java b/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/TopicMetricsCollector.java index 6f6a3b4..fe1b484 100644 --- a/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/TopicMetricsCollector.java +++ b/src/main/java/com/appdynamics/extensions/webspheremq/metricscollector/TopicMetricsCollector.java @@ -11,6 +11,8 @@ import com.appdynamics.extensions.conf.MonitorContextConfiguration; import com.appdynamics.extensions.logging.ExtensionsLoggerFactory; import com.appdynamics.extensions.metrics.Metric; +import com.appdynamics.extensions.webspheremq.common.Constants; +import com.appdynamics.extensions.webspheremq.common.WMQUtil; import com.appdynamics.extensions.webspheremq.config.ExcludeFilters; import com.appdynamics.extensions.webspheremq.config.QueueManager; import com.appdynamics.extensions.webspheremq.config.WMQMetricOverride; @@ -23,18 +25,14 @@ import org.slf4j.Logger; import java.io.IOException; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.concurrent.*; public class TopicMetricsCollector extends MetricsCollector implements Runnable { public static final Logger logger = ExtensionsLoggerFactory.getLogger(TopicMetricsCollector.class); private final String artifact = "Topics"; - public TopicMetricsCollector(Map metricsToReport, MonitorContextConfiguration monitorContextConfig, PCFMessageAgent agent, QueueManager queueManager, MetricWriteHelper metricWriteHelper, CountDownLatch countDownLatch) { - this.metricsToReport = metricsToReport; + public TopicMetricsCollector(MonitorContextConfiguration monitorContextConfig, PCFMessageAgent agent, QueueManager queueManager, MetricWriteHelper metricWriteHelper, CountDownLatch countDownLatch) { this.monitorContextConfig = monitorContextConfig; this.agent = agent; this.metricWriteHelper = metricWriteHelper; @@ -56,10 +54,8 @@ protected void publishMetrics() throws TaskExecutionException { logger.info("Collecting Topic metrics..."); List futures = Lists.newArrayList(); - Map metricsForInquireTStatusCmd = getMetricsToReport(InquireTStatusCmdCollector.COMMAND); - if(!metricsForInquireTStatusCmd.isEmpty()){ - futures.add(monitorContextConfig.getContext().getExecutorService().submit("Topic Status Cmd Collector", new InquireTStatusCmdCollector(this, metricsForInquireTStatusCmd))); - } + futures.add(monitorContextConfig.getContext().getExecutorService().submit("Topic Status Cmd Collector", new InquireTStatusCmdCollector(this))); + for(Future f: futures){ try { long timeout = 20; @@ -93,23 +89,28 @@ protected void processPCFRequestAndPublishQMetrics(String topicGenericName, PCFM Set excludeFilters = this.queueManager.getTopicFilters().getExclude(); if(!isExcluded(topicString,excludeFilters)) { //check for exclude filters logger.debug("Pulling out metrics for topic name {} for command {}",topicString,command); - Iterator itr = getMetricsToReport().keySet().iterator(); + Enumeration pcfParameters = response[i].getParameters(); List metrics = Lists.newArrayList(); - while (itr.hasNext()) { - String metrickey = itr.next(); - WMQMetricOverride wmqOverride = getMetricsToReport().get(metrickey); - try{ - PCFParameter pcfParam = response[i].getParameter(wmqOverride.getConstantValue()); - if(pcfParam instanceof MQCFIN){ - int metricVal = response[i].getIntParameterValue(wmqOverride.getConstantValue()); - Metric metric = createMetric(queueManager, metrickey, metricVal, wmqOverride, getAtrifact(), topicString, metrickey); - metrics.add(metric); + List mqMetrics = (List) this.monitorContextConfig.getConfigYml().get("mqMetrics"); + List excludedMetrics = WMQUtil.getMetricsToExcludeFromConfigYml(mqMetrics, Constants.METRIC_TYPE_TOPIC); + while (pcfParameters.hasMoreElements()) { + PCFParameter pcfParam = pcfParameters.nextElement(); + String metrickey = pcfParam.getParameterName(); + if (!WMQUtil.isMetricExcluded(metrickey, excludedMetrics)) { + try { + if (pcfParam != null) { + // create metric objects from PCF parameter + metrics.addAll(createMetrics(queueManager, topicString, pcfParam)); + } else { + logger.warn("PCF parameter is null in response for Topic: {} for metric: {} in command {}", topicString, metrickey, command); + } + } catch (Exception pcfe) { + logger.error("PCFException caught while collecting metric for Topic: {} for metric: {} in command {}", topicString, metrickey, command, pcfe); } } - catch (PCFException pcfe) { - logger.error("PCFException caught while collecting metric for Topic: {} for metric: {} in command {}",topicString, wmqOverride.getIbmCommand(),command, pcfe); + else { + logger.debug("Topic metric key {} is excluded.",metrickey); } - } publishMetrics(metrics); } @@ -120,28 +121,7 @@ protected void processPCFRequestAndPublishQMetrics(String topicGenericName, PCFM } - private Map getMetricsToReport(String command) { - Map commandMetrics = Maps.newHashMap(); - if (getMetricsToReport() == null || getMetricsToReport().isEmpty()) { - logger.debug("There are no metrics configured for {}",command); - return commandMetrics; - } - Iterator itr = getMetricsToReport().keySet().iterator(); - while (itr.hasNext()) { - String metrickey = itr.next(); - WMQMetricOverride wmqOverride = getMetricsToReport().get(metrickey); - if(wmqOverride.getIbmCommand().equalsIgnoreCase(command)){ - commandMetrics.put(metrickey,wmqOverride); - } - } - return commandMetrics; - } - public String getAtrifact() { return artifact; } - - public Map getMetricsToReport() { - return this.metricsToReport; - } } diff --git a/src/main/resources/conf/config.yml b/src/main/resources/conf/config.yml index 9fd4746..f483dde 100644 --- a/src/main/resources/conf/config.yml +++ b/src/main/resources/conf/config.yml @@ -5,9 +5,9 @@ numberOfThreads: 20 #This will create it in specific Tier aka Component. Replace . Please make sure to have a trailing |. #To find out the COMPONENT_ID, please see the screen shot here https://docs.appdynamics.com/display/PRO42/Build+a+Monitoring+Extension+Using+Java -metricPrefix: "Server|Component:|Custom Metrics|WebsphereMQ|" +#metricPrefix: "Server|Component:|Custom Metrics|WebsphereMQ|" #For SIM -#metricPrefix: "Custom Metrics|WebsphereMQ|" +metricPrefix: "Custom Metrics|WebsphereMQ|" #This is the timeout on queue metrics and channel metrics threads.Default value is 20 seconds. #No need to change the default unless you know what you are doing. @@ -30,16 +30,16 @@ queueManagers: #The transport type for the queue manager connection, the default is "Bindings" for a binding type connection #For bindings type, connection WMQ extension (i.e machine agent) need to be on the same machine on which WebbsphereMQ server is running #For client type, connection change it to "Client". - transportType: "Bindings" + transportType: "Client" #Channel name of the queue manager, channel should be server-conn type. #This field is not required in case of transportType: Bindings - #channelName: "SYSTEM.ADMIN.SVRCONN" + channelName: "DEV.ADMIN.SVRCONN" #for user access level, please check "Access Permissions" section on the extensions page #comment out the username and password in case of transportType: Bindings. - #username: "" - #password: "" + username: "admin" + password: "root" #Uncomment only if encryption of passwords is wanted. #encryptedPassword: "" @@ -47,7 +47,7 @@ queueManagers: #PCF requests are always sent to SYSTEM.ADMIN.COMMAND.QUEUE. The PCF responses to these requests are sent to the default reply-to queue called #SYSTEM.DEFAULT.MODEL.QUEUE. However, you can override this behavior and send it to a temporary dynamic queue by changing the modelQueueName and replyQueuePrefix fields. #For more details around this https://www.ibm.com/support/knowledgecenter/SSFKSJ_7.5.0/com.ibm.mq.ref.adm.doc/q083240_.htm & https://www.ibm.com/support/knowledgecenter/SSFKSJ_8.0.0/com.ibm.mq.adm.doc/q020010_.htm - #modelQueueName: "" + modelQueueName: "Q1" #replyQueuePrefix: "" @@ -112,131 +112,28 @@ mqMetrics: # This Object will extract queue manager metrics - metricsType: "queueMgrMetrics" metrics: - include: - - Status: - alias: "Status" - ibmConstant: "com.ibm.mq.constants.CMQCFC.MQIACF_Q_MGR_STATUS" - aggregationType: "OBSERVATION" - timeRollUpType: "AVERAGE" - clusterRollUpType: "INDIVIDUAL" - - ConnectionCount: - alias: "ConnectionCount" - ibmConstant: "com.ibm.mq.constants.CMQCFC.MQIACF_CONNECTION_COUNT" + exclude: [] # This Object will extract queue metrics - metricsType: "queueMetrics" metrics: - include: - - MaxQueueDepth: - alias: "Max Queue Depth" - ibmConstant: "com.ibm.mq.constants.CMQC.MQIA_MAX_Q_DEPTH" - ibmCommand: "MQCMD_INQUIRE_Q" - - - CurrentQueueDepth: - alias: "Current Queue Depth" - ibmConstant: "com.ibm.mq.constants.CMQC.MQIA_CURRENT_Q_DEPTH" - ibmCommand: "MQCMD_INQUIRE_Q" - - - OpenInputCount: - alias: "Open Input Count" - ibmConstant: "com.ibm.mq.constants.CMQC.MQIA_OPEN_INPUT_COUNT" - ibmCommand: "MQCMD_INQUIRE_Q" - - - OpenOutputCount: - alias: "Open Output Count" - ibmConstant: "com.ibm.mq.constants.CMQC.MQIA_OPEN_OUTPUT_COUNT" - ibmCommand: "MQCMD_INQUIRE_Q" - -# - OldestMsgAge: -# alias: "OldestMsgAge" -# ibmConstant: "com.ibm.mq.constants.CMQCFC.MQIACF_OLDEST_MSG_AGE" -# ibmCommand: "MQCMD_INQUIRE_Q_STATUS" -# aggregationType: "OBSERVATION" -# timeRollUpType: "CURRENT" -# clusterRollUpType: "INDIVIDUAL" - - - UncommittedMsgs: - alias: "UncommittedMsgs" - ibmConstant: "com.ibm.mq.constants.CMQCFC.MQIACF_UNCOMMITTED_MSGS" - ibmCommand: "MQCMD_INQUIRE_Q_STATUS" - -# - OnQTime: -# ibmConstant: "com.ibm.mq.constants.CMQCFC.MQIACF_Q_TIME_INDICATOR" -# ibmCommand: "MQCMD_INQUIRE_Q_STATUS" -# aggregationType: "OBSERVATION" -# timeRollUpType: "CURRENT" -# clusterRollUpType: "INDIVIDUAL" - -# - HighQDepth: -# alias: "HighQDepth" -# ibmConstant: "com.ibm.mq.constants.CMQC.MQIA_HIGH_Q_DEPTH" -# ibmCommand: "MQCMD_RESET_Q_STATS" - -# - MsgDeqCount: -# alias: "MsgDeqCount" -# ibmConstant: "com.ibm.mq.constants.CMQC.MQIA_MSG_DEQ_COUNT" -# ibmCommand: "MQCMD_RESET_Q_STATS" - -# - MsgEnqCount: -# alias: "MsgEnqCount" -# ibmConstant: "com.ibm.mq.constants.CMQC.MQIA_MSG_ENQ_COUNT" -# ibmCommand: "MQCMD_RESET_Q_STATS" + exclude: [] # This Object will extract channel metrics - metricsType: "channelMetrics" metrics: - include: - - Messages: - alias: "Messages" - ibmConstant: "com.ibm.mq.constants.CMQCFC.MQIACH_MSGS" - - - Status: - alias: "Status" - ibmConstant: "com.ibm.mq.constants.CMQCFC.MQIACH_CHANNEL_STATUS" #http://www.ibm.com/support/knowledgecenter/SSFKSJ_7.5.0/com.ibm.mq.ref.dev.doc/q090880_.htm - aggregationType: "OBSERVATION" - timeRollUpType: "AVERAGE" - clusterRollUpType: "INDIVIDUAL" - - - ByteSent: - alias: "Byte Sent" - ibmConstant: "com.ibm.mq.constants.CMQCFC.MQIACH_BYTES_SENT" - - - ByteReceived: - alias: "Byte Received" - ibmConstant: "com.ibm.mq.constants.CMQCFC.MQIACH_BYTES_RECEIVED" - - - BuffersSent: - alias: "Buffers Sent" - ibmConstant: "com.ibm.mq.constants.CMQCFC.MQIACH_BUFFERS_SENT" - - - BuffersReceived: - alias: "Buffers Received" - ibmConstant: "com.ibm.mq.constants.CMQCFC.MQIACH_BUFFERS_RECEIVED" + exclude: [] - metricsType: "listenerMetrics" metrics: - include: - - Status: - alias: "Status" - ibmConstant: "com.ibm.mq.constants.CMQCFC.MQIACH_LISTENER_STATUS" - aggregationType: "OBSERVATION" - timeRollUpType: "AVERAGE" - clusterRollUpType: "INDIVIDUAL" + exclude: [] # This Object will extract topic metrics - metricsType: "topicMetrics" metrics: - include: - - PublishCount: - alias: "Publish Count" - ibmConstant: "com.ibm.mq.constants.CMQC.MQIA_PUB_COUNT" - ibmCommand: "MQCMD_INQUIRE_TOPIC_STATUS" - - SubscriptionCount: - alias: "Subscription Count" - ibmConstant: "com.ibm.mq.constants.CMQC.MQIA_SUB_COUNT" - ibmCommand: "MQCMD_INQUIRE_TOPIC_STATUS" + exclude: [] #Run it as a scheduled task instead of running every minute. #If you want to run this every minute, comment this out @@ -258,17 +155,17 @@ sslConnection: # If any of the following fields are not set, the values of the specific fields are set from the system properties of the corresponding fields as specified in the comments. # If the system properties are not set for the field, then the data is retrieved from machine agent configFile. Please refer to ControllerInfoFactory for more details. controllerInfo: - controllerHost: "controller" - controllerPort: 8080 - account: "customer1" - username: "user" + controllerHost: "24-6-0-saas-controller.e2e.appd-test.com" + controllerPort: 8090 + account: "e2e-customer" + username: "user1" password: "welcome" encryptedPassword: "" encryptionKey: "" controllerSslEnabled: false enableOrchestration: false - uniqueHostId: "" - accountAccessKey: "" + uniqueHostId: "pramadde-aws-ec6" + accountAccessKey: "0e6678e0-2bc0-40ad-9e8b-fa6fe440635e" machinePath: "" simEnabled: true applicationName: "" diff --git a/src/test/java/com/appdynamics/extensions/webspheremq/metricscollector/ChannelMetricsCollectorTest.java b/src/test/java/com/appdynamics/extensions/webspheremq/metricscollector/ChannelMetricsCollectorTest.java index 8d3a6b0..21adfa5 100644 --- a/src/test/java/com/appdynamics/extensions/webspheremq/metricscollector/ChannelMetricsCollectorTest.java +++ b/src/test/java/com/appdynamics/extensions/webspheremq/metricscollector/ChannelMetricsCollectorTest.java @@ -58,7 +58,6 @@ public class ChannelMetricsCollectorTest { private MetricWriteHelper metricWriteHelper; private MonitorContextConfiguration monitorContextConfig; - private Map channelMetricsToReport; private QueueManager queueManager; ArgumentCaptor pathCaptor = ArgumentCaptor.forClass(List.class); @@ -69,14 +68,12 @@ public void setup() { Map configMap = monitorContextConfig.getConfigYml(); ObjectMapper mapper = new ObjectMapper(); queueManager = mapper.convertValue(((List)configMap.get("queueManagers")).get(0), QueueManager.class); - Map> metricsMap = WMQUtil.getMetricsToReportFromConfigYml((List) configMap.get("mqMetrics")); - channelMetricsToReport = metricsMap.get(Constants.METRIC_TYPE_CHANNEL); } @Test public void testpublishMetrics() throws MQException, IOException, TaskExecutionException { when(pcfMessageAgent.send(any(PCFMessage.class))).thenReturn(createPCFResponseForInquireChannelStatusCmd()); - classUnderTest = new ChannelMetricsCollector(channelMetricsToReport, monitorContextConfig, pcfMessageAgent, queueManager, metricWriteHelper, Mockito.mock(CountDownLatch.class)); + classUnderTest = new ChannelMetricsCollector(monitorContextConfig, pcfMessageAgent, queueManager, metricWriteHelper, Mockito.mock(CountDownLatch.class)); classUnderTest.publishMetrics(); verify(metricWriteHelper, times(3)).transformAndPrintMetrics(pathCaptor.capture()); List metricPathsList = Lists.newArrayList(); diff --git a/src/test/java/com/appdynamics/extensions/webspheremq/metricscollector/ListenerMetricsCollectorTest.java b/src/test/java/com/appdynamics/extensions/webspheremq/metricscollector/ListenerMetricsCollectorTest.java index 907a949..5f8ee67 100644 --- a/src/test/java/com/appdynamics/extensions/webspheremq/metricscollector/ListenerMetricsCollectorTest.java +++ b/src/test/java/com/appdynamics/extensions/webspheremq/metricscollector/ListenerMetricsCollectorTest.java @@ -58,7 +58,6 @@ public class ListenerMetricsCollectorTest { private MetricWriteHelper metricWriteHelper; private MonitorContextConfiguration monitorContextConfig; - private Map listenerMetricsToReport; private QueueManager queueManager; ArgumentCaptor pathCaptor = ArgumentCaptor.forClass(List.class); @@ -69,14 +68,12 @@ public void setup() { Map configMap = monitorContextConfig.getConfigYml(); ObjectMapper mapper = new ObjectMapper(); queueManager = mapper.convertValue(((List)configMap.get("queueManagers")).get(0), QueueManager.class); - Map> metricsMap = WMQUtil.getMetricsToReportFromConfigYml((List) configMap.get("mqMetrics")); - listenerMetricsToReport = metricsMap.get(Constants.METRIC_TYPE_LISTENER); } @Test public void testpublishMetrics() throws MQException, IOException, TaskExecutionException { when(pcfMessageAgent.send(any(PCFMessage.class))).thenReturn(createPCFResponseForInquireListenerStatusCmd()); - classUnderTest = new ListenerMetricsCollector(listenerMetricsToReport, monitorContextConfig, pcfMessageAgent, queueManager, metricWriteHelper, Mockito.mock(CountDownLatch.class)); + classUnderTest = new ListenerMetricsCollector(monitorContextConfig, pcfMessageAgent, queueManager, metricWriteHelper, Mockito.mock(CountDownLatch.class)); classUnderTest.publishMetrics(); verify(metricWriteHelper, times(2)).transformAndPrintMetrics(pathCaptor.capture()); List metricPathsList = Lists.newArrayList(); diff --git a/src/test/java/com/appdynamics/extensions/webspheremq/metricscollector/QueueManagerMetricsCollectorTest.java b/src/test/java/com/appdynamics/extensions/webspheremq/metricscollector/QueueManagerMetricsCollectorTest.java index 99ab83f..8a80518 100644 --- a/src/test/java/com/appdynamics/extensions/webspheremq/metricscollector/QueueManagerMetricsCollectorTest.java +++ b/src/test/java/com/appdynamics/extensions/webspheremq/metricscollector/QueueManagerMetricsCollectorTest.java @@ -63,7 +63,6 @@ public class QueueManagerMetricsCollectorTest { private MetricWriteHelper metricWriteHelper; private MonitorContextConfiguration monitorContextConfig; - private Map queueMgrMetricsToReport; private QueueManager queueManager; ArgumentCaptor pathCaptor = ArgumentCaptor.forClass(List.class); @@ -74,14 +73,12 @@ public void setup() { Map configMap = monitorContextConfig.getConfigYml(); ObjectMapper mapper = new ObjectMapper(); queueManager = mapper.convertValue(((List)configMap.get("queueManagers")).get(0), QueueManager.class); - Map> metricsMap = WMQUtil.getMetricsToReportFromConfigYml((List) configMap.get("mqMetrics")); - queueMgrMetricsToReport = metricsMap.get(Constants.METRIC_TYPE_QUEUE_MANAGER); } @Test public void testProcessPCFRequestAndPublishQMetricsForInquireQStatusCmd() throws MQException, IOException, TaskExecutionException { when(pcfMessageAgent.send(any(PCFMessage.class))).thenReturn(createPCFResponseForInquireQMgrStatusCmd()); - classUnderTest = new QueueManagerMetricsCollector(queueMgrMetricsToReport, monitorContextConfig, pcfMessageAgent, queueManager, metricWriteHelper, Mockito.mock(CountDownLatch.class)); + classUnderTest = new QueueManagerMetricsCollector(monitorContextConfig, pcfMessageAgent, queueManager, metricWriteHelper, Mockito.mock(CountDownLatch.class)); classUnderTest.publishMetrics(); verify(metricWriteHelper, times(1)).transformAndPrintMetrics(pathCaptor.capture()); List metricPathsList = Lists.newArrayList(); @@ -152,7 +149,7 @@ private PCFMessage[] createPCFResponseForInquireQMgrStatusCmd() { @Test public void testDisplayName() throws MQException, IOException, TaskExecutionException { when(pcfMessageAgent.send(any(PCFMessage.class))).thenReturn(createPCFResponseForInquireQMgrStatusCmd()); - classUnderTest = new QueueManagerMetricsCollector(queueMgrMetricsToReport, monitorContextConfig, pcfMessageAgent, queueManager, metricWriteHelper, Mockito.mock(CountDownLatch.class)); + classUnderTest = new QueueManagerMetricsCollector(monitorContextConfig, pcfMessageAgent, queueManager, metricWriteHelper, Mockito.mock(CountDownLatch.class)); classUnderTest.publishMetrics(); verify(metricWriteHelper, times(1)).transformAndPrintMetrics(pathCaptor.capture()); List metricPathsList = Lists.newArrayList(); @@ -162,8 +159,8 @@ public void testDisplayName() throws MQException, IOException, TaskExecutionExce } } Assert.assertEquals(queueManager.getDisplayName(), "QueueManager1"); - Assert.assertThat(metricPathsList, hasItem("Server|Component:Tier1|Custom Metrics|WebsphereMQ|QueueManager1|Status")); - Assert.assertThat(metricPathsList, not(hasItem("Server|Component:Tier1|Custom Metrics|WebsphereMQ|QManager|Status"))); + Assert.assertThat(metricPathsList, hasItem("Server|Component:Tier1|Custom Metrics|WebsphereMQ|QueueManager1|MQIACF_Q_MGR_STATUS")); + Assert.assertThat(metricPathsList, not(hasItem("Server|Component:Tier1|Custom Metrics|WebsphereMQ|QManager|MQIACF_Q_MGR_STATUS"))); } } diff --git a/src/test/java/com/appdynamics/extensions/webspheremq/metricscollector/QueueMetricsCollectorTest.java b/src/test/java/com/appdynamics/extensions/webspheremq/metricscollector/QueueMetricsCollectorTest.java index 6bf2f7f..81673da 100644 --- a/src/test/java/com/appdynamics/extensions/webspheremq/metricscollector/QueueMetricsCollectorTest.java +++ b/src/test/java/com/appdynamics/extensions/webspheremq/metricscollector/QueueMetricsCollectorTest.java @@ -60,7 +60,6 @@ public class QueueMetricsCollectorTest { private CountDownLatch phaser; private MonitorContextConfiguration monitorContextConfig; - private Map queueMetricsToReport; private QueueManager queueManager; ArgumentCaptor pathCaptor = ArgumentCaptor.forClass(List.class); @@ -71,15 +70,13 @@ public void setup() { Map configMap = monitorContextConfig.getConfigYml(); ObjectMapper mapper = new ObjectMapper(); queueManager = mapper.convertValue(((List)configMap.get("queueManagers")).get(0), QueueManager.class); - Map> metricsMap = WMQUtil.getMetricsToReportFromConfigYml((List) configMap.get("mqMetrics")); - queueMetricsToReport = metricsMap.get(Constants.METRIC_TYPE_QUEUE); } @Test public void testProcessPCFRequestAndPublishQMetricsForInquireQStatusCmd() throws MQException, IOException { PCFMessage request = createPCFRequestForInquireQStatusCmd(); when(pcfMessageAgent.send(request)).thenReturn(createPCFResponseForInquireQStatusCmd()); - classUnderTest = new QueueMetricsCollector(queueMetricsToReport, monitorContextConfig, pcfMessageAgent, queueManager, metricWriteHelper, phaser); + classUnderTest = new QueueMetricsCollector(monitorContextConfig, pcfMessageAgent, queueManager, metricWriteHelper, phaser); classUnderTest.processPCFRequestAndPublishQMetrics("*", request, "MQCMD_INQUIRE_Q_STATUS"); verify(metricWriteHelper, times(2)).transformAndPrintMetrics(pathCaptor.capture()); @@ -105,7 +102,7 @@ public void testProcessPCFRequestAndPublishQMetricsForInquireQStatusCmd() throws public void testProcessPCFRequestAndPublishQMetricsForInquireQCmd() throws MQException, IOException { PCFMessage request = createPCFRequestForInquireQCmd(); when(pcfMessageAgent.send(request)).thenReturn(createPCFResponseForInquireQCmd()); - classUnderTest = new QueueMetricsCollector(queueMetricsToReport, monitorContextConfig, pcfMessageAgent, queueManager, metricWriteHelper, phaser); + classUnderTest = new QueueMetricsCollector(monitorContextConfig, pcfMessageAgent, queueManager, metricWriteHelper, phaser); classUnderTest.processPCFRequestAndPublishQMetrics("*", request, "MQCMD_INQUIRE_Q"); verify(metricWriteHelper, times(2)).transformAndPrintMetrics(pathCaptor.capture()); @@ -131,7 +128,7 @@ public void testProcessPCFRequestAndPublishQMetricsForInquireQCmd() throws MQExc public void testProcessPCFRequestAndPublishQMetricsForResetQStatsCmd() throws MQException, IOException { PCFMessage request = createPCFRequestForResetQStatsCmd(); when(pcfMessageAgent.send(request)).thenReturn(createPCFResponseForResetQStatsCmd()); - classUnderTest = new QueueMetricsCollector(queueMetricsToReport, monitorContextConfig, pcfMessageAgent, queueManager, metricWriteHelper, phaser); + classUnderTest = new QueueMetricsCollector(monitorContextConfig, pcfMessageAgent, queueManager, metricWriteHelper, phaser); classUnderTest.processPCFRequestAndPublishQMetrics("*", request, "MQCMD_RESET_Q_STATS"); verify(metricWriteHelper, times(1)).transformAndPrintMetrics(pathCaptor.capture()); diff --git a/src/test/java/com/appdynamics/extensions/webspheremq/metricscollector/TopicMetricsCollectorTest.java b/src/test/java/com/appdynamics/extensions/webspheremq/metricscollector/TopicMetricsCollectorTest.java index 773d6fb..1f00376 100644 --- a/src/test/java/com/appdynamics/extensions/webspheremq/metricscollector/TopicMetricsCollectorTest.java +++ b/src/test/java/com/appdynamics/extensions/webspheremq/metricscollector/TopicMetricsCollectorTest.java @@ -60,7 +60,6 @@ public class TopicMetricsCollectorTest { private MetricWriteHelper metricWriteHelper; private MonitorContextConfiguration monitorContextConfig; - private Map topicMetricsToReport; private QueueManager queueManager; ArgumentCaptor pathCaptor = ArgumentCaptor.forClass(List.class); @@ -71,14 +70,12 @@ public void setup() { Map configMap = monitorContextConfig.getConfigYml(); ObjectMapper mapper = new ObjectMapper(); queueManager = mapper.convertValue(((List)configMap.get("queueManagers")).get(0), QueueManager.class); - Map> metricsMap = WMQUtil.getMetricsToReportFromConfigYml((List) configMap.get("mqMetrics")); - topicMetricsToReport = metricsMap.get(Constants.METRIC_TYPE_TOPIC); } @Test public void testpublishMetrics() throws MQException, IOException, TaskExecutionException { when(pcfMessageAgent.send(any(PCFMessage.class))).thenReturn(createPCFResponseForInquireTopicStatusCmd()); - classUnderTest = new TopicMetricsCollector(topicMetricsToReport, monitorContextConfig, pcfMessageAgent, queueManager, metricWriteHelper, Mockito.mock(CountDownLatch.class)); + classUnderTest = new TopicMetricsCollector(monitorContextConfig, pcfMessageAgent, queueManager, metricWriteHelper, Mockito.mock(CountDownLatch.class)); classUnderTest.publishMetrics(); verify(metricWriteHelper, times(2)).transformAndPrintMetrics(pathCaptor.capture()); List metricPathsList = Lists.newArrayList(); From f9c71b6f15bf9299223b3a7b9c78840e1ef348f8 Mon Sep 17 00:00:00 2001 From: Darshancisco <120148267+Darshancisco@users.noreply.github.com> Date: Wed, 23 Jul 2025 06:46:22 +0530 Subject: [PATCH 2/2] changes --- .../extensions/webspheremq/common/WMQUtil.java | 5 +---- src/main/resources/conf/config.yml | 8 ++++---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/appdynamics/extensions/webspheremq/common/WMQUtil.java b/src/main/java/com/appdynamics/extensions/webspheremq/common/WMQUtil.java index 51c6d91..0e09e12 100644 --- a/src/main/java/com/appdynamics/extensions/webspheremq/common/WMQUtil.java +++ b/src/main/java/com/appdynamics/extensions/webspheremq/common/WMQUtil.java @@ -15,10 +15,7 @@ import com.google.common.base.Strings; import com.google.common.collect.Lists; import com.google.common.collect.Maps; -import com.ibm.mq.pcf.MQCFIL; -import com.ibm.mq.pcf.MQCFIN; -import com.ibm.mq.pcf.MQCFST; -import com.ibm.mq.pcf.PCFParameter; + import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; diff --git a/src/main/resources/conf/config.yml b/src/main/resources/conf/config.yml index f483dde..5e708c5 100644 --- a/src/main/resources/conf/config.yml +++ b/src/main/resources/conf/config.yml @@ -155,16 +155,16 @@ sslConnection: # If any of the following fields are not set, the values of the specific fields are set from the system properties of the corresponding fields as specified in the comments. # If the system properties are not set for the field, then the data is retrieved from machine agent configFile. Please refer to ControllerInfoFactory for more details. controllerInfo: - controllerHost: "24-6-0-saas-controller.e2e.appd-test.com" - controllerPort: 8090 - account: "e2e-customer" + controllerHost: "localhost" + controllerPort: 8080 + account: "customer1" username: "user1" password: "welcome" encryptedPassword: "" encryptionKey: "" controllerSslEnabled: false enableOrchestration: false - uniqueHostId: "pramadde-aws-ec6" + uniqueHostId: "new_metric_extension_update" accountAccessKey: "0e6678e0-2bc0-40ad-9e8b-fa6fe440635e" machinePath: "" simEnabled: true