Skip to content

Commit 041d230

Browse files
authored
Merge pull request #184 from scouter-project/master
Merge for release
2 parents a09e242 + 1944128 commit 041d230

File tree

77 files changed

+3180
-217
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+3180
-217
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
scouter.agent.batch/bin/*
12
scouter.agent.java/bin/*
23
scouter.client/bin/*
34
scouter.common/bin/*
@@ -98,3 +99,7 @@ dependency-reduced-pom.xml
9899
buildNumber.properties
99100
.mvn/timing.properties
100101

102+
scouter.client.build/.settings/org.eclipse.core.resources.prefs
103+
scouter.common/.settings/org.eclipse.core.resources.prefs
104+
scouter.agent.host/.settings/org.eclipse.core.resources.prefs
105+
scouter.agent.batch/.settings/org.eclipse.core.resources.prefs

README_kr.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
![scouter](./scouter.document/img/main/scouter-logo-w200.png)
1+
![scouter](./scouter.document/img/main/scouter-logo-w200.png)
22

33
[![Englsh](https://img.shields.io/badge/language-English-red.svg)](README.md) ![Korean](https://img.shields.io/badge/language-Korean-blue.svg)
44

@@ -53,7 +53,7 @@ APM은 Application performance montoring 또는 application performance manageme
5353
<br>
5454

5555
- **Server (Collector)** : Agent가 전송한 데이터를 저장하고 Client 요청시 Client에게 적절한 데이터를 전송
56-
- **Scala** : Written in Scala. It will provide a variety of features and performance scalability that can not be written in Java.
56+
- **Scala** : Scala를 사용하여 개발하였음으로, 자바 코딩으로는 제공하기 어려운 성능 확장성 및 여러가지 기능들을 제공 할수 있음.
5757
- **HASH FILE** : 고속의 자체 개발한 Hash 인덱스 방식의 파일 Repository 사용으로 최상의 속도를 동작하며 추가적인 DB 및 라이브러리의 설치가 불필요하여 압축 해제만으로 쉽게 설치 가능.
5858
- **GZIP** : 압축 옵션을 통해 저장 공간을 절약하도록 개발됨.
5959
<br>

scouter.agent.batch/.classpath

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
5+
<classpathentry combineaccessrules="false" kind="src" path="/scouter.common"/>
6+
<classpathentry combineaccessrules="false" kind="src" path="/scouter.agent.java"/>
7+
<classpathentry kind="output" path="bin"/>
8+
</classpath>

scouter.agent.batch/.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>scouter.agent.batch</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=1.6
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11+
org.eclipse.jdt.core.compiler.source=1.6
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
/*
2+
* Copyright 2016 the original author or authors.
3+
* @https://github.com/scouter-project/scouter
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package scouter.agent.batch;
19+
20+
import scouter.agent.batch.asm.JDBCPreparedStatementASM;
21+
import scouter.agent.batch.asm.JDBCStatementASM;
22+
import scouter.agent.batch.asm.JDBCResultSetASM;
23+
24+
import scouter.agent.asm.ScouterClassWriter;
25+
import scouter.agent.asm.IASM;
26+
import scouter.agent.ClassDesc;
27+
import scouter.agent.ObjTypeDetector;
28+
import scouter.agent.asm.util.AsmUtil;
29+
import scouter.org.objectweb.asm.*;
30+
import scouter.util.FileUtil;
31+
32+
import java.lang.instrument.ClassFileTransformer;
33+
import java.lang.instrument.IllegalClassFormatException;
34+
import java.security.ProtectionDomain;
35+
import java.util.ArrayList;
36+
import java.util.List;
37+
38+
public class AgentTransformer implements ClassFileTransformer {
39+
private static List<String> filters = new ArrayList<String>();
40+
private static List<IASM> asms = new ArrayList<IASM>();
41+
// hook 관련 설정이 변경되면 자동으로 변경된다.
42+
43+
static {
44+
asms.add(new JDBCPreparedStatementASM());
45+
asms.add(new JDBCStatementASM());
46+
asms.add(new JDBCResultSetASM());
47+
48+
filters.add("Statement");
49+
filters.add("ResultSet");
50+
}
51+
52+
private Configure conf = Configure.getInstance();
53+
private Logger.FileLog bciOut;
54+
55+
public byte[] transform(ClassLoader loader, String className, Class classBeingRedefined,
56+
ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
57+
try {
58+
if(!conf.sql_enabled || className == null){
59+
return null;
60+
}
61+
62+
if (className.startsWith("scouter/") || !filter(className)) {
63+
return null;
64+
}
65+
66+
//classfileBuffer = DirectPatch.patch(className, classfileBuffer);
67+
ObjTypeDetector.check(className);
68+
final ClassDesc classDesc = new ClassDesc();
69+
ClassReader cr = new ClassReader(classfileBuffer);
70+
cr.accept(new ClassVisitor(Opcodes.ASM4) {
71+
public void visit(int version, int access, String name, String signature, String superName,
72+
String[] interfaces) {
73+
classDesc.set(version, access, name, signature, superName, interfaces);
74+
super.visit(version, access, name, signature, superName, interfaces);
75+
}
76+
77+
@Override
78+
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
79+
classDesc.anotation += desc;
80+
return super.visitAnnotation(desc, visible);
81+
}
82+
}, 0);
83+
if (AsmUtil.isInterface(classDesc.access)) {
84+
return null;
85+
}
86+
classDesc.classBeingRedefined = classBeingRedefined;
87+
ClassWriter cw = getClassWriter(classDesc);
88+
ClassVisitor cv = cw;
89+
List<IASM> workAsms = asms;
90+
for (int i = 0, max = workAsms.size(); i < max; i++) {
91+
cv = workAsms.get(i).transform(cv, className, classDesc);
92+
if (cv != cw) {
93+
cr = new ClassReader(classfileBuffer);
94+
cr.accept(cv, ClassReader.EXPAND_FRAMES);
95+
classfileBuffer = cw.toByteArray();
96+
cv = cw = getClassWriter(classDesc);
97+
if (conf._log_asm_enabled) {
98+
if (this.bciOut == null) {
99+
this.bciOut = new Logger.FileLog("./scouter.bci");
100+
}
101+
this.bciOut.println(className + "\t\t[" + loader + "]");
102+
dump(className, classfileBuffer);
103+
}
104+
}
105+
}
106+
return classfileBuffer;
107+
} catch (Throwable t) {
108+
Logger.println("A101", "Transformer Error", t);
109+
t.printStackTrace();
110+
}
111+
return null;
112+
}
113+
114+
private ClassWriter getClassWriter(final ClassDesc classDesc) {
115+
ClassWriter cw;
116+
switch (classDesc.version) {
117+
case Opcodes.V1_1:
118+
case Opcodes.V1_2:
119+
case Opcodes.V1_3:
120+
case Opcodes.V1_4:
121+
case Opcodes.V1_5:
122+
case Opcodes.V1_6:
123+
cw = new ScouterClassWriter(ClassWriter.COMPUTE_MAXS);
124+
break;
125+
default:
126+
cw = new ScouterClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
127+
}
128+
return cw;
129+
}
130+
131+
private boolean filter(String className){
132+
for(String name: filters){
133+
if(className.indexOf(name) >= 0){
134+
return true;
135+
}
136+
}
137+
return false;
138+
}
139+
140+
private void dump(String className, byte[] bytes) {
141+
String fname = "./dump/" + className.replace('/', '_') + ".class";
142+
FileUtil.save(fname, bytes);
143+
}
144+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright 2016 Scouter Project.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package scouter.agent.batch;
17+
18+
import java.io.File;
19+
import java.io.FileWriter;
20+
21+
import scouter.agent.batch.dump.ThreadDumpHandler;
22+
import scouter.agent.batch.trace.TraceContext;
23+
import scouter.util.ThreadUtil;
24+
25+
public class BatchMonitor extends Thread {
26+
private static BatchMonitor instance = null;
27+
public Configure config = null;
28+
29+
static public BatchMonitor getInstance(){
30+
if(instance == null){
31+
instance = new BatchMonitor();
32+
instance.setDaemon(true);
33+
instance.setName(ThreadUtil.getName(instance));
34+
35+
TraceContext.getInstance();
36+
Runtime.getRuntime().addShutdownHook(new ResultSender());
37+
instance.start();
38+
}
39+
return instance;
40+
}
41+
42+
public void run() {
43+
FileWriter stackWriter = null;
44+
FileWriter indexWriter = null;
45+
try {
46+
File stackFile = null;
47+
config = Configure.getInstance();
48+
TraceContext traceContext = TraceContext.getInstance();
49+
if(config.sfa_dump_enabled){
50+
File indexFile = null;
51+
52+
stackFile = new File(traceContext.getLogFilename() + ".log");
53+
if(stackFile.exists()){
54+
stackFile = null;
55+
}else{
56+
traceContext.stackLogFile = stackFile.getAbsolutePath();
57+
58+
stackWriter = new FileWriter(stackFile);
59+
indexWriter = new FileWriter(new File(traceContext.getLogFilename() + ".inx"));
60+
}
61+
}
62+
if(stackWriter != null){
63+
while(!config.scouter_stop){
64+
ThreadDumpHandler.processDump(stackFile, stackWriter, indexWriter, config.sfa_dump_filter, config.sfa_dump_header_exists);
65+
traceContext.checkThread();
66+
Thread.sleep(config.sfa_dump_interval_ms);
67+
}
68+
}
69+
}catch(Throwable ex){
70+
Logger.println("ERROR: " + ex.getMessage());
71+
}finally{
72+
if(stackWriter != null){
73+
try{ stackWriter.close(); }catch(Exception ex){}
74+
}
75+
if(indexWriter != null){
76+
try{ indexWriter.close(); }catch(Exception ex){}
77+
}
78+
}
79+
}
80+
}

0 commit comments

Comments
 (0)