Skip to content
This repository was archived by the owner on Jun 8, 2020. It is now read-only.

Commit 9975a58

Browse files
author
Guenter Grossberger
committed
added option to ignore monitors in maintenance and some minor changes
1 parent b162039 commit 9975a58

File tree

10 files changed

+171
-6
lines changed

10 files changed

+171
-6
lines changed

asm-monitor/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.ca.apm.extensions</groupId>
55
<artifactId>asm-monitor</artifactId>
6-
<version>1.5.7</version>
6+
<version>1.5.8</version>
77
<name>ASMMonitor</name>
88
<description>Extension to integrate App Synthetic Monitor (fka Cloud Monitor, WatchMouse) into CA APM.</description>
99

asm-monitor/src/main/java/com/ca/apm/swat/epaplugins/asm/AsmReader.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ protected static void setProperties(Properties properties) {
231231
* Connects to ASM API and gets all folder, monitor and monitoring station information.
232232
* Then starts a thread per folder to collect the monitor metrics.
233233
* @param epaWaitTime sleep time in main loop
234-
* @param properties properties read from config file
235234
* @param metricWriter interface to EPAgent, write metrics here
236235
*/
237236
private void work(int epaWaitTime, MetricWriter metricWriter) {
@@ -496,7 +495,7 @@ private void stopThreads() {
496495
"cancelling task for folder " + futureMap.get(future));
497496

498497
if (future.cancel(true)) {
499-
log(SeverityLevel.VERBOSE,
498+
log(SeverityLevel.WARN,
500499
"folder " + futureMap.get(future) + " could not be cancelled");
501500
}
502501
}

asm-monitor/src/main/java/com/ca/apm/swat/epaplugins/asm/AsmRequestHelper.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ public void printApiCallStatistics() {
132132
resetValues = true;
133133
}
134134

135+
// don't reset counters if just started
136+
if (0 == lastPrintApiTimestamp) {
137+
lastPrintApiTimestamp = now.getTime();
138+
}
139+
135140
long timeElapsed = now.getTime() - lastPrintApiTimestamp;
136141
if (PRINT_API_INTERVAL < timeElapsed) {
137142
lastPrintApiTimestamp = now.getTime();
@@ -158,7 +163,7 @@ public void printApiCallStatistics() {
158163
count = 0;
159164
for (Iterator<String> mit = map.keySet().iterator(); mit.hasNext(); ) {
160165
String cmd = mit.next();
161-
buf.append(map.get(cmd)).append(' ').append(cmd).append(',');
166+
buf.append(map.get(cmd)).append(' ').append(cmd).append(", ");
162167
count += map.get(cmd);
163168
if (resetValues) {
164169
map.put(cmd, Long.valueOf(0));

asm-monitor/src/main/java/com/ca/apm/swat/epaplugins/asm/monitor/BaseMonitor.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
*
2727
*/
2828
public class BaseMonitor extends AbstractMonitor implements AsmProperties {
29-
3029
private String name = null;
3130
private String folder = null;
3231
private String[] tags = null;
@@ -139,7 +138,6 @@ public Map<String, String> generateMetrics(
139138

140139
JSONObject jsonObject = new JSONObject(jsonString);
141140
String name = jsonObject.optString(NAME_TAG, null);
142-
Monitor monitor = null;
143141
Module module = new Module(Thread.currentThread().getName());
144142
int originalMapSize = metricMap.size();
145143

@@ -153,7 +151,14 @@ public Map<String, String> generateMetrics(
153151
return metricMap;
154152
}
155153

154+
// return if this monitor is in maintenance and REPORT_MAINTENANCE=false
155+
if (!(EpaUtils.getBooleanProperty(REPORT_MAINTENANCE, true))
156+
&& (3 == jsonObject.optInt(TYPE_TAG, 0))) {
157+
return metricMap;
158+
}
159+
156160
// if we find a name append it to metric tree
161+
Monitor monitor = null;
157162
if (name != null) {
158163
metricTree = metricTree + METRIC_PATH_SEPARATOR + name;
159164

asm-monitor/src/main/java/com/ca/apm/swat/epaplugins/utils/AsmProperties.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public interface AsmProperties {
102102
public static final String SKIP_NO_CHECKPOINT_AVAILABLE = "asm.skipNoCheckpointAvailable";
103103
public static final String REPORT_PER_INTERVAL_COUNTER = "asm.report.perIntervalCounter";
104104
public static final String REPORT_LONG_AVERAGE = "asm.report.longAverage";
105+
public static final String REPORT_MAINTENANCE = "asm.report.maintenance";
105106

106107
// folder and other constants in properties
107108
public static final String ROOT_FOLDER = "root_folder";

asm-monitor/src/main/java/com/ca/apm/swat/epaplugins/utils/CryptoUtils.java

100755100644
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class CryptoUtils implements AsmProperties {
2525
private AlgorithmParameterSpec paramSpec;
2626

2727
public static final String UTF8 = "UTF8";
28+
2829
/**
2930
* Create new helper class for encryption.
3031
* @param passPhrase pass phrase

asm-monitor/src/main/java/com/wily/introscope/epagent/EpaUtils.java

100755100644
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class EpaUtils {
2727
*/
2828
private EpaUtils() {
2929
}
30+
3031
/**
3132
* Get the logging component.
3233
* @return the logging component

asm-monitor/src/main/resources/AppSyntheticMonitor.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,15 @@ asm.report.perIntervalCounter=false
175175
#
176176
asm.report.longAverage=false
177177

178+
######################################
179+
# Report monitors in maintenance.
180+
#
181+
# By default ASM Monitor reports all monitors, also monitors in maintenance mode.
182+
# If you set asm.report.maintenance=false new metrics for monitors that are in maintenance will not be reported.
183+
# Metric values from the time before the maintenance period started will continue to be shown.
184+
#
185+
asm.report.maintenance=true
186+
178187
######################################
179188
# Response code translation
180189
#

asm-monitor/src/test/java/com/ca/apm/swat/epaplugins/asm/LogTest.java

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,149 @@ public void getLogFolder() {
243243
}
244244
}
245245

246+
/**
247+
* Test getLog() for a monitor in maintenance.
248+
*/
249+
@Test
250+
public void getLogMaintenance() {
251+
252+
try {
253+
// set properties
254+
EpaUtils.getProperties().setProperty(METRICS_LOGS, TRUE);
255+
EpaUtils.getProperties().setProperty(DISPLAY_STATIONS, FALSE);
256+
EpaUtils.getProperties().setProperty(REPORT_MAINTENANCE, FALSE);
257+
258+
String folder = "Tests";
259+
// Monitor monitor = MonitorFactory.getMonitor("Simple JMeter recording",
260+
// SCRIPT_MONITOR, folder, EMPTY_STRING_ARRAY);
261+
int numMonitors = 5;
262+
String metricPrefix = MONITOR_METRIC_PREFIX + folder;
263+
264+
// load file
265+
accessor.loadFile(LOGS_CMD, "target/test-classes/rule_log_maintenance.json");
266+
267+
// call API
268+
Map<String, String> metricMap =
269+
requestHelper.getLogs(folder, numMonitors, metricPrefix, null).getMap();
270+
271+
// metricMap should contain those entries
272+
273+
String[] expectedMetrics = {
274+
"Monitors|Tests:Agent Time Zone",
275+
"Monitors|Tests|Simple HTTP validation test:Alerts Per Interval",
276+
"Monitors|Tests|Simple HTTP validation test:Check End Time",
277+
"Monitors|Tests|Simple HTTP validation test:Check Start Time",
278+
"Monitors|Tests|Simple HTTP validation test:Connect Time (ms)",
279+
"Monitors|Tests|Simple HTTP validation test:Download Size (kB)",
280+
"Monitors|Tests|Simple HTTP validation test:Download Time (ms)",
281+
"Monitors|Tests|Simple HTTP validation test:IP Address",
282+
"Monitors|Tests|Simple HTTP validation test:Location Code",
283+
"Monitors|Tests|Simple HTTP validation test:Processing Time (ms)",
284+
"Monitors|Tests|Simple HTTP validation test:Repeat",
285+
"Monitors|Tests|Simple HTTP validation test:Resolve Time (ms)",
286+
"Monitors|Tests|Simple HTTP validation test:Result Code",
287+
"Monitors|Tests|Simple HTTP validation test:Monitor ID",
288+
"Monitors|Tests|Simple HTTP validation test:Monitor Name",
289+
"Monitors|Tests|Simple HTTP validation test:Total Time (ms)",
290+
"Monitors|Tests|Simple HTTP validation test:Type",
291+
"Monitors|Tests|Simple HTTP validation test:Monitor ID",
292+
"Monitors|Tests|DNS test:Alerts Per Interval",
293+
"Monitors|Tests|DNS test:Check End Time",
294+
"Monitors|Tests|DNS test:Check Start Time",
295+
"Monitors|Tests|DNS test:Download Size (kB)",
296+
"Monitors|Tests|DNS test:Download Time (ms)",
297+
/* monitor "FTP test" is in maintenance (type=3) and shoudl not be reported
298+
299+
"Monitors|Tests|FTP test:IP Address",
300+
"Monitors|Tests|FTP test:Location Code",
301+
"Monitors|Tests|FTP test:Processing Time (ms)",
302+
"Monitors|Tests|FTP test:Repeat",
303+
"Monitors|Tests|FTP test:Result Code",
304+
"Monitors|Tests|FTP test:Monitor ID",
305+
"Monitors|Tests|FTP test:Monitor Name",
306+
*/
307+
"Monitors|Tests|Custom page ping:Total Time (ms)",
308+
"Monitors|Tests|Custom page ping:Type",
309+
"Monitors|Tests|Custom page ping:Monitor ID",
310+
"Monitors|Tests|Custom page ping:Connect Time (ms)",
311+
};
312+
313+
if (DEBUG) {
314+
TreeSet<String> sortedSet = new TreeSet<String>(metricMap.keySet());
315+
for (Iterator<String> it = sortedSet.iterator(); it.hasNext(); ) {
316+
String key = it.next();
317+
System.out.println(key + " = " + metricMap.get(key));
318+
}
319+
}
320+
321+
// check
322+
checkMetrics(expectedMetrics, metricMap);
323+
324+
} catch (Exception e) {
325+
e.printStackTrace();
326+
Assert.fail(e.getMessage());
327+
}
328+
}
329+
330+
/**
331+
* Test getLog() for a monitor in maintenance.
332+
*/
333+
@Test
334+
public void getLogMaintenance2() {
335+
336+
try {
337+
// set properties
338+
EpaUtils.getProperties().setProperty(METRICS_LOGS, TRUE);
339+
EpaUtils.getProperties().setProperty(DISPLAY_STATIONS, FALSE);
340+
// EpaUtils.getProperties().setProperty(REPORT_MAINTENANCE, FALSE); default is true
341+
342+
String folder = "Tests";
343+
// Monitor monitor = MonitorFactory.getMonitor("Simple JMeter recording",
344+
// SCRIPT_MONITOR, folder, EMPTY_STRING_ARRAY);
345+
int numMonitors = 5;
346+
String metricPrefix = MONITOR_METRIC_PREFIX + folder;
347+
348+
// load file
349+
accessor.loadFile(LOGS_CMD, "target/test-classes/rule_log_maintenance.json");
350+
351+
// call API
352+
Map<String, String> metricMap =
353+
requestHelper.getLogs(folder, numMonitors, metricPrefix, null).getMap();
354+
355+
// metricMap should contain those entries
356+
// monitor "FTP test" is in maintenance (type=3) but will be reported nonetheless
357+
358+
String[] expectedMetrics = {
359+
"Monitors|Tests:Agent Time Zone",
360+
"Monitors|Tests|Simple HTTP validation test:Alerts Per Interval",
361+
"Monitors|Tests|DNS test:Check End Time",
362+
"Monitors|Tests|FTP test:IP Address",
363+
"Monitors|Tests|FTP test:Location Code",
364+
"Monitors|Tests|FTP test:Processing Time (ms)",
365+
"Monitors|Tests|FTP test:Repeat",
366+
"Monitors|Tests|FTP test:Result Code",
367+
"Monitors|Tests|FTP test:Monitor ID",
368+
"Monitors|Tests|FTP test:Monitor Name",
369+
"Monitors|Tests|Custom page ping:Type",
370+
};
371+
372+
if (DEBUG) {
373+
TreeSet<String> sortedSet = new TreeSet<String>(metricMap.keySet());
374+
for (Iterator<String> it = sortedSet.iterator(); it.hasNext(); ) {
375+
String key = it.next();
376+
System.out.println(key + " = " + metricMap.get(key));
377+
}
378+
}
379+
380+
// check
381+
checkMetrics(expectedMetrics, metricMap);
382+
383+
} catch (Exception e) {
384+
e.printStackTrace();
385+
Assert.fail(e.getMessage());
386+
}
387+
}
388+
246389
/**
247390
* Test getLog() for a http monitor.
248391
*/

asm-monitor/src/test/resources/rule_log_maintenance.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)