Skip to content

Commit

Permalink
Merge pull request #8 from Appdynamics/6.0.1
Browse files Browse the repository at this point in the history
Minor Bug fixes related to metric reporting and log4j2
  • Loading branch information
saxenaabhi142 authored Dec 2, 2021
2 parents 65c8f1c + 15c38ea commit bf2f571
Show file tree
Hide file tree
Showing 28 changed files with 1,455 additions and 1,594 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# IBM websphere message broker Monitoring Extension CHANGELOG

### Version 6.0.1
- Fixed issue related to reporting of metrics
- Fixed error related to log4j2

### Version 6.0.0
- Revamped extension to appd-exts-commons 2.2.4
655 changes: 294 additions & 361 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.appdynamics.extensions</groupId>
<artifactId>websphere-message-broker-extension</artifactId>
<version>6.0.0</version>
<version>6.0.1</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -177,7 +177,7 @@
<copy todir="${target.dir}">
<fileset dir="src/main/resources/conf" includes="monitor.xml"/>
<fileset dir="src/main/resources/conf" includes="config.yml"/>
<fileset dir="src/main/resources/conf" includes="log4j.xml"/>
<fileset dir="src/main/resources/conf" includes="log4j2.xml"/>
<fileset dir="src/main/resources/conf" includes="log4j.dtd"/>
<fileset dir="src/main/resources/" includes="appd-message-broker-monitor.sh"/>
<fileset dir="src/main/resources/" includes="appd-message-broker-monitor.bat"/>
Expand Down
62 changes: 48 additions & 14 deletions src/main/java/com/appdynamics/extensions/wmb/StatsProcessor.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.appdynamics.extensions.wmb;

import com.appdynamics.extensions.MetricWriteHelper;
import com.appdynamics.extensions.metrics.Metric;
import com.appdynamics.extensions.wmb.metricUtils.*;
import com.google.common.collect.Maps;

import javax.jms.*;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

Expand All @@ -17,19 +17,51 @@ public abstract class StatsProcessor<T> {

protected Map config;
protected XmlParser<T> parser;
protected MetricWriteHelper metricWriteHelper;
protected String metricPrefix;
protected Map<String,Map> metricPropsHolder;
protected MetricPrinter printer;
protected Map<String,MetricProperties> metricPropsHolder;
protected final MetricValueTransformer valueTransformer = new MetricValueTransformer();

public StatsProcessor(Map config, XmlParser<T> parser, MetricWriteHelper metricWriteHelper,String metricPrefix) {
public StatsProcessor(Map config, XmlParser<T> parser, MetricPrinter printer) {
this.config = config;
this.printer = printer;
this.parser = parser;
this.metricWriteHelper = metricWriteHelper;
this.metricPrefix=metricPrefix;
}

public abstract void subscribe(Session session) throws JMSException;

protected MetricProperties createMetricProperties(Map metadata, String metricName, String alias) {
MetricProperties props = new DefaultMetricProperties();
props.setAlias(alias);
props.setMetricName(metricName);
if(metadata.get("metricType") != null){
props.setAggregationFields(metadata.get("metricType").toString());
}
if(metadata.get("multiplier") != null){
props.setMultiplier(Double.parseDouble(metadata.get("multiplier").toString()));
}
if(metadata.get("convert") != null){
props.setConversionValues((Map)metadata.get("convert"));
}
if(metadata.get("delta") != null){
props.setDelta(Boolean.parseBoolean(metadata.get("delta").toString()));
}
return props;
}

protected Metric createMetricPoint(String metricPath, String value, MetricProperties properties, String metricName) {
BigDecimal decimalValue = valueTransformer.transform(metricPath + SEPARATOR + metricName, value, properties);
if (decimalValue != null) {
Metric m = new Metric();
m.setMetricName(metricName);
m.setMetricPath(metricPath);
m.setProperties(properties);
m.setMetricValue(decimalValue);
return m;
} else {
return null;
}
}

protected String getMessageString(Message message) throws JMSException {
if(message != null) {
if (message instanceof TextMessage) {
Expand All @@ -46,9 +78,8 @@ protected String getMessageString(Message message) throws JMSException {
}

//creates a map from the config.yaml of all the configured metrics along with their configured metric properties.
//protected Map<String, MetricProperties> buildMetricProperties(String name,String typeOfStatistics) {
protected Map<String, Map> buildMetricProperties(String name,String typeOfStatistics) {
Map<String,Map> propertiesMap = Maps.newHashMap();
protected Map<String, MetricProperties> buildMetricProperties(String name,String typeOfStatistics) {
Map<String,MetricProperties> propertiesMap = Maps.newHashMap();
Object metricsObj = config.get(name);
if(metricsObj != null){
Map metrics = (Map)metricsObj;
Expand All @@ -65,8 +96,11 @@ protected Map<String, Map> buildMetricProperties(String name,String typeOfStatis
if(includeMetrics != null){
for(Object includeObj : includeMetrics){
Map metadata = (Map)includeObj;
String metricName = (String) metadata.get("name");
propertiesMap.put(join(SEPARATOR,type,identifier,metricName),metadata);
Map.Entry entry = (Map.Entry)metadata.entrySet().iterator().next();
String metricName = entry.getKey().toString();
String alias = entry.getValue().toString();
MetricProperties props = createMetricProperties(metadata, metricName, alias);
propertiesMap.put(join(SEPARATOR,type,identifier,metricName),props);
}
}
}
Expand All @@ -79,4 +113,4 @@ protected Map<String, Map> buildMetricProperties(String name,String typeOfStatis
}

protected abstract List<Metric> buildMetrics(T stats);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.appdynamics.extensions.wmb;

import com.appdynamics.extensions.MetricWriteHelper;
import com.appdynamics.extensions.logging.ExtensionsLoggerFactory;
import com.appdynamics.extensions.wmb.flowstats.FlowStatistics;
import com.appdynamics.extensions.wmb.flowstats.FlowStatsProcessor;
import com.appdynamics.extensions.wmb.metricUtils.MetricPrinter;
import com.appdynamics.extensions.wmb.resourcestats.ResourceStatistics;
import com.appdynamics.extensions.wmb.resourcestats.ResourceStatsProcessor;
import org.slf4j.Logger;
Expand All @@ -17,30 +18,26 @@ class StatsSubscription {

private static final Logger logger = ExtensionsLoggerFactory.getLogger(StatsSubscription.class);
private Map config;
private MetricWriteHelper metricWriteHelper;
private String metricPrefix;
private MetricPrinter printer;
final ParserFactory parserFactory = new ParserFactory();

StatsSubscription(Map queueManagerConfig, MetricWriteHelper metricWriteHelper,String metricPrefix) {
StatsSubscription(Map queueManagerConfig, MetricPrinter metricPrinter) {
this.config = queueManagerConfig;
this.metricWriteHelper=metricWriteHelper;
this.metricPrefix=metricPrefix;
this.printer = metricPrinter;
}

void subscribe(Connection conn) throws JMSException, JAXBException {
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Subscribe to resource statistics
if (config.get("resourceStatisticsSubscribers") != null) {
logger.info("Subscribing to resourceStatisticsSubscribers");
StatsProcessor<ResourceStatistics> resourceStatsProcessor = new ResourceStatsProcessor<ResourceStatistics>(config,parserFactory.getResourceStatisticsParser(),metricWriteHelper,metricPrefix);
StatsProcessor<ResourceStatistics> resourceStatsProcessor = new ResourceStatsProcessor<ResourceStatistics>(config,parserFactory.getResourceStatisticsParser(),printer);
resourceStatsProcessor.subscribe(session);
}
// Subscribe to message flow statistics
if (config.get("flowStatisticsSubscribers") != null) {
logger.info("Subscribing to flowStatisticsSubscribers");
StatsProcessor<FlowStatistics> flowStatsProcessor = new com.appdynamics.extensions.wmb.flowstats.FlowStatsProcessor(config,parserFactory.getFlowStatisticsParser(),metricWriteHelper,metricPrefix);
StatsProcessor<FlowStatistics> flowStatsProcessor = new FlowStatsProcessor(config,parserFactory.getFlowStatisticsParser(),printer);
flowStatsProcessor.subscribe(session);
}

}
}
}
68 changes: 35 additions & 33 deletions src/main/java/com/appdynamics/extensions/wmb/WMBMonitor.java
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
package com.appdynamics.extensions.wmb;


import com.appdynamics.extensions.ABaseMonitor;
import com.appdynamics.extensions.MetricWriteHelper;
import com.appdynamics.extensions.TasksExecutionServiceProvider;
import com.appdynamics.extensions.conf.MonitorContextConfiguration;
import com.appdynamics.extensions.logging.ExtensionsLoggerFactory;
import com.appdynamics.extensions.util.AssertUtils;
import com.appdynamics.extensions.util.PathResolver;
import com.singularity.ee.agent.systemagent.api.exception.TaskExecutionException;
import com.appdynamics.extensions.wmb.metricUtils.CustomMetricWriter;
import com.google.common.collect.Maps;
import org.slf4j.Logger;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class WMBMonitor extends ABaseMonitor {
public class WMBMonitor extends ABaseMonitor{

private static final Logger logger = ExtensionsLoggerFactory.getLogger(WMBMonitor.class);

private MonitorContextConfiguration monitorContextConfiguration;
private Map<String, ?> configYml;
private static final String DEFAULT_METRIC_PREFIX = "Custom Metrics|WMB";
private static final String MONITOR_NAME = "WMBMonitor";
private static final String MA_PID = "MA-PID";
private static final String CONFIG_FILE = "config-file";
private static final String NAME = "name";
private static ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
private static CountDownLatch sharedLatch = new CountDownLatch(1);
private static String pid;
private static final Logger logger = ExtensionsLoggerFactory.getLogger(WMBMonitor.class);

private static final String DEFAULT_METRIC_PREFIX = "Custom Metrics|WMB";
private static final String MONITOR_NAME = "WMBMonitor";
private static final String NAME = "name";
private static final String MA_PID = "MA-PID";
private static final String CONFIG_FILE = "config-file";

@Override
protected String getDefaultMetricPrefix() {
return DEFAULT_METRIC_PREFIX;
}

@Override
public String getMonitorName() {
return MONITOR_NAME;
}
Expand All @@ -47,69 +47,71 @@ public String getMonitorName() {
protected void initializeMoreStuff(Map<String, String> args) {
monitorContextConfiguration = getContextConfiguration();
configYml = monitorContextConfiguration.getConfigYml();
pid = args.get(MA_PID);
}

@Override
protected void doRun(TasksExecutionServiceProvider tasksExecutionServiceProvider) {

List<Map> queueManagers = (List<Map>) configYml.get("queueManagers");
AssertUtils.assertNotNull(queueManagers, "QueueManagers cannot be null");
for (Map queueManager : queueManagers) {
AssertUtils.assertNotNull(queueManager, "QueueManager cannot be null");
WMBMonitorTask task = createTask(queueManager, tasksExecutionServiceProvider.getMetricWriteHelper());
WMBMonitorTask task = createTask(queueManager, new CustomMetricWriter(),sharedLatch);
tasksExecutionServiceProvider.submit((String) queueManager.get(NAME), task);
}
Map watchDogProperties = (Map) configYml.get("machineAgentWatchDog");

Map watchDogProperties = (Map)configYml.get("machineAgentWatchDog");
/*
* This extension works in continuous mode and starts a JVM by invoking a script. When the MA dies, the extension becomes
* an orphanned process. To better manage the extension, we watch the MA process using MA PID passed through the script.
*/
scheduler.scheduleAtFixedRate(new ProcessWatchDog(pid, sharedLatch, PathResolver.resolveDirectory(this.getClass())), ((Integer) watchDogProperties.get("initialDelay")).longValue(), ((Integer) watchDogProperties.get("period")).longValue(), TimeUnit.SECONDS);
scheduler.scheduleAtFixedRate(new ProcessWatchDog(pid, sharedLatch, PathResolver.resolveDirectory(this.getClass())), ((Integer)watchDogProperties.get("initialDelay")).longValue(),((Integer)watchDogProperties.get("period")).longValue(), TimeUnit.SECONDS);

}

private WMBMonitorTask createTask(Map queueManager, MetricWriteHelper metricWriteHelper) {
private WMBMonitorTask createTask(Map queueManager, MetricWriteHelper metricWriteHelper, CountDownLatch sharedLatch) {
return new WMBMonitorTask.Builder()
.metricPrefix(monitorContextConfiguration.getMetricPrefix())
.metricWriter(metricWriteHelper)
.manager(queueManager)
.countdownLatch(sharedLatch)
.build();
}

@Override
protected List<Map<String, ?>> getServers() {
return (List<Map<String, ?>>) configYml.get("queueManagers");
}

public static void main(String[] args) throws TaskExecutionException {

public static void main(String[] args){
if (args == null || args.length == 0) {
logger.error("MA PID was not passed as an argument to WMBMonitor.");
return;
}
if (args.length > 1) {
if(args.length > 1){
logger.error("Incorrect number of arguments were passed to WMBMonitor.");
return;
}

logger.info("MA pid = [{}]", args[0]);
pid = args[0];
final WMBMonitor monitor = new WMBMonitor();
logger.info("MA pid = {}",args[0]);
final WMBMonitor wmbMonitor = new WMBMonitor();
String configFile = System.getProperty("extension.configuration");
final Map<String, String> taskArgs = new HashMap<>();
taskArgs.put(CONFIG_FILE, configFile);
taskArgs.put(MA_PID, args[0]);

Map<String,String> taskArgs = Maps.newHashMap();
taskArgs.put(CONFIG_FILE,configFile);
taskArgs.put(MA_PID,args[0]);
try {
monitor.execute(taskArgs, null);
wmbMonitor.execute(taskArgs,null);
logger.info("Connection started. Wait Indefinitely...");
sharedLatch.await();
logger.info("My parent has died. I have to die as well.");
System.exit(0);
} catch (Exception e) {
logger.error("Error in Execution");
} finally {
if (scheduler != null) {
}
catch(Exception e){
logger.error("Error in execution",e);
}
finally{
if(scheduler != null){
scheduler.shutdown();
}
}
}
}
}
Loading

0 comments on commit bf2f571

Please sign in to comment.