commit
c346091203
|
|
@ -0,0 +1,17 @@
|
|||
# Editor configuration, see http://editorconfig.org
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
max_line_length = 80
|
||||
|
||||
[*.sh]
|
||||
end_of_line = lf
|
||||
|
||||
[*.java]
|
||||
indent_size = 4
|
||||
max_line_length = 120
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
##############################
|
||||
## Java
|
||||
##############################
|
||||
.mtj.tmp/
|
||||
*.class
|
||||
*.jar
|
||||
*.war
|
||||
*.ear
|
||||
*.nar
|
||||
hs_err_pid*
|
||||
replay_pid*
|
||||
|
||||
##############################
|
||||
## Maven
|
||||
##############################
|
||||
target/
|
||||
pom.xml.tag
|
||||
pom.xml.releaseBackup
|
||||
pom.xml.versionsBackup
|
||||
pom.xml.next
|
||||
pom.xml.bak
|
||||
release.properties
|
||||
dependency-reduced-pom.xml
|
||||
buildNumber.properties
|
||||
.mvn/timing.properties
|
||||
.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
##############################
|
||||
## Gradle
|
||||
##############################
|
||||
bin/
|
||||
build/
|
||||
.gradle
|
||||
.gradletasknamecache
|
||||
gradle-app.setting
|
||||
!gradle-wrapper.jar
|
||||
|
||||
##############################
|
||||
## IntelliJ
|
||||
##############################
|
||||
out/
|
||||
.idea/
|
||||
.idea_modules/
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
|
||||
##############################
|
||||
## Eclipse
|
||||
##############################
|
||||
.settings/
|
||||
bin/
|
||||
tmp/
|
||||
.metadata
|
||||
.classpath
|
||||
.project
|
||||
*.tmp
|
||||
*.bak
|
||||
*.swp
|
||||
*~.nib
|
||||
local.properties
|
||||
.loadpath
|
||||
.factorypath
|
||||
|
||||
##############################
|
||||
## NetBeans
|
||||
##############################
|
||||
nbproject/private/
|
||||
build/
|
||||
nbbuild/
|
||||
dist/
|
||||
nbdist/
|
||||
nbactions.xml
|
||||
nb-configuration.xml
|
||||
|
||||
##############################
|
||||
## Visual Studio Code
|
||||
##############################
|
||||
.vscode/
|
||||
.code-workspace
|
||||
|
||||
##############################
|
||||
## OS X
|
||||
##############################
|
||||
.DS_Store
|
||||
|
||||
##############################
|
||||
## Miscellaneous
|
||||
##############################
|
||||
*.log
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"instrument":[
|
||||
{
|
||||
"class": "com.javadevelopersguide.jersey.resources",
|
||||
"methods":["fetchAll", "create"]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"instrument":[
|
||||
{
|
||||
"class": "org.jboss.as.quickstarts.rshelloworld.HelloWorld",
|
||||
"methods":["getHelloWorldJSON"]
|
||||
},
|
||||
{
|
||||
"class": "org.jboss.as.quickstarts.rshelloworld.HelloWorld",
|
||||
"methods":["getHelloWorldXML"]
|
||||
},
|
||||
{
|
||||
"class": "org.jboss.as.quickstarts.rshelloworld.HelloService",
|
||||
"methods":["createHelloMessage"]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"instrument":[
|
||||
{
|
||||
"class": "org.jboss.as.quickstarts.rshelloworld.HelloService",
|
||||
"methods":["createHelloMessage"],
|
||||
"adviceClass":"com.example.AdviceCommandExecuter"
|
||||
},
|
||||
{
|
||||
"class": "org.jboss.as.quickstarts.helloworld.HelloWorldServlet",
|
||||
"methods":["doGet"],
|
||||
"adviceClass":"com.example.AdviceRestServlet"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,246 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>agent_loader_test</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<junit.version>5.6.0</junit.version>
|
||||
<maven-enforcer-plugin.version>3.0.0-M3</maven-enforcer-plugin.version>
|
||||
<maven-checkstyle-plugin.version>3.1.2</maven-checkstyle-plugin.version>
|
||||
<checkstyle.version>8.45.1</checkstyle.version>
|
||||
<maven-surefire-plugin.version>3.0.0-M5</maven-surefire-plugin.version>
|
||||
<jacoco-maven-plugin.version>0.8.4</jacoco-maven-plugin.version>
|
||||
<maven-javadoc-plugin.version>3.0.0</maven-javadoc-plugin.version>
|
||||
<!-- JaCoCo thresholds. Increase gradually as you add tests. -->
|
||||
<jacoco.unit-tests.limit.instruction-ratio>0%</jacoco.unit-tests.limit.instruction-ratio>
|
||||
<jacoco.unit-tests.limit.branch-ratio>0%</jacoco.unit-tests.limit.branch-ratio>
|
||||
<jacoco.unit-tests.limit.class-complexity>20</jacoco.unit-tests.limit.class-complexity>
|
||||
<jacoco.unit-tests.limit.method-complexity>5</jacoco.unit-tests.limit.method-complexity>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>commons-cli</groupId>
|
||||
<artifactId>commons-cli</artifactId>
|
||||
<version>1.5.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun</groupId>
|
||||
<artifactId>tools</artifactId>
|
||||
<version>1.8</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>C:\Program Files\Java\jdk1.8.0_291\lib\tools.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-dependencies</id>
|
||||
<phase>prepare-package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
|
||||
<configuration>
|
||||
<includeScope>compile</includeScope>
|
||||
<outputDirectory>
|
||||
${project.build.directory}/libs
|
||||
</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<addClasspath>true</addClasspath>
|
||||
<classpathPrefix>libs/</classpathPrefix>
|
||||
<mainClass>com.example.App</mainClass>
|
||||
</manifest>
|
||||
<manifestEntries>
|
||||
<Class-Path>libs/tools-1.8.jar</Class-Path>
|
||||
</manifestEntries>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-enforcer-plugin</artifactId>
|
||||
<version>${maven-enforcer-plugin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>enforce</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<rules>
|
||||
<requireMavenVersion>
|
||||
<version>3.6.3</version>
|
||||
</requireMavenVersion>
|
||||
</rules>
|
||||
<fail>true</fail>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>3.3.0</version>
|
||||
<configuration>
|
||||
<descriptors>
|
||||
<descriptor>src/assembly/dep.xml</descriptor>
|
||||
</descriptors>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>create-archive</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- <plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
<version>${maven-checkstyle-plugin.version}</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.puppycrawl.tools</groupId>
|
||||
<artifactId>checkstyle</artifactId>
|
||||
<version>${checkstyle.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.ngeor</groupId>
|
||||
<artifactId>checkstyle-rules</artifactId>
|
||||
<version>4.9.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<configuration>
|
||||
<configLocation>com/github/ngeor/checkstyle.xml</configLocation>
|
||||
<includeTestSourceDirectory>true</includeTestSourceDirectory>
|
||||
<skip>${skipTests}</skip>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>checkstyle</id>
|
||||
<phase>validate</phase>
|
||||
<goals>
|
||||
<goal>check</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin> -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${maven-surefire-plugin.version}</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<version>${jacoco-maven-plugin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>pre-unit-test</id>
|
||||
<goals>
|
||||
<goal>prepare-agent</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>post-unit-test</id>
|
||||
<phase>test</phase>
|
||||
<goals>
|
||||
<goal>report</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>check-unit-test</id>
|
||||
<phase>test</phase>
|
||||
<goals>
|
||||
<goal>check</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<dataFile>${project.build.directory}/jacoco.exec</dataFile>
|
||||
<rules>
|
||||
<rule>
|
||||
<element>BUNDLE</element>
|
||||
<limits>
|
||||
<limit>
|
||||
<counter>INSTRUCTION</counter>
|
||||
<value>COVEREDRATIO</value>
|
||||
<minimum>${jacoco.unit-tests.limit.instruction-ratio}</minimum>
|
||||
</limit>
|
||||
<limit>
|
||||
<counter>BRANCH</counter>
|
||||
<value>COVEREDRATIO</value>
|
||||
<minimum>${jacoco.unit-tests.limit.branch-ratio}</minimum>
|
||||
</limit>
|
||||
</limits>
|
||||
</rule>
|
||||
<rule>
|
||||
<element>CLASS</element>
|
||||
<limits>
|
||||
<limit>
|
||||
<counter>COMPLEXITY</counter>
|
||||
<value>TOTALCOUNT</value>
|
||||
<maximum>${jacoco.unit-tests.limit.class-complexity}</maximum>
|
||||
</limit>
|
||||
</limits>
|
||||
</rule>
|
||||
<rule>
|
||||
<element>METHOD</element>
|
||||
<limits>
|
||||
<limit>
|
||||
<counter>COMPLEXITY</counter>
|
||||
<value>TOTALCOUNT</value>
|
||||
<maximum>${jacoco.unit-tests.limit.method-complexity}</maximum>
|
||||
</limit>
|
||||
</limits>
|
||||
</rule>
|
||||
</rules>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<reporting>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>${maven-javadoc-plugin.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</reporting>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
|
||||
<id>bin</id>
|
||||
<formats>
|
||||
<format>zip</format>
|
||||
</formats>
|
||||
<fileSets>
|
||||
<fileSet>
|
||||
<directory>${project.basedir}</directory>
|
||||
<outputDirectory>/</outputDirectory>
|
||||
<includes>
|
||||
<include>README*</include>
|
||||
<include>LICENSE*</include>
|
||||
<include>NOTICE*</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
<fileSet>
|
||||
<directory>${project.build.directory}</directory>
|
||||
<outputDirectory>/</outputDirectory>
|
||||
<includes>
|
||||
<include>*.jar</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
<fileSet>
|
||||
<directory>${project.basedir}/config</directory>
|
||||
<outputDirectory>/</outputDirectory>
|
||||
<includes>
|
||||
<include>*.json</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
<fileSet>
|
||||
<directory>C:\Users\wiegee\Documents\NetBeansProjects\JavaAgentTest\agent_test\target</directory>
|
||||
<outputDirectory>libs</outputDirectory>
|
||||
<includes>
|
||||
<include>agent_test-1.0-SNAPSHOT.jar</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
<fileSet>
|
||||
<directory>${project.build.directory}/libs</directory>
|
||||
<outputDirectory>libs</outputDirectory>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</assembly>
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
package com.example;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.CommandLineParser;
|
||||
import org.apache.commons.cli.DefaultParser;
|
||||
import org.apache.commons.cli.Option;
|
||||
import org.apache.commons.cli.Options;
|
||||
import org.apache.commons.cli.ParseException;
|
||||
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
|
||||
/**
|
||||
* Hello world!
|
||||
*/
|
||||
public final class App {
|
||||
private App() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Says hello to the world.
|
||||
*
|
||||
* @param args The arguments of the program.
|
||||
* @throws ParseException
|
||||
*/
|
||||
public static void main(String[] args) throws ParseException {
|
||||
Options options = new Options();
|
||||
Option processId = Option.builder("p")
|
||||
.longOpt("processId")
|
||||
.required(true)
|
||||
.hasArg()
|
||||
.desc("process id java agent is attached to")
|
||||
.build();
|
||||
|
||||
Option configFile = Option.builder("c")
|
||||
.longOpt("configFile")
|
||||
.required(true)
|
||||
.hasArg()
|
||||
.desc("config File pfad")
|
||||
.build();
|
||||
|
||||
options.addOption(processId);
|
||||
options.addOption(configFile);
|
||||
CommandLineParser parser = new DefaultParser();
|
||||
CommandLine cmd = parser.parse(options, args);
|
||||
|
||||
JSONParser jsonParser = new JSONParser();
|
||||
JSONObject jsonparams=null;
|
||||
// cmd.getOptionValue("processId");
|
||||
try (FileReader reader = new FileReader(cmd.getOptionValue("configFile"))) {
|
||||
jsonparams = (JSONObject) jsonParser.parse(reader);
|
||||
// JSONObject instrumentation = (JSONObject) ((JSONArray) jsonparams.get("instrument")).get(0);
|
||||
|
||||
// for (int i = 0; i < instrumentation.size(); i++) {
|
||||
|
||||
// }
|
||||
|
||||
MyJavaAgentLoader.loadAgent(cmd.getOptionValue("processId"), jsonparams.toString());
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (org.json.simple.parser.ParseException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package com.example;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.management.ManagementFactory;
|
||||
|
||||
import com.sun.tools.attach.VirtualMachine;
|
||||
|
||||
public class MyJavaAgentLoader {
|
||||
|
||||
//static final Logger logger = LoggerFactory.getLogger(MyJavaAgentLoader.class);
|
||||
|
||||
//private static final String jarFilePath = "C:\\Users\\wiegee\\Documents\\NetBeansProjects\\JavaAgentTest\\agent_test\\target\\agent_test-1.0-SNAPSHOT.jar";
|
||||
private static final String jarFilePath = new File("libs\\agent_test-1.0-SNAPSHOT.jar").getAbsolutePath();
|
||||
|
||||
public static void loadAgent(String processId, String jsonparams) {
|
||||
|
||||
String nameOfRunningVM = ManagementFactory.getRuntimeMXBean().getName();
|
||||
int p = nameOfRunningVM.indexOf('@');
|
||||
//String pid = nameOfRunningVM.substring(0, p);
|
||||
|
||||
try {
|
||||
System.out.println("test123");
|
||||
VirtualMachine vm = VirtualMachine.attach(processId);
|
||||
|
||||
vm.loadAgent(jarFilePath, jsonparams);
|
||||
|
||||
vm.detach();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package com.example;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Unit test for simple App.
|
||||
*/
|
||||
class AppTest {
|
||||
/**
|
||||
* Rigorous Test.
|
||||
*/
|
||||
@Test
|
||||
void testApp() {
|
||||
assertEquals(1, 1);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
##############################
|
||||
## Java
|
||||
##############################
|
||||
.mtj.tmp/
|
||||
*.class
|
||||
*.jar
|
||||
*.war
|
||||
*.ear
|
||||
*.nar
|
||||
hs_err_pid*
|
||||
replay_pid*
|
||||
|
||||
##############################
|
||||
## Maven
|
||||
##############################
|
||||
target/
|
||||
pom.xml.tag
|
||||
pom.xml.releaseBackup
|
||||
pom.xml.versionsBackup
|
||||
pom.xml.next
|
||||
pom.xml.bak
|
||||
release.properties
|
||||
dependency-reduced-pom.xml
|
||||
buildNumber.properties
|
||||
.mvn/timing.properties
|
||||
.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
##############################
|
||||
## Gradle
|
||||
##############################
|
||||
bin/
|
||||
build/
|
||||
.gradle
|
||||
.gradletasknamecache
|
||||
gradle-app.setting
|
||||
!gradle-wrapper.jar
|
||||
|
||||
##############################
|
||||
## IntelliJ
|
||||
##############################
|
||||
out/
|
||||
.idea/
|
||||
.idea_modules/
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
|
||||
##############################
|
||||
## Eclipse
|
||||
##############################
|
||||
.settings/
|
||||
bin/
|
||||
tmp/
|
||||
.metadata
|
||||
.classpath
|
||||
.project
|
||||
*.tmp
|
||||
*.bak
|
||||
*.swp
|
||||
*~.nib
|
||||
local.properties
|
||||
.loadpath
|
||||
.factorypath
|
||||
|
||||
##############################
|
||||
## NetBeans
|
||||
##############################
|
||||
nbproject/private/
|
||||
build/
|
||||
nbbuild/
|
||||
dist/
|
||||
nbdist/
|
||||
nbactions.xml
|
||||
nb-configuration.xml
|
||||
|
||||
##############################
|
||||
## Visual Studio Code
|
||||
##############################
|
||||
.vscode/
|
||||
.code-workspace
|
||||
|
||||
##############################
|
||||
## OS X
|
||||
##############################
|
||||
.DS_Store
|
||||
|
||||
##############################
|
||||
## Miscellaneous
|
||||
##############################
|
||||
*.log
|
||||
|
|
@ -0,0 +1,128 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>agent_test</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<name>agent_test</name>
|
||||
<!-- FIXME change it to the project's website -->
|
||||
<url>http://www.example.com</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
<version>2.5</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.adobe</groupId>
|
||||
<artifactId>adobe-wkf</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>C:\Users\wiegee\Documents\adobe-AEMForms-libs\adobe-wkf.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.adobe</groupId>
|
||||
<artifactId>adobe-dscf-client</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>C:\Users\wiegee\Documents\adobe-AEMForms-libs\adobe-dscf-client.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.adobe</groupId>
|
||||
<artifactId>adobe-dscf</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>C:\Users\wiegee\Documents\adobe-AEMForms-libs\adobe-dscf.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.bytebuddy</groupId>
|
||||
<artifactId>byte-buddy</artifactId>
|
||||
<version>1.11.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.dynatrace.oneagent.sdk.java</groupId>
|
||||
<artifactId>oneagent-sdk</artifactId>
|
||||
<version>1.9.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpcore</artifactId>
|
||||
<version>4.4.16</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpasyncclient</artifactId>
|
||||
<version>4.1.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents.client5</groupId>
|
||||
<artifactId>httpclient5</artifactId>
|
||||
<version>5.3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.10.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<transformers>
|
||||
<transformer
|
||||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<manifestEntries>
|
||||
<Premain-Class>com.example.Agent</Premain-Class>
|
||||
<Main-Class>com.example.Agent</Main-Class>
|
||||
<Agent-Class>com.example.Agent</Agent-Class>
|
||||
<Can-Redefine-Classes>true</Can-Redefine-Classes>
|
||||
<Can-Retransform-Classes>true</Can-Retransform-Classes>
|
||||
</manifestEntries>
|
||||
</transformer>
|
||||
</transformers>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- clean lifecycle, see
|
||||
https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,160 @@
|
|||
package com.example;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
//import java.io.Console;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.adobe.workflow.engine.PEInvokeProcessCommand;
|
||||
import com.dynatrace.oneagent.sdk.OneAgentSDKFactory;
|
||||
import com.dynatrace.oneagent.sdk.api.OneAgentSDK;
|
||||
import net.bytebuddy.asm.*;
|
||||
import net.bytebuddy.asm.Advice.FieldValue;
|
||||
import net.bytebuddy.implementation.bytecode.assign.Assigner.Typing;
|
||||
|
||||
public class AdviceCommandExecuter {
|
||||
// @Advice.AllArguments Object[] args,
|
||||
@Advice.OnMethodEnter
|
||||
static AdviceResponse invokeBeforeEnterMethod(@Advice.AllArguments Object[] args,
|
||||
@Advice.Origin String method, @FieldValue(value = "m_command", typing = Typing.DYNAMIC) Object m_command) {
|
||||
|
||||
String uniqueID = UUID.randomUUID().toString();
|
||||
long currentTimeStamp = System.currentTimeMillis();
|
||||
String workflow = "";
|
||||
|
||||
Date date = new Date(currentTimeStamp);
|
||||
DateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.mmm'Z'");
|
||||
String dateTxT = f.format(date);
|
||||
|
||||
try {
|
||||
|
||||
if (m_command != null) {
|
||||
workflow = ((PEInvokeProcessCommand) m_command).getInvocationInfo().getProcessTypeId();
|
||||
}
|
||||
|
||||
workflow = workflow.replace(" ", "_");
|
||||
|
||||
System.out.println("Printing Methods args: ");
|
||||
for (Object obj : args) {
|
||||
System.out.println(obj.toString());
|
||||
}
|
||||
|
||||
// Timestamp Start
|
||||
|
||||
OneAgentSDK oneAgentSdk = OneAgentSDKFactory.createInstance();
|
||||
oneAgentSdk.addCustomRequestAttribute("method_start_time", currentTimeStamp);
|
||||
|
||||
String thread_name = Thread.currentThread().getName().replace(" ", "_");
|
||||
oneAgentSdk.addCustomRequestAttribute("thread_name", thread_name);
|
||||
|
||||
StringBuilder m_duration = new StringBuilder("nttdata.aemforms.workflow.duration");
|
||||
StringBuilder m_starttime = new StringBuilder("nttdata.aemforms.workflow.starttime");
|
||||
|
||||
if (uniqueID != null) {
|
||||
m_duration.append(",uuid=");
|
||||
m_duration.append(uniqueID);
|
||||
m_starttime.append(",uuid=");
|
||||
m_starttime.append(uniqueID);
|
||||
}
|
||||
if (thread_name != null) {
|
||||
m_duration.append(",threadname=");
|
||||
m_duration.append(thread_name);
|
||||
m_starttime.append(",threadname=");
|
||||
m_starttime.append(thread_name);
|
||||
}
|
||||
if (method != null) {
|
||||
m_duration.append(",method=");
|
||||
m_duration.append(method.replace(" ", "_"));
|
||||
m_starttime.append(",method=");
|
||||
m_starttime.append(method.replace(" ", "_"));
|
||||
}
|
||||
if (dateTxT != null) {
|
||||
m_duration.append(",startdate=");
|
||||
m_duration.append(dateTxT);
|
||||
m_starttime.append(",startdate=");
|
||||
m_starttime.append(dateTxT);
|
||||
}
|
||||
if (workflow != null) {
|
||||
m_duration.append(",workflow=");
|
||||
m_duration.append(workflow);
|
||||
m_starttime.append(",workflow=");
|
||||
m_starttime.append(workflow);
|
||||
}
|
||||
m_duration.append(" 0");
|
||||
m_starttime.append(" ");
|
||||
m_starttime.append(currentTimeStamp);
|
||||
|
||||
System.out.println("Metric duration: " + m_duration.toString());
|
||||
System.out.println("Metric starttime: " + m_starttime.toString());
|
||||
|
||||
OneAgentMetricWriter.getInstance().writeMetric(m_duration.toString());
|
||||
OneAgentMetricWriter.getInstance().writeMetric(m_starttime.toString());
|
||||
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Exception occured during call Oneagent SDK" +
|
||||
ex.getMessage());
|
||||
}
|
||||
|
||||
return new AdviceResponse(currentTimeStamp, uniqueID, workflow, dateTxT);
|
||||
|
||||
}
|
||||
|
||||
@Advice.OnMethodExit(onThrowable=Throwable.class)
|
||||
static void invokeAfterExitMethod(
|
||||
@Advice.Origin String method,
|
||||
@Advice.Enter AdviceResponse adviceResponse) {
|
||||
|
||||
if (adviceResponse != null) {
|
||||
long currentTimeStamp = System.currentTimeMillis();
|
||||
long duration = (currentTimeStamp - adviceResponse.startTime);
|
||||
|
||||
// // WRITE METRIC
|
||||
String thread_name = Thread.currentThread().getName().replace(" ", "_");
|
||||
|
||||
StringBuilder m_duration = new StringBuilder("nttdata.aemforms.workflow.duration");
|
||||
StringBuilder m_endtime = new StringBuilder("nttdata.aemforms.workflow.endtime");
|
||||
|
||||
if (adviceResponse.uniqueID != null) {
|
||||
m_duration.append(",uuid=");
|
||||
m_duration.append(adviceResponse.uniqueID);
|
||||
m_endtime.append(",uuid=");
|
||||
m_endtime.append(adviceResponse.uniqueID);
|
||||
}
|
||||
if (thread_name != null) {
|
||||
m_duration.append(",threadname=");
|
||||
m_duration.append(thread_name);
|
||||
m_endtime.append(",threadname=");
|
||||
m_endtime.append(thread_name);
|
||||
}
|
||||
if (method != null) {
|
||||
m_duration.append(",method=");
|
||||
m_duration.append(method.replace(" ", "_"));
|
||||
m_endtime.append(",method=");
|
||||
m_endtime.append(method.replace(" ", "_"));
|
||||
}
|
||||
if (adviceResponse.startDate != null) {
|
||||
m_duration.append(",startdate=");
|
||||
m_duration.append(adviceResponse.startDate);
|
||||
m_endtime.append(",startdate=");
|
||||
m_endtime.append(adviceResponse.startDate);
|
||||
}
|
||||
if (adviceResponse.workflow != null) {
|
||||
m_duration.append(",workflow=");
|
||||
m_duration.append(adviceResponse.workflow);
|
||||
m_endtime.append(",workflow=");
|
||||
m_endtime.append(adviceResponse.workflow);
|
||||
}
|
||||
m_duration.append(" ");
|
||||
m_duration.append(duration);
|
||||
m_endtime.append(" ");
|
||||
m_endtime.append(currentTimeStamp);
|
||||
|
||||
System.out.println("Metric duration: " + m_duration.toString());
|
||||
System.out.println("Metric endtime: " + m_endtime.toString());
|
||||
|
||||
OneAgentMetricWriter.getInstance().writeMetric(m_duration.toString());
|
||||
OneAgentMetricWriter.getInstance().writeMetric(m_endtime.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package com.example;
|
||||
|
||||
public class AdviceResponse {
|
||||
public long startTime;
|
||||
public String uniqueID;
|
||||
public String workflow;
|
||||
public String startDate;
|
||||
|
||||
public AdviceResponse(long startTime, String uniqueID, String workflow, String startDate) {
|
||||
this.startTime=startTime;
|
||||
this.uniqueID=uniqueID;
|
||||
this.workflow=workflow;
|
||||
this.startDate=startDate;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,205 @@
|
|||
package com.example;
|
||||
|
||||
import java.net.URLDecoder;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import net.bytebuddy.asm.*;
|
||||
|
||||
public class AdviceRestServlet {
|
||||
@Advice.OnMethodEnter
|
||||
static AdviceResponse invokeBeforeEnterMethod(@Advice.AllArguments Object[] args,
|
||||
@Advice.Origin String method) {
|
||||
|
||||
String SYNC_INVOKE = "services/";
|
||||
try {
|
||||
|
||||
HttpServletRequest req = (HttpServletRequest) args[0];
|
||||
String uri = req.getRequestURI();
|
||||
uri = URLDecoder.decode(uri);
|
||||
|
||||
if (uri.endsWith(".xml"))
|
||||
return null;
|
||||
|
||||
if (uri.endsWith(".json"))
|
||||
return null;
|
||||
|
||||
if (!uri.startsWith("/rest/"))
|
||||
return null;
|
||||
|
||||
uri = uri.substring(6);
|
||||
|
||||
if (!uri.startsWith(SYNC_INVOKE))
|
||||
return null;
|
||||
|
||||
uri = uri.substring(SYNC_INVOKE.length());
|
||||
|
||||
int dotPos = uri.indexOf(46);
|
||||
int suffixPos = uri.indexOf(47, dotPos);
|
||||
if (dotPos >= 0 && suffixPos > dotPos) {
|
||||
uri = uri.substring(0, suffixPos);
|
||||
}
|
||||
|
||||
int majorVersion = 0;
|
||||
int minorVersion = 0;
|
||||
String version = null;
|
||||
int colonPos = uri.lastIndexOf(58);
|
||||
if (colonPos >= 0) {
|
||||
version = uri.substring(colonPos + 1);
|
||||
uri = uri.substring(0, colonPos);
|
||||
|
||||
try {
|
||||
String[] nums = version.split("\\.");
|
||||
if (nums.length != 2) {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
majorVersion = Integer.parseInt(nums[0]);
|
||||
minorVersion = Integer.parseInt(nums[1]);
|
||||
} catch (Throwable var25) {
|
||||
throw new Exception("The version part of the URL should follow <major>.<minor> format.");
|
||||
}
|
||||
}
|
||||
|
||||
dotPos = uri.lastIndexOf(46);
|
||||
String operationName;
|
||||
if (dotPos >= 0) {
|
||||
operationName = uri.substring(dotPos + 1);
|
||||
uri = uri.substring(0, dotPos);
|
||||
} else {
|
||||
operationName = "invoke";
|
||||
}
|
||||
|
||||
if (operationName != "invoke")
|
||||
return null;
|
||||
|
||||
String uniqueID = UUID.randomUUID().toString();
|
||||
long currentTimeStamp = System.currentTimeMillis();
|
||||
|
||||
Date date=new Date(currentTimeStamp);
|
||||
DateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.mmm'Z'");
|
||||
String dateTxT=f.format(date);
|
||||
|
||||
|
||||
String workflow = uri.replace(" ", "_");
|
||||
String thread_name = Thread.currentThread().getName().replace(" ", "_");
|
||||
|
||||
StringBuilder m_duration = new StringBuilder("nttdata.aemforms.workflow.duration");
|
||||
StringBuilder m_starttime = new StringBuilder("nttdata.aemforms.workflow.starttime");
|
||||
|
||||
if (uniqueID != null) {
|
||||
m_duration.append(",uuid=");
|
||||
m_duration.append(uniqueID);
|
||||
m_starttime.append(",uuid=");
|
||||
m_starttime.append(uniqueID);
|
||||
}
|
||||
if (thread_name != null) {
|
||||
m_duration.append(",threadname=");
|
||||
m_duration.append(thread_name);
|
||||
m_starttime.append(",threadname=");
|
||||
m_starttime.append(thread_name);
|
||||
}
|
||||
if (method != null) {
|
||||
m_duration.append(",method=");
|
||||
m_duration.append(method.replace(" ", "_").replace(",","_"));
|
||||
m_starttime.append(",method=");
|
||||
m_starttime.append(method.replace(" ", "_").replace(",","_"));
|
||||
}
|
||||
if (dateTxT != null) {
|
||||
m_duration.append(",startdate=");
|
||||
m_duration.append(dateTxT);
|
||||
m_starttime.append(",startdate=");
|
||||
m_starttime.append(dateTxT);
|
||||
}
|
||||
if (workflow != null) {
|
||||
m_duration.append(",workflow=");
|
||||
m_duration.append(workflow);
|
||||
m_starttime.append(",workflow=");
|
||||
m_starttime.append(workflow);
|
||||
}
|
||||
m_duration.append(" 0");
|
||||
m_starttime.append(" ");
|
||||
m_starttime.append(currentTimeStamp);
|
||||
|
||||
System.out.println(m_duration);
|
||||
System.out.println(m_starttime);
|
||||
|
||||
OneAgentMetricWriter.getInstance().writeMetric(m_duration.toString());
|
||||
OneAgentMetricWriter.getInstance().writeMetric(m_starttime.toString());
|
||||
|
||||
return new AdviceResponse(currentTimeStamp, uniqueID, workflow, dateTxT);
|
||||
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Exception occured: " + ex.getMessage());
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
// (onThrowable=Throwable.class)
|
||||
|
||||
@Advice.OnMethodExit(onThrowable=Throwable.class)
|
||||
static void invokeAfterExitMethod(
|
||||
@Advice.Origin String method,
|
||||
@Advice.Enter AdviceResponse adviceResponse) {
|
||||
|
||||
|
||||
if (adviceResponse != null) {
|
||||
long currentTimeStamp = System.currentTimeMillis();
|
||||
long duration = (currentTimeStamp - adviceResponse.startTime);
|
||||
|
||||
// // WRITE METRIC
|
||||
String thread_name = Thread.currentThread().getName().replace(" ", "_");
|
||||
|
||||
StringBuilder m_duration = new StringBuilder("nttdata.aemforms.workflow.duration");
|
||||
StringBuilder m_endtime = new StringBuilder("nttdata.aemforms.workflow.endtime");
|
||||
|
||||
if (adviceResponse.uniqueID != null) {
|
||||
m_duration.append(",uuid=");
|
||||
m_duration.append(adviceResponse.uniqueID);
|
||||
m_endtime.append(",uuid=");
|
||||
m_endtime.append(adviceResponse.uniqueID);
|
||||
}
|
||||
if (thread_name != null) {
|
||||
m_duration.append(",threadname=");
|
||||
m_duration.append(thread_name);
|
||||
m_endtime.append(",threadname=");
|
||||
m_endtime.append(thread_name);
|
||||
}
|
||||
if (method != null) {
|
||||
m_duration.append(",method=");
|
||||
m_duration.append(method.replace(" ", "_").replace(",","_"));
|
||||
m_endtime.append(",method=");
|
||||
m_endtime.append(method.replace(" ", "_").replace(",","_"));
|
||||
}
|
||||
if (adviceResponse.startDate != null) {
|
||||
m_duration.append(",startdate=");
|
||||
m_duration.append(adviceResponse.startDate);
|
||||
m_endtime.append(",startdate=");
|
||||
m_endtime.append(adviceResponse.startDate);
|
||||
}
|
||||
if (adviceResponse.workflow != null) {
|
||||
m_duration.append(",workflow=");
|
||||
m_duration.append(adviceResponse.workflow);
|
||||
m_endtime.append(",workflow=");
|
||||
m_endtime.append(adviceResponse.workflow);
|
||||
}
|
||||
|
||||
m_duration.append(" ");
|
||||
m_duration.append(duration);
|
||||
m_endtime.append(" ");
|
||||
m_endtime.append(currentTimeStamp);
|
||||
|
||||
System.out.println("Metric duration: " + m_duration.toString());
|
||||
System.out.println("Metric endtime: " + m_endtime.toString());
|
||||
|
||||
OneAgentMetricWriter.getInstance().writeMetric(m_duration.toString());
|
||||
OneAgentMetricWriter.getInstance().writeMetric(m_endtime.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,255 @@
|
|||
package com.example;
|
||||
|
||||
import com.adobe.idp.dsc.InvocationRequest;
|
||||
import com.adobe.idp.dsc.engine.impl.ServiceEngineImpl;
|
||||
import com.adobe.idp.dsc.impl.InvocationRequestImpl;
|
||||
import com.adobe.idp.dsc.registry.infomodel.Operation;
|
||||
import com.adobe.idp.dsc.registry.infomodel.ServiceConfiguration;
|
||||
|
||||
//import java.io.Console;
|
||||
// import java.util.UUID;
|
||||
|
||||
// import com.adobe.workflow.engine.PEInvokeProcessCommand;
|
||||
// import com.dynatrace.oneagent.sdk.OneAgentSDKFactory;
|
||||
// import com.dynatrace.oneagent.sdk.api.OneAgentSDK;
|
||||
import net.bytebuddy.asm.*;
|
||||
// import net.bytebuddy.asm.Advice.FieldValue;
|
||||
// import net.bytebuddy.implementation.bytecode.assign.Assigner.Typing;
|
||||
|
||||
public class AdviceRouter {
|
||||
// @Advice.AllArguments Object[] args,
|
||||
@Advice.OnMethodEnter
|
||||
static void invokeBeforeEnterMethod(@Advice.AllArguments Object[] args,
|
||||
@Advice.Origin String method) {
|
||||
|
||||
try {
|
||||
|
||||
System.out.println("");
|
||||
System.out.println("");
|
||||
System.out.println("################################## START router call #################################");
|
||||
InvocationRequest aRequest=(InvocationRequest)args[0];
|
||||
InvocationRequestImpl _request = (InvocationRequestImpl)aRequest;
|
||||
|
||||
String _endpointId = (String)_request.getProperty("ENDPOINT_PUBLIC_ID");
|
||||
String _connectorId = (String)_request.getProperty("CONNECTOR_ID");
|
||||
|
||||
if(_endpointId!= null)
|
||||
System.out.println("endpointId: "+_endpointId);
|
||||
if(_connectorId!= null)
|
||||
System.out.println("connectorId: "+_connectorId);
|
||||
|
||||
|
||||
if(_request.getInvocationId()!=null)
|
||||
System.out.println("_request.innvocationId: "+_request.getInvocationId());
|
||||
if(_request.getOperationName()!=null)
|
||||
System.out.println("_request.operation.name: "+_request.getOperationName());
|
||||
if(_request.getServiceName()!=null)
|
||||
System.out.println("_request.service.name: "+_request.getServiceName());
|
||||
if(_request.getEndPointURI()!=null)
|
||||
System.out.println("_request.endpointURI: "+_request.getEndPointURI());
|
||||
|
||||
ServiceConfiguration _config = _request.getTargetServiceConfiguration();
|
||||
if (_config == null) {
|
||||
_config = ServiceEngineImpl.resolveConfiguration(aRequest.getServiceName(), aRequest.getServiceExplicitVersion(), aRequest.getServiceOriginalVersion());
|
||||
_request.setTargetServiceConfiguration(_config);
|
||||
}
|
||||
|
||||
Operation _operation = _config.getOperation(aRequest.getOperationName());
|
||||
Boolean longLivedInvokeExists = (Boolean)aRequest.getProperty("long-lived-invoke");
|
||||
if (longLivedInvokeExists == null) {
|
||||
longLivedInvokeExists = new Boolean(false);
|
||||
}
|
||||
|
||||
|
||||
if(_operation.getName()!=null)
|
||||
System.out.println("operation.name: "+_operation.getName());
|
||||
|
||||
if(_operation.getServiceId()!=null)
|
||||
System.out.println("operation.serviceId: "+_operation.getServiceId());
|
||||
|
||||
if(_operation.getTitle()!=null)
|
||||
System.out.println("operation.title: "+_operation.getTitle());
|
||||
|
||||
|
||||
if(_config.getComponentId()!=null)
|
||||
System.out.println("config.componentId: "+_config.getComponentId());
|
||||
if(_config.getServiceId()!=null)
|
||||
System.out.println("config.serviceId: "+_config.getServiceId());
|
||||
if(_config.getType()!=null)
|
||||
System.out.println("config.type: "+_config.getType());
|
||||
if(_config.getTitle()!=null)
|
||||
System.out.println("config.type: "+_config.getTitle());
|
||||
|
||||
|
||||
System.out.println("################################## END router call #################################");
|
||||
System.out.println("");
|
||||
System.out.println("");
|
||||
|
||||
|
||||
}catch(Exception ex) {
|
||||
System.out.println("Exception occured: "+ex.getMessage());
|
||||
}
|
||||
// String uniqueID = UUID.randomUUID().toString();
|
||||
// long currentTimeStamp = System.currentTimeMillis();
|
||||
// String workflow = "";
|
||||
|
||||
// try {
|
||||
|
||||
// if(m_command != null) {
|
||||
// workflow =((PEInvokeProcessCommand)m_command).getInvocationInfo().getProcessTypeId();
|
||||
// //System.out.println("Workflow: "+ workflow);
|
||||
// }
|
||||
|
||||
// //workflow = "test-test123";
|
||||
// workflow=workflow.replace(" ", "_");
|
||||
|
||||
// // System.out.println("Test STR Private variable: "+
|
||||
// // ((JsonObject)testStr).get("name"));
|
||||
// System.out.println("Printing Methods args: ");
|
||||
// for (Object obj : args) {
|
||||
// System.out.println(obj.toString());
|
||||
// }
|
||||
|
||||
|
||||
// // Timestamp Start
|
||||
|
||||
// OneAgentSDK oneAgentSdk = OneAgentSDKFactory.createInstance();
|
||||
// oneAgentSdk.addCustomRequestAttribute("method_start_time", currentTimeStamp);
|
||||
|
||||
// // RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();
|
||||
// // String jvmName = bean.getName();
|
||||
// // System.out.println("Name = " + jvmName);
|
||||
|
||||
// // System.out.println("Method invoked before enter method by: " + method);
|
||||
|
||||
// String thread_name = Thread.currentThread().getName().replace(" ", "_");
|
||||
// oneAgentSdk.addCustomRequestAttribute("thread_name", thread_name);
|
||||
|
||||
// StringBuilder m_duration = new StringBuilder("nttdata.aemforms.workflow.duration");
|
||||
// StringBuilder m_starttime = new StringBuilder("nttdata.aemforms.workflow.starttime");
|
||||
|
||||
// if (uniqueID!= null) {
|
||||
// m_duration.append(",uuid=");
|
||||
// m_duration.append(uniqueID);
|
||||
// m_starttime.append(",uuid=");
|
||||
// m_starttime.append(uniqueID);
|
||||
// }
|
||||
// if (thread_name != null) {
|
||||
// m_duration.append(",threadname=");
|
||||
// m_duration.append(thread_name);
|
||||
// m_starttime.append(",threadname=");
|
||||
// m_starttime.append(thread_name);
|
||||
// }
|
||||
// if (method != null) {
|
||||
// m_duration.append(",method=");
|
||||
// m_duration.append(method.replace(" ", "_"));
|
||||
// m_starttime.append(",method=");
|
||||
// m_starttime.append(method.replace(" ", "_"));
|
||||
// }
|
||||
// if (workflow != null) {
|
||||
// m_duration.append(",workflow=");
|
||||
// m_duration.append(workflow);
|
||||
// m_starttime.append(",workflow=");
|
||||
// m_starttime.append(workflow);
|
||||
// }
|
||||
// m_duration.append(" 0");
|
||||
// m_starttime.append(" ");
|
||||
// m_starttime.append(currentTimeStamp);
|
||||
|
||||
// // // SEND METRIC ############################
|
||||
// // // String m_duration = "nttdata.aemforms.workflow.duration,uuid=" + uniqueID + ",threadname="
|
||||
// // // + thread_name.replace(" ", "_") + ",methode=" + method.replace(" ", "_") + ",workflow="
|
||||
// // // + workflow.replace(" ", "_") + " 0";
|
||||
// // // String m_starttime = "nttdata.aemforms.workflow.starttime,uuid=" + uniqueID + ",threadname="
|
||||
// // // + thread_name.replace(" ", "_") + ",methode=" + method.replace(" ", "_") + ",workflow="
|
||||
// // // + workflow.replace(" ", "_") + " " + currentTimeStamp;
|
||||
|
||||
// System.out.println("Metric duration: " + m_duration.toString());
|
||||
// System.out.println("Metric starttime: " + m_starttime.toString());
|
||||
|
||||
// OneAgentMetricWriter.getInstance().writeMetric(m_duration.toString());
|
||||
// OneAgentMetricWriter.getInstance().writeMetric(m_starttime.toString());
|
||||
|
||||
// } catch(Exception ex) {
|
||||
// System.out.println("Exception occured during call Oneagent SDK"+
|
||||
// ex.getMessage());
|
||||
// }
|
||||
|
||||
// return new AdviceResponse(currentTimeStamp, uniqueID, workflow);
|
||||
|
||||
}
|
||||
|
||||
// (onThrowable = Throwable.class)
|
||||
// @Advice.OnMethodExit
|
||||
// static void invokeAfterExitMethod(
|
||||
// @Advice.Origin String method,
|
||||
// @Advice.Enter AdviceResponse adviceResponse) {
|
||||
|
||||
// // OneAgentSDK oneAgentSdk = OneAgentSDKFactory.createInstance();
|
||||
// // oneAgentSdk.addCustomRequestAttribute("method_end_time",
|
||||
// // System.currentTimeMillis());
|
||||
|
||||
// if (adviceResponse != null) {
|
||||
// long currentTimeStamp = System.currentTimeMillis();
|
||||
// long duration = (currentTimeStamp - adviceResponse.startTime);
|
||||
// // System.out.println("Method " + method + " took " + duration + "ms");
|
||||
|
||||
// // // WRITE METRIC
|
||||
// String thread_name = Thread.currentThread().getName().replace(" ", "_");
|
||||
// //System.out.println(method);
|
||||
// //method = method.replace(" ", "_");
|
||||
|
||||
// StringBuilder m_duration = new StringBuilder("nttdata.aemforms.workflow.duration");
|
||||
// StringBuilder m_endtime = new StringBuilder("nttdata.aemforms.workflow.endtime");
|
||||
|
||||
// if (adviceResponse.uniqueID != null) {
|
||||
// m_duration.append(",uuid=");
|
||||
// m_duration.append(adviceResponse.uniqueID);
|
||||
// m_endtime.append(",uuid=");
|
||||
// m_endtime.append(adviceResponse.uniqueID);
|
||||
// }
|
||||
// if (thread_name != null) {
|
||||
// m_duration.append(",threadname=");
|
||||
// m_duration.append(thread_name);
|
||||
// m_endtime.append(",threadname=");
|
||||
// m_endtime.append(thread_name);
|
||||
// }
|
||||
// if (method != null) {
|
||||
// m_duration.append(",method=");
|
||||
// m_duration.append(method.replace(" ", "_"));
|
||||
// m_endtime.append(",method=");
|
||||
// m_endtime.append(method.replace(" ", "_"));
|
||||
// }
|
||||
// if (adviceResponse.workflow != null) {
|
||||
// m_duration.append(",workflow=");
|
||||
// m_duration.append(adviceResponse.workflow);
|
||||
// m_endtime.append(",workflow=");
|
||||
// m_endtime.append(adviceResponse.workflow);
|
||||
// }
|
||||
// m_duration.append(" ");
|
||||
// m_duration.append(duration);
|
||||
// m_endtime.append(" ");
|
||||
// m_endtime.append(currentTimeStamp);
|
||||
|
||||
// // String m_duration = "nttdata.aemforms.workflow.duration,uuid=" +
|
||||
// // adviceResponse.uniqueID + ",threadname="
|
||||
// // + thread_name.replace(" ", "_") + ",method=" + method.replace(" ", "_") +
|
||||
// // ",workflow="
|
||||
// // + adviceResponse.workflow.replace(" ", "_") + " " + duration;
|
||||
|
||||
// // String m_endtime = "nttdata.aemforms.workflow.endtime,uuid=" +
|
||||
// // adviceResponse.uniqueID + ",threadname="
|
||||
// // + thread_name.replace(" ", "_") + ",methode=" + method.replace(" ", "_") +
|
||||
// // ",workflow="
|
||||
// // + adviceResponse.workflow.replace(" ", "_") + " " + currentTimeStamp;
|
||||
|
||||
// System.out.println("Metric duration: " + m_duration.toString());
|
||||
// System.out.println("Metric endtime: " + m_endtime.toString());
|
||||
|
||||
// OneAgentMetricWriter.getInstance().writeMetric(m_duration.toString());
|
||||
// OneAgentMetricWriter.getInstance().writeMetric(m_endtime.toString());
|
||||
// } else {
|
||||
// System.out.println("AdviceResponse AfterExit is null");
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
|
@ -0,0 +1,151 @@
|
|||
package com.example;
|
||||
|
||||
import java.lang.instrument.Instrumentation;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
import org.json.simple.JSONArray;
|
||||
|
||||
|
||||
|
||||
import net.bytebuddy.agent.builder.AgentBuilder;
|
||||
import net.bytebuddy.agent.builder.ResettableClassFileTransformer;
|
||||
import net.bytebuddy.agent.builder.AgentBuilder.RedefinitionStrategy;
|
||||
import net.bytebuddy.asm.Advice;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
import net.bytebuddy.matcher.ElementMatchers;
|
||||
|
||||
class Agent {
|
||||
// public static void premain(String arguments, Instrumentation instrumentation) {
|
||||
// new AgentBuilder.Default()
|
||||
// .type(ElementMatchers.any())
|
||||
// .transform((builder, typeDescription, classLoader, module) -> builder
|
||||
// .method(ElementMatchers.nameContainsIgnoreCase("fetch"))
|
||||
// .intercept(Advice.to(DTAdvice.class)))
|
||||
// .installOn(instrumentation);
|
||||
// }
|
||||
|
||||
// public static void agentmain_BAK(String agentArgs, Instrumentation instrumentation) {
|
||||
|
||||
// System.out.println("attached dynamically witth parameeters: "+agentArgs);
|
||||
|
||||
// ElementMatcher.Junction matches = ElementMatchers.nameStartsWith("com.javadevelopersguide.jersey.resources");
|
||||
|
||||
// ResettableClassFileTransformer ab = new AgentBuilder.Default()
|
||||
// .disableClassFormatChanges()
|
||||
// .with(RedefinitionStrategy.RETRANSFORMATION)
|
||||
// .type(matches)
|
||||
// .transform((builder, typeDescription, classLoader, module) -> builder
|
||||
// //.method(ElementMatchers.nameContainsIgnoreCase("fetch"))
|
||||
// .visit(Advice.to(DTAdvice.class).on(ElementMatchers.nameContainsIgnoreCase("fetch"))))
|
||||
// .installOn(instrumentation);
|
||||
|
||||
|
||||
|
||||
// int x = 0;
|
||||
|
||||
// }
|
||||
|
||||
public static void agentmain(String agentArgs, Instrumentation instrumentation) {
|
||||
|
||||
System.out.println("attached dynamically witth parameeters 2: "+agentArgs);
|
||||
//String[] methods = {"fetchAll","create"};
|
||||
|
||||
JSONParser jsonParser = new JSONParser();
|
||||
JSONObject jsonparams=null;
|
||||
|
||||
try {
|
||||
jsonparams = (JSONObject) jsonParser.parse(agentArgs);
|
||||
|
||||
JSONArray class_configs = (JSONArray) jsonparams.get("instrument");
|
||||
|
||||
Iterator it = class_configs.iterator();
|
||||
|
||||
while(it.hasNext()) {
|
||||
|
||||
JSONObject config = (JSONObject) it.next();
|
||||
//JSONObject config = (JSONObject) ((JSONArray) jsonparams.get("instrument")).get(0);
|
||||
JSONArray methods = (JSONArray) config.get("methods");
|
||||
//JSONjsonparams.get("instrument")
|
||||
|
||||
|
||||
Class adviceCls = Class.forName((String) config.get("adviceClass"));
|
||||
Advice advice = Advice.to(adviceCls);
|
||||
|
||||
//Advice advice = Advice.withCustomMapping().bind(DTAdvice.class,""); //to(DTAdvice.class);
|
||||
ElementMatcher.Junction matches = ElementMatchers.nameMatches(config.get("class").toString());
|
||||
|
||||
ResettableClassFileTransformer ab = new AgentBuilder.Default()
|
||||
.disableClassFormatChanges()
|
||||
.with(RedefinitionStrategy.RETRANSFORMATION)
|
||||
.type(matches)
|
||||
|
||||
.transform((builder, typeDescription, classLoader, module) -> {
|
||||
for (int i = 0; i < methods.size(); i++) {
|
||||
System.out.println(methods.get(i).toString());
|
||||
builder = builder.visit(advice.on(ElementMatchers.named(methods.get(i).toString())));
|
||||
}
|
||||
|
||||
return builder;
|
||||
}).installOn(instrumentation);
|
||||
}
|
||||
|
||||
|
||||
} catch (ParseException | ClassNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
|
||||
System.out.println(e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// public static void agentmain(String agentArgs, Instrumentation instrumentation) {
|
||||
|
||||
// System.out.println("attached dynamically witth parameeters 2: "+agentArgs);
|
||||
// //String[] methods = {"fetchAll","create"};
|
||||
|
||||
// JSONParser jsonParser = new JSONParser();
|
||||
// JSONObject jsonparams=null;
|
||||
|
||||
// try {
|
||||
// jsonparams = (JSONObject) jsonParser.parse(agentArgs);
|
||||
// JSONObject config = (JSONObject) ((JSONArray) jsonparams.get("instrument")).get(0);
|
||||
// JSONArray methods = (JSONArray) config.get("methods");
|
||||
// //JSONjsonparams.get("instrument")
|
||||
// Advice advice = Advice.to(DTAdvice.class);
|
||||
// ElementMatcher.Junction matches = ElementMatchers.nameMatches(config.get("class").toString());
|
||||
|
||||
// ResettableClassFileTransformer ab = new AgentBuilder.Default()
|
||||
// .disableClassFormatChanges()
|
||||
// .with(RedefinitionStrategy.RETRANSFORMATION)
|
||||
// .type(matches)
|
||||
|
||||
// .transform((builder, typeDescription, classLoader, module) -> {
|
||||
// for (int i = 0; i < methods.size(); i++) {
|
||||
// System.out.println(methods.get(i).toString());
|
||||
// builder = builder.visit(advice.on(ElementMatchers.named(methods.get(i).toString())));
|
||||
// }
|
||||
|
||||
// return builder;
|
||||
// }).installOn(instrumentation);
|
||||
|
||||
|
||||
// } catch (ParseException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
// }
|
||||
|
||||
public static void main(String[] args) {
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
// package com.example;
|
||||
// import java.lang.management.ManagementFactory;
|
||||
// import java.lang.management.RuntimeMXBean;
|
||||
|
||||
|
||||
// import com.dynatrace.oneagent.sdk.OneAgentSDKFactory;
|
||||
// import com.dynatrace.oneagent.sdk.api.OneAgentSDK;
|
||||
// import com.google.gson.JsonObject;
|
||||
|
||||
// import net.bytebuddy.asm.*;
|
||||
// import net.bytebuddy.asm.Advice.FieldValue;
|
||||
// import net.bytebuddy.implementation.bytecode.assign.Assigner.Typing;
|
||||
|
||||
// public class DTAdvice {
|
||||
// //@Advice.AllArguments Object[] args,
|
||||
// @Advice.OnMethodEnter
|
||||
// static long invokeBeforeEnterMethod(@Advice.AllArguments Object[] args,
|
||||
// @Advice.Origin String method, @FieldValue(value = "jsonObject", typing = Typing.DYNAMIC) Object testStr) {
|
||||
|
||||
// try {
|
||||
// System.out.println("DTAdvice.....");
|
||||
// System.out.println("Test STR Private variable: "+ ((JsonObject)testStr).get("name"));
|
||||
// System.out.println("Printing Methods args: ");
|
||||
// for(Object obj : args) {
|
||||
// System.out.println(obj.toString());
|
||||
// }
|
||||
// OneAgentSDK oneAgentSdk = OneAgentSDKFactory.createInstance();
|
||||
// oneAgentSdk.addCustomRequestAttribute("method_start_time", System.currentTimeMillis());
|
||||
|
||||
// RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();
|
||||
// String jvmName = bean.getName();
|
||||
// System.out.println("Name = " + jvmName);
|
||||
|
||||
|
||||
// System.out.println("Method invoked before enter method by: " + method);
|
||||
|
||||
|
||||
// String thread_name = Thread.currentThread().getName();
|
||||
// oneAgentSdk.addCustomRequestAttribute("thread_name", thread_name);
|
||||
// System.out.println("Current Thread Name: "+thread_name);
|
||||
|
||||
|
||||
// //SEND METRIC ############################
|
||||
// String m = "aemforms.threads,threadname="+thread_name+",methode="+method+",action=start "+System.currentTimeMillis();
|
||||
// OneAgentMetricWriter.getInstance().writeMetric(m);
|
||||
|
||||
// } catch(Exception ex) {
|
||||
// System.out.println("Exception occured during call Oneagent SDK"+ ex.getMessage());
|
||||
// }
|
||||
|
||||
// // final SimpleHttpRequest request = SimpleRequestBuilder.post("http://localhost:14499/metrics/ingest")
|
||||
// // .setBody("cpu.temperature,cpu=1 55",ContentType.TEXT_HTML)
|
||||
// // .build();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// //final HttpPost httpPost = new HttpPost("sadsad");
|
||||
// // HttpClient client = HttpClient.newHttpClient();
|
||||
|
||||
// // HttpRequest request = HttpRequest.newBuilder()
|
||||
// // .uri(URI.create("http://localhost:14499/metrics/ingest"))
|
||||
// // .POST(HttpRequest.BodyPublishers.ofString("cpu.temperature,cpu=1 55"))
|
||||
// // .build();
|
||||
|
||||
// // client.sendAsync(request, BodyHandlers.ofString())
|
||||
// // .thenApply(response -> { System.out.println(response.statusCode());
|
||||
// // return response; } )
|
||||
// // .thenApply(HttpResponse::body)
|
||||
// // .thenAccept(System.out::println);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// return System.currentTimeMillis();
|
||||
// }
|
||||
|
||||
// @Advice.OnMethodExit
|
||||
// static void invokeAfterExitMethod(
|
||||
// @Advice.Origin String method,
|
||||
// @Advice.Enter long startTime
|
||||
// ) {
|
||||
// OneAgentSDK oneAgentSdk = OneAgentSDKFactory.createInstance();
|
||||
// oneAgentSdk.addCustomRequestAttribute("method_end_time", System.currentTimeMillis());
|
||||
|
||||
// long duration = (System.currentTimeMillis() - startTime);
|
||||
// System.out.println("Method " + method + " took " + duration + "ms");
|
||||
|
||||
|
||||
// oneAgentSdk.addCustomRequestAttribute("method_duration", duration);
|
||||
// System.out.println("End method");
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package com.example;
|
||||
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.concurrent.FutureCallback;
|
||||
|
||||
public class MetricPostCallback implements FutureCallback<HttpResponse> {
|
||||
public void completed(final HttpResponse response2) {
|
||||
System.out.println("metric ingest --> complete");
|
||||
}
|
||||
|
||||
public void failed(final Exception ex) {
|
||||
System.out.println("metric ingest --> failed "+ ex.getMessage());
|
||||
}
|
||||
|
||||
public void cancelled() {
|
||||
System.out.println("metric ingest --> cacelled");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
package com.example;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
//import org.apache.http.concurrent.FutureCallback;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
|
||||
import org.apache.http.impl.nio.client.HttpAsyncClients;
|
||||
|
||||
public class OneAgentMetricWriter {
|
||||
|
||||
private static OneAgentMetricWriter instance;
|
||||
CloseableHttpAsyncClient client = null;
|
||||
HttpPost httpPost=null;
|
||||
|
||||
private OneAgentMetricWriter() {
|
||||
this.client = HttpAsyncClients.custom()
|
||||
.build();
|
||||
client.start();
|
||||
|
||||
this.httpPost = new HttpPost("http://localhost:14499/metrics/ingest");
|
||||
}
|
||||
|
||||
public void writeMetric(String request) {
|
||||
// final CloseableHttpAsyncClient client = HttpAsyncClients.custom()
|
||||
// .build();
|
||||
// client.start();
|
||||
|
||||
|
||||
//String request = "cpu.temperature,cpu=1 55";
|
||||
StringEntity entity;
|
||||
try {
|
||||
entity = new StringEntity(request);
|
||||
httpPost.setEntity(entity);
|
||||
httpPost.setHeader("Content-type", "text/plain");
|
||||
Future<HttpResponse> future = client.execute(httpPost, new MetricPostCallback());
|
||||
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static OneAgentMetricWriter getInstance() {
|
||||
if (instance == null) {
|
||||
// synchronized block to remove overhead
|
||||
synchronized (OneAgentMetricWriter.class) {
|
||||
if (instance == null) {
|
||||
// if instance is null, initialize
|
||||
instance = new OneAgentMetricWriter();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,117 @@
|
|||
package com.example;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.RuntimeMXBean;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.concurrent.FutureCallback;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
|
||||
import org.apache.http.impl.nio.client.HttpAsyncClients;
|
||||
|
||||
import com.dynatrace.oneagent.sdk.OneAgentSDKFactory;
|
||||
import com.dynatrace.oneagent.sdk.api.OneAgentSDK;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import net.bytebuddy.asm.*;
|
||||
import net.bytebuddy.asm.Advice.FieldValue;
|
||||
import net.bytebuddy.implementation.bytecode.assign.Assigner.Typing;
|
||||
|
||||
public class XMLDTAdvice {
|
||||
//@Advice.AllArguments Object[] args,
|
||||
@Advice.OnMethodEnter
|
||||
static long invokeBeforeEnterMethod(@Advice.AllArguments Object[] args,
|
||||
@Advice.Origin String method) {
|
||||
|
||||
try {
|
||||
|
||||
System.out.println("XMLDTAdvice.....");
|
||||
|
||||
// System.out.println("Test STR Private variable: "+ ((JsonObject)testStr).get("name"));
|
||||
// System.out.println("Printing Methods args: ");
|
||||
for(Object obj : args) {
|
||||
System.out.println(obj.toString());
|
||||
}
|
||||
OneAgentSDK oneAgentSdk = OneAgentSDKFactory.createInstance();
|
||||
oneAgentSdk.addCustomRequestAttribute("method_start_time", System.currentTimeMillis());
|
||||
|
||||
RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();
|
||||
String jvmName = bean.getName();
|
||||
System.out.println("Name = " + jvmName);
|
||||
|
||||
|
||||
System.out.println("Method invoked before enter method by: " + method);
|
||||
|
||||
|
||||
String thread_name = Thread.currentThread().getName();
|
||||
oneAgentSdk.addCustomRequestAttribute("thread_name", thread_name);
|
||||
System.out.println("Current Thread Name: "+thread_name);
|
||||
|
||||
|
||||
//SEND METRIC ############################
|
||||
// final CloseableHttpAsyncClient client = HttpAsyncClients.custom()
|
||||
// .build();
|
||||
// client.start();
|
||||
|
||||
// final HttpPost httpPost = new HttpPost("http://localhost:14499/metrics/ingest");
|
||||
// String request = "cpu.temperature,cpu=1 55";
|
||||
// StringEntity entity = new StringEntity(request);
|
||||
// httpPost.setEntity(entity);
|
||||
// httpPost.setHeader("Content-type", "text/plain");
|
||||
|
||||
// final Future<HttpResponse> future = client.execute(httpPost, new MetricPostCallback());
|
||||
OneAgentMetricWriter.getInstance().writeMetric("cpu.temperature,cpu=1 55");
|
||||
|
||||
} catch(Exception ex) {
|
||||
System.out.println("Exception occured during call Oneagent SDK"+ ex.getMessage());
|
||||
}
|
||||
|
||||
// final SimpleHttpRequest request = SimpleRequestBuilder.post("http://localhost:14499/metrics/ingest")
|
||||
// .setBody("cpu.temperature,cpu=1 55",ContentType.TEXT_HTML)
|
||||
// .build();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//final HttpPost httpPost = new HttpPost("sadsad");
|
||||
// HttpClient client = HttpClient.newHttpClient();
|
||||
|
||||
// HttpRequest request = HttpRequest.newBuilder()
|
||||
// .uri(URI.create("http://localhost:14499/metrics/ingest"))
|
||||
// .POST(HttpRequest.BodyPublishers.ofString("cpu.temperature,cpu=1 55"))
|
||||
// .build();
|
||||
|
||||
// client.sendAsync(request, BodyHandlers.ofString())
|
||||
// .thenApply(response -> { System.out.println(response.statusCode());
|
||||
// return response; } )
|
||||
// .thenApply(HttpResponse::body)
|
||||
// .thenAccept(System.out::println);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@Advice.OnMethodExit
|
||||
static void invokeAfterExitMethod(
|
||||
@Advice.Origin String method,
|
||||
@Advice.Enter long startTime
|
||||
) {
|
||||
OneAgentSDK oneAgentSdk = OneAgentSDKFactory.createInstance();
|
||||
oneAgentSdk.addCustomRequestAttribute("method_end_time", System.currentTimeMillis());
|
||||
|
||||
long duration = (System.currentTimeMillis() - startTime);
|
||||
System.out.println("Method " + method + " took " + duration + "ms");
|
||||
|
||||
|
||||
oneAgentSdk.addCustomRequestAttribute("method_duration", duration);
|
||||
System.out.println("End method");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.example;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit test for simple App.
|
||||
*/
|
||||
public class AppTest
|
||||
{
|
||||
/**
|
||||
* Rigorous Test :-)
|
||||
*/
|
||||
@Test
|
||||
public void shouldAnswerWithTrue()
|
||||
{
|
||||
assertTrue( true );
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue