Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -129,48 +131,22 @@ private PCFMessageAgent initPCFMesageAgent(MQQueueManager ibmQueueManager) {

private void extractAndReportMetrics(PCFMessageAgent agent) {
Map<String, Map<String, WMQMetricOverride>> metricsMap = WMQUtil.getMetricsToReportFromConfigYml((List<Map>) configMap.get("mqMetrics"));

CountDownLatch countDownLatch = new CountDownLatch(metricsMap.size());

Map<String, WMQMetricOverride> 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<String, WMQMetricOverride> 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<String, WMQMetricOverride> 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<String, WMQMetricOverride> 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<String, WMQMetricOverride> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,33 @@
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 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.<br>
* It contains metric type as key and a map of metric and WMQMetricOverride as value,<br>
Expand All @@ -38,6 +54,36 @@ public static Map<String, Map<String, WMQMetricOverride>> getMetricsToReportFrom
return metricsMap;
}

/**
* Returns master data structure,This map will contain only those metrics which are to be excluded.<br>
* It contains metric type as key and a list of metric keys to be excluded.
*/
public static List<String> getMetricsToExcludeFromConfigYml(List<Map> mqMetrics, String metricType) {
List<String> 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<String> 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<String, WMQMetricOverride> gatherMetricNamesByApplyingIncludeFilter(List includeMetrics) {
Map<String, WMQMetricOverride> overrideMap = Maps.newHashMap();
for (Object inc : includeMetrics) {
Expand Down Expand Up @@ -69,4 +115,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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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<String, WMQMetricOverride> 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;
Expand All @@ -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<String> channelGenericNames = this.queueManager.getChannelFilters().getInclude();
Expand All @@ -98,19 +94,35 @@ protected void publishMetrics() throws TaskExecutionException {
Set<ExcludeFilters> excludeFilters = this.queueManager.getChannelFilters().getExclude();
if(!isExcluded(channelName,excludeFilters)) { //check for exclude filters
logger.debug("Pulling out metrics for channel name {}",channelName);
Iterator<String> itr = getMetricsToReport().keySet().iterator();
Enumeration<PCFParameter> pcfParameters = response[i].getParameters();
List<Metric> 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<Map> mqMetrics = (List<Map>) this.monitorContextConfig.getConfigYml().get("mqMetrics");
List<String> 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);
}
Expand Down Expand Up @@ -146,8 +158,4 @@ protected void publishMetrics() throws TaskExecutionException {
public String getAtrifact() {
return artifact;
}

public Map<String, WMQMetricOverride> getMetricsToReport() {
return this.metricsToReport;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.slf4j.Logger;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;

Expand All @@ -26,8 +27,8 @@ class InquireQCmdCollector extends QueueMetricsCollector implements Runnable {

protected static final String COMMAND = "MQCMD_INQUIRE_Q";

public InquireQCmdCollector(QueueMetricsCollector collector, Map<String, WMQMetricOverride> 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() {
Expand All @@ -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<String> queueGenericNames = this.queueManager.getQueueFilters().getInclude();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.slf4j.Logger;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;

Expand All @@ -26,8 +27,8 @@ class InquireQStatusCmdCollector extends QueueMetricsCollector implements Runnab

protected static final String COMMAND = "MQCMD_INQUIRE_Q_STATUS";

public InquireQStatusCmdCollector(QueueMetricsCollector collector, Map<String, WMQMetricOverride> 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() {
Expand All @@ -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<String> queueGenericNames = this.queueManager.getQueueFilters().getInclude();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -25,8 +26,8 @@ class InquireTStatusCmdCollector extends TopicMetricsCollector implements Runnab

protected static final String COMMAND = "MQCMD_INQUIRE_TOPIC_STATUS";

public InquireTStatusCmdCollector(TopicMetricsCollector collector, Map<String, WMQMetricOverride> 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() {
Expand All @@ -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<String> 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
Expand All @@ -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());
Expand Down
Loading