generated from newrelic-experimental/java-instrumentation-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
1,266 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...ring/src/main/java/com/newrelic/instrumentation/labs/sap/mpl/processing/GatewayUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.newrelic.instrumentation.labs.sap.mpl.processing; | ||
|
||
import java.util.Map; | ||
|
||
import com.sap.it.op.mpl.MessageProcessingLogPart; | ||
|
||
public class GatewayUtils { | ||
|
||
public static void addAttribute(Map<String, Object> attributes, String key, Object value) { | ||
if(value != null && attributes != null && key != null && !key.isEmpty()) { | ||
attributes.put(key, value); | ||
} | ||
} | ||
|
||
public static void reportMPL(MessageProcessingLogPart logPart) { | ||
String logString = logPart.toLogString(); | ||
if(logString != null && !logString.isEmpty()) { | ||
GatewayLogger.log(logString); | ||
} | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
...g/src/main/java/com/newrelic/instrumentation/labs/sap/mpl/processing/NRLabsFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.newrelic.instrumentation.labs.sap.mpl.processing; | ||
|
||
import java.util.logging.Formatter; | ||
import java.util.logging.LogRecord; | ||
|
||
public class NRLabsFormatter extends Formatter { | ||
|
||
@Override | ||
public String format(LogRecord record) { | ||
return record.getMessage() + "\n"; | ||
} | ||
|
||
} |
131 changes: 131 additions & 0 deletions
131
...ing/src/main/java/com/newrelic/instrumentation/labs/sap/mpl/processing/NRLabsHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package com.newrelic.instrumentation.labs.sap.mpl.processing; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
import java.util.logging.Handler; | ||
import java.util.logging.Level; | ||
import java.util.logging.LogRecord; | ||
|
||
import com.newrelic.api.agent.NewRelic; | ||
|
||
public class NRLabsHandler extends Handler { | ||
|
||
private int maxFiles; | ||
private long maxSize; | ||
private long rolloverTime; | ||
private int index = 0; | ||
private File currentLog; | ||
private PrintWriter logWriter; | ||
private String logFileName; | ||
private long logCreated; | ||
|
||
public NRLabsHandler(String filename, int rolltime, long size, int max) throws IOException { | ||
logFileName = filename; | ||
if(max < 1) max = 1; | ||
maxFiles = max; | ||
if(size <= 0) { | ||
maxSize = 1024L*1024L; | ||
} else { | ||
maxSize = size; | ||
} | ||
if(rolltime <= 0) { | ||
rolloverTime = 0; | ||
} else { | ||
rolloverTime = rolltime * 60000L; | ||
} | ||
currentLog = new File(logFileName); | ||
FileWriter fWriter = new FileWriter(currentLog, true); | ||
logWriter = new PrintWriter(fWriter, true); | ||
logCreated = System.currentTimeMillis(); | ||
NewRelic.getAgent().getLogger().log(Level.FINE, "Constructed NRLabsHandler: {0}", toString()); | ||
} | ||
|
||
@Override | ||
public void publish(LogRecord record) { | ||
if(!isLoggable(record)) { | ||
NewRelic.getAgent().getLogger().log(Level.FINE, "The LogRecord {0} is not loggable", record); | ||
return; | ||
} | ||
|
||
if(logWriter == null) { | ||
NewRelic.getAgent().getLogger().log(Level.FINE, "Cannot write record because logWriter is null: {0}", record); | ||
return; | ||
} | ||
|
||
String msg = record.getMessage(); | ||
logWriter.println(msg); | ||
logWriter.flush(); | ||
} | ||
|
||
@Override | ||
public void flush() { | ||
logWriter.flush(); | ||
} | ||
|
||
@Override | ||
public void close() throws SecurityException { | ||
logWriter.close(); | ||
} | ||
|
||
private void rollLog() { | ||
logWriter.close(); | ||
|
||
int fileEnding = index + 1; | ||
if(fileEnding >= maxFiles) { | ||
fileEnding = 1; | ||
} | ||
if (maxFiles > 1) { | ||
File oldLog = new File(logFileName + "." + fileEnding); | ||
if (oldLog.exists()) { | ||
oldLog.delete(); | ||
} | ||
currentLog.renameTo(oldLog); | ||
currentLog = new File(logFileName); | ||
try { | ||
logWriter = new PrintWriter(currentLog); | ||
} catch (FileNotFoundException e) { | ||
NewRelic.getAgent().getLogger().log(Level.FINE, e, "Failed to open log file"); | ||
} | ||
index++; | ||
if(index == maxFiles) index = 0; | ||
} else { | ||
currentLog.delete(); | ||
currentLog = new File(logFileName); | ||
try { | ||
logWriter = new PrintWriter(currentLog); | ||
} catch (FileNotFoundException e) { | ||
NewRelic.getAgent().getLogger().log(Level.FINE, e, "Failed to open log file"); | ||
} | ||
} | ||
logCreated = System.currentTimeMillis(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "NRLabsHandler [maxFiles=" + maxFiles + ", maxSize=" + maxSize + ", rolloverTime=" + rolloverTime | ||
+ ", index=" + index + ", currentLog=" + currentLog + ", logWriter=" + logWriter + ", logFileName=" | ||
+ logFileName + ", logCreated=" + logCreated + "]"; | ||
} | ||
|
||
public void checkForRoll() { | ||
boolean rolled = false; | ||
long logSize = currentLog.length(); | ||
if(logSize > maxSize) { | ||
NewRelic.getAgent().getLogger().log(Level.FINE, "Rolling log {0} because current size {1} exceeds max file {2}", logFileName, logSize, maxSize); | ||
rollLog(); | ||
rolled = true; | ||
} | ||
|
||
long timeExisted = System.currentTimeMillis() - logCreated; | ||
|
||
if(!rolled && rolloverTime != 0 && (timeExisted > rolloverTime)) { | ||
NewRelic.getAgent().getLogger().log(Level.FINE, "Rolling log {0} because file existence {1} exceeds max time {2}", logFileName, timeExisted, rolloverTime); | ||
rollLog(); | ||
} | ||
|
||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
...g/src/main/java/com/newrelic/instrumentation/labs/sap/mpl/processing/NRLabsTimerTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.newrelic.instrumentation.labs.sap.mpl.processing; | ||
|
||
import java.util.TimerTask; | ||
|
||
public class NRLabsTimerTask extends TimerTask { | ||
|
||
@Override | ||
public void run() { | ||
GatewayLogger.checkConfig(); | ||
} | ||
|
||
} |
19 changes: 0 additions & 19 deletions
19
sap-gateway-monitoring/src/main/java/com/sap/it/op/agent/collector/camel/MplAccessor.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.