Skip to content

Commit 2d356b7

Browse files
committed
Merge pull request #38 from scouter-project/dev
Dev
2 parents 01708c1 + b150716 commit 2d356b7

File tree

105 files changed

+2966
-743
lines changed

Some content is hidden

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

105 files changed

+2966
-743
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,10 @@ scouter.agent.java/.settings/*
2222
scouter.enduser.script/.idea/*
2323
scouter.enduser.script/.settings/*
2424
node_modules/
25+
scouter.enduser.script/.externalToolBuilders/
26+
scouter.server/*.scouter
27+
scouter.server/conf/account.xml
28+
scouter.server/conf/account_group.xml
29+
scouter.server/database/
30+
scouter.client.product/plugin_customization.ini
31+
scouter.client/plugin_customization.ini

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ APM means application performance monitoring or application performance manageme
55
- Opensource WAS - Tomcat, JBoss, Resin ...
66
- Opensource DB - MariaDB(on closed beta testing now)
77

8-
- Monitoring target (hopeful with every contributors)
8+
- Monitoring target (hopeful with every contributor)
99
- Nodejs, Redis, MongoDB, PostgreSQL, Apach HTTPD, nginX, php ...
1010

1111
![Screen](https://github.com/scouter-project/scouter-help/blob/master/misc/screen/dash1.png)
@@ -20,7 +20,7 @@ SCOUTER can help you.
2020
- Services : ActiveService, TPS, ResponseTime, Transaction Profile(class,sql,apicall), TagCount
2121
- Resources : Cpu,Memory,Network and Heap usage, Connection pools etc.
2222

23-
### At a glance(Click to watch the film)
23+
### At a glance(Click to watch the video)
2424
[![Demo gif](https://j.gifs.com/yDqbAa.gif)](https://youtu.be/iuArTzsD7Ws)
2525

2626
<iframe width="560" height="315" src="https://www.youtube.com/embed/iuArTzsD7Ws" frameborder="0" allowfullscreen></iframe>

scouter.agent.host/src/scouter/boot/Boot.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static void main(String[] args) throws Throwable {
3636
try {
3737
JarUtil.unJar(JarUtil.getThisJarFile(), new File(lib));
3838
} catch (Exception e) {
39-
System.out.println("Fail to extract jar files");
39+
System.out.println("Fail to extract jar files : " + e.toString());
4040
System.out.println("Please check the permission : " + lib + "/*.*");
4141
}
4242
URL[] jarfiles = getURLs(lib);

scouter.agent.java/src/scouter/agent/Configure.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ public final static synchronized Configure getInstance() {
178178
public String hook_jdbc_pstmt = "";
179179
public String hook_jdbc_stmt = "";
180180
public String hook_jdbc_rs = "";
181+
182+
public String hook_dbc_wrapper="";
181183

182184
// /LOAD CONTROL/////
183185
public boolean enable_reject_service = false;
@@ -231,6 +233,8 @@ public final static synchronized Configure getInstance() {
231233
public boolean enable_hook_future = true;
232234
////////////////////////////////////////////
233235

236+
public boolean enable_dbc_wrapper = true;
237+
234238
public String direct_patch_class = "";
235239

236240
public long max_think_time = DateUtil.MILLIS_PER_FIVE_MINUTE;
@@ -242,7 +246,13 @@ public final static synchronized Configure getInstance() {
242246
public boolean enable_trace_web = false;
243247
public String key_web_name = "X-Forwarded-Host";
244248
public String key_web_time = "X-Forwarded-Time";
249+
250+
public boolean enable_summary=true;
251+
public int summary_service_max=10000;
252+
public int summary_sql_max=10000;
253+
public int summary_api_max=5000;
245254

255+
246256
/**
247257
* sometimes call by sample application, at that time normally set some
248258
* properties directly
@@ -292,6 +302,8 @@ public File getPropertyFile() {
292302
}
293303

294304
long last_check = 0;
305+
306+
295307

296308
public synchronized boolean reload(boolean force) {
297309
long now = System.currentTimeMillis();
@@ -427,6 +439,7 @@ private void apply() {
427439
this.hook_jdbc_pstmt = getValue("hook_jdbc_pstmt", "");
428440
this.hook_jdbc_stmt = getValue("hook_jdbc_stmt", "");
429441
this.hook_jdbc_rs = getValue("hook_jdbc_rs", "");
442+
this.hook_dbc_wrapper= getValue("hook_dbc_wrapper", "");
430443

431444
this.hook_signature ^= this.hook_args.hashCode();
432445
this.hook_signature ^= this.hook_return.hashCode();
@@ -496,6 +509,8 @@ private void apply() {
496509
this.enable_hook_jsp = getBoolean("enable_hook_jsp", true);
497510
this.enable_hook_future = getBoolean("enable_hook_future", true);
498511

512+
this.enable_dbc_wrapper= getBoolean("enable_dbc_wrapper", true);
513+
499514
this.direct_patch_class = getValue("direct_patch_class", "");
500515
this.max_think_time = getLong("max_think_time", DateUtil.MILLIS_PER_FIVE_MINUTE);
501516

@@ -510,6 +525,13 @@ private void apply() {
510525
this.key_web_name = getValue("key_web_name", "X-Forwarded-Host");
511526
this.key_web_time = getValue("key_web_time", "X-Forwarded-Time");
512527

528+
//SUMMARY최대 갯수를 관리한다.
529+
this.enable_summary = getBoolean("enable_summary", true);
530+
this.summary_sql_max = getInt("summary_sql_max", 10000);
531+
this.summary_api_max= getInt("summary_api_max", 5000);
532+
this.summary_service_max = getInt("summary_service_max", 10000);
533+
534+
513535
resetObjInfo();
514536
setErrorStatus();
515537
setStaticContents();

scouter.agent.java/src/scouter/agent/asm/JDBCDriverASM.java

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* limitations under the License.
1515
*/
1616
package scouter.agent.asm;
17-
import java.util.HashMap;
1817
import java.util.Map;
18+
1919
import scouter.agent.ClassDesc;
2020
import scouter.agent.Configure;
2121
import scouter.agent.Logger;
@@ -28,15 +28,17 @@
2828
import scouter.org.objectweb.asm.Opcodes;
2929
import scouter.org.objectweb.asm.Type;
3030
import scouter.org.objectweb.asm.commons.LocalVariablesSorter;
31+
3132
public class JDBCDriverASM implements IASM, Opcodes {
32-
private Map<String, MethodSet> reserved = new HashMap<String, MethodSet>();
33+
//user can define driver.connect()
34+
private Map<String, MethodSet> reserved =MethodSet.getHookingSet(Configure.getInstance().hook_dbc_wrapper);
3335
public JDBCDriverASM() {
3436
AsmUtil.add(reserved, "com/ibm/db2/jcc/DB2Driver", "connect(Ljava/lang/String;Ljava/util/Properties;)Ljava/sql/Connection;");
3537
}
3638
public boolean isTarget(String className) {
3739
MethodSet mset = reserved.get(className);
3840
if (mset != null){
39-
return false;
41+
return true;
4042
}
4143
return false;
4244
}
@@ -77,11 +79,9 @@ public MethodVisitor visitMethod(int access, String name, String desc, String si
7779
// ///////////////////////////////////////////////////////////////////////////
7880
class JDBCDriverMV extends LocalVariablesSorter implements Opcodes {
7981
private static final String TRACE_SQL = TraceSQL.class.getName().replace('.', '/');
80-
private final static String START_METHOD = "startCreateDBC";
81-
private static final String START_SIGNATURE = "(Ljava/lang/String;)Ljava/lang/Object;";
82-
private final static String END_METHOD = "endCreateDBC";
83-
private static final String END_SIGNATURE = "(Ljava/sql/Connection;Ljava/lang/Object;)Ljava/sql/Connection;";
84-
private static final String ERR_SIGNATURE = "(Ljava/lang/Object;Ljava/lang/Throwable;)V";
82+
private final static String CONNECT_METHOD = "driverConnect";
83+
private static final String CONNECT_SIGNATURE = "(Ljava/sql/Connection;Ljava/lang/String;)Ljava/sql/Connection;";
84+
private static final String ERR_SIGNATURE = "(Ljava/lang/String;Ljava/lang/Throwable;)V";
8585

8686
private Label startFinally = new Label();
8787
private Type returnType;
@@ -93,23 +93,18 @@ public JDBCDriverMV(int access, String desc, MethodVisitor mv, String fullname)
9393
this.returnType = Type.getReturnType(desc);
9494
}
9595
private String fullname;
96-
private int statIdx;
9796
private int strArgIdx;
9897
private boolean isStatic;
9998
@Override
10099
public void visitCode() {
101-
mv.visitVarInsn(Opcodes.ALOAD, strArgIdx);
102-
mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACE_SQL, START_METHOD, START_SIGNATURE,false);
103-
statIdx = newLocal(Type.getType(Object.class));
104-
mv.visitVarInsn(Opcodes.ASTORE, statIdx);
105100
mv.visitLabel(startFinally);
106101
mv.visitCode();
107102
}
108103
@Override
109104
public void visitInsn(int opcode) {
110105
if ((opcode >= IRETURN && opcode <= RETURN)) {
111-
mv.visitVarInsn(Opcodes.ALOAD, statIdx);
112-
mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACE_SQL, END_METHOD, END_SIGNATURE,false);
106+
mv.visitVarInsn(Opcodes.ALOAD, strArgIdx);
107+
mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACE_SQL, CONNECT_METHOD, CONNECT_SIGNATURE,false);
113108
}
114109
mv.visitInsn(opcode);
115110
}
@@ -122,9 +117,9 @@ public void visitMaxs(int maxStack, int maxLocals) {
122117

123118
int errIdx = newLocal(Type.getType(Throwable.class));
124119
mv.visitVarInsn(Opcodes.ASTORE, errIdx);
125-
mv.visitVarInsn(Opcodes.ALOAD, statIdx);
120+
mv.visitVarInsn(Opcodes.ALOAD, strArgIdx);
126121
mv.visitVarInsn(Opcodes.ALOAD, errIdx);
127-
mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACE_SQL, END_METHOD, ERR_SIGNATURE,false);
122+
mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACE_SQL, CONNECT_METHOD, ERR_SIGNATURE,false);
128123
mv.visitInsn(ATHROW);
129124
mv.visitMaxs(maxStack + 8, maxLocals + 2);
130125
}

scouter.agent.java/src/scouter/agent/counter/task/ServicePerf.java

Lines changed: 86 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -14,77 +14,109 @@
1414
* limitations under the License.
1515
*/
1616

17-
package scouter.agent.counter.task;
18-
17+
package scouter.agent.counter.task;
18+
1919
import scouter.agent.Configure;
2020
import scouter.agent.counter.CounterBasket;
2121
import scouter.agent.counter.anotation.Counter;
2222
import scouter.agent.counter.meter.MeterResource;
2323
import scouter.agent.counter.meter.MeterService;
24+
import scouter.agent.netio.data.DataProxy;
25+
import scouter.agent.summary.ServiceSummary;
2426
import scouter.agent.trace.TraceContextManager;
2527
import scouter.agent.util.DumpUtil;
28+
import scouter.lang.SummaryEnum;
2629
import scouter.lang.TimeTypeEnum;
2730
import scouter.lang.counters.CounterConstants;
2831
import scouter.lang.pack.PerfCounterPack;
32+
import scouter.lang.pack.SummaryPack;
2933
import scouter.lang.value.DecimalValue;
3034
import scouter.lang.value.FloatValue;
3135
import scouter.lang.value.ListValue;
32-
33-
public class ServicePerf {
34-
35-
private MeterResource activeCounter = new MeterResource();
36-
37-
@Counter
38-
public void getServicePerf(CounterBasket pw) {
39-
Configure conf = Configure.getInstance();
40-
MeterService service = MeterService.getInstance();
41-
int elapsed = service.getElapsedTime(30);
42-
float tps = service.getTPS(30);
43-
float err = service.getError(30);
44-
int count = service.getServiceCount(60);
36+
import scouter.util.DateUtil;
37+
38+
public class ServicePerf {
39+
40+
private MeterResource activeCounter = new MeterResource();
41+
42+
@Counter
43+
public void getServicePerf(CounterBasket pw) {
44+
Configure conf = Configure.getInstance();
45+
MeterService service = MeterService.getInstance();
46+
int elapsed = service.getElapsedTime(30);
47+
float tps = service.getTPS(30);
48+
float err = service.getError(30);
49+
int count = service.getServiceCount(60);
4550
int resp90pct = service.getElapsed90Pct(30);
46-
47-
int[] act = TraceContextManager.getActiveCount();
48-
int active = act[0] + act[1] + act[2];
49-
if (conf.auto_dump_trigger <= active) {
50-
DumpUtil.autoDump();
51+
52+
int[] act = TraceContextManager.getActiveCount();
53+
int active = act[0] + act[1] + act[2];
54+
if (conf.auto_dump_trigger <= active) {
55+
DumpUtil.autoDump();
5156
}
52-
activeCounter.add(active);
53-
54-
// active service 30초 평균으로 변경
55-
active = (int) Math.round(activeCounter.getAvg(30));
56-
57-
PerfCounterPack p = pw.getPack(TimeTypeEnum.REALTIME);
58-
p.put(CounterConstants.WAS_ELAPSED_TIME, new DecimalValue(elapsed));
59-
p.put(CounterConstants.WAS_SERVICE_COUNT, new DecimalValue(count));
60-
p.put(CounterConstants.WAS_TPS, new FloatValue(tps));
61-
p.put(CounterConstants.WAS_ERROR_RATE, new FloatValue(err));
57+
activeCounter.add(active);
58+
59+
// active service 30초 평균으로 변경
60+
active = (int) Math.round(activeCounter.getAvg(30));
61+
62+
PerfCounterPack p = pw.getPack(TimeTypeEnum.REALTIME);
63+
p.put(CounterConstants.WAS_ELAPSED_TIME, new DecimalValue(elapsed));
64+
p.put(CounterConstants.WAS_SERVICE_COUNT, new DecimalValue(count));
65+
p.put(CounterConstants.WAS_TPS, new FloatValue(tps));
66+
p.put(CounterConstants.WAS_ERROR_RATE, new FloatValue(err));
6267
p.put(CounterConstants.WAS_ACTIVE_SERVICE, new DecimalValue(active));
6368
p.put(CounterConstants.WAS_ELAPSED_90PCT, new DecimalValue(resp90pct));
64-
65-
ListValue activeSpeed = new ListValue();
66-
activeSpeed.add(act[0]);
67-
activeSpeed.add(act[1]);
68-
activeSpeed.add(act[2]);
69-
70-
p.put(CounterConstants.WAS_ACTIVE_SPEED, activeSpeed);
71-
72-
// UdpProxy.sendAlert(, message)
73-
74-
count = service.getServiceCount(300);
75-
tps = service.getTPS(300);
76-
elapsed = service.getElapsedTime(300);
77-
err = service.getError(300);
78-
int activeSErvice = (int) activeCounter.getAvg(300);
69+
70+
ListValue activeSpeed = new ListValue();
71+
activeSpeed.add(act[0]);
72+
activeSpeed.add(act[1]);
73+
activeSpeed.add(act[2]);
74+
75+
p.put(CounterConstants.WAS_ACTIVE_SPEED, activeSpeed);
76+
77+
// UdpProxy.sendAlert(, message)
78+
79+
count = service.getServiceCount(300);
80+
tps = service.getTPS(300);
81+
elapsed = service.getElapsedTime(300);
82+
err = service.getError(300);
83+
int activeSErvice = (int) activeCounter.getAvg(300);
7984
resp90pct = service.getElapsed90Pct(300);
80-
81-
p = pw.getPack(TimeTypeEnum.FIVE_MIN);
82-
p.put(CounterConstants.WAS_ELAPSED_TIME, new DecimalValue(elapsed));
83-
p.put(CounterConstants.WAS_SERVICE_COUNT, new DecimalValue(count));
84-
p.put(CounterConstants.WAS_TPS, new FloatValue(tps));
85-
p.put(CounterConstants.WAS_ERROR_RATE, new FloatValue(err));
85+
86+
p = pw.getPack(TimeTypeEnum.FIVE_MIN);
87+
p.put(CounterConstants.WAS_ELAPSED_TIME, new DecimalValue(elapsed));
88+
p.put(CounterConstants.WAS_SERVICE_COUNT, new DecimalValue(count));
89+
p.put(CounterConstants.WAS_TPS, new FloatValue(tps));
90+
p.put(CounterConstants.WAS_ERROR_RATE, new FloatValue(err));
8691
p.put(CounterConstants.WAS_ACTIVE_SERVICE, new DecimalValue(activeSErvice));
87-
p.put(CounterConstants.WAS_ELAPSED_90PCT, new DecimalValue(resp90pct));
88-
}
89-
92+
p.put(CounterConstants.WAS_ELAPSED_90PCT, new DecimalValue(resp90pct));
93+
}
94+
95+
private long last_sent = DateUtil.getMinUnit(System.currentTimeMillis()) / 5;
96+
97+
@Counter(interval = 500)
98+
public void summay(CounterBasket pw) {
99+
long time = System.currentTimeMillis();
100+
long now = DateUtil.getMinUnit(time) / 5;
101+
if (now == last_sent)
102+
return;
103+
last_sent = now;
104+
time = (time - 10000) / DateUtil.MILLIS_PER_FIVE_MINUTE * DateUtil.MILLIS_PER_FIVE_MINUTE;
105+
106+
SummaryPack p = ServiceSummary.getInstance().getAndClear(SummaryEnum.APP);
107+
if (p != null) {
108+
p.time = time;
109+
DataProxy.send(p);
110+
}
111+
p = ServiceSummary.getInstance().getAndClear(SummaryEnum.SQL);
112+
if (p != null) {
113+
p.time = time;
114+
DataProxy.send(p);
115+
}
116+
p = ServiceSummary.getInstance().getAndClear(SummaryEnum.APICALL);
117+
if (p != null) {
118+
p.time = time;
119+
DataProxy.send(p);
120+
}
121+
}
90122
}

scouter.agent.java/src/scouter/agent/netio/data/DataProxy.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import scouter.lang.pack.ObjectPack;
3131
import scouter.lang.pack.Pack;
3232
import scouter.lang.pack.PerfCounterPack;
33+
import scouter.lang.pack.SummaryPack;
3334
import scouter.lang.pack.TextPack;
3435
import scouter.lang.pack.XLogPack;
3536
import scouter.lang.pack.XLogProfilePack;
@@ -203,7 +204,10 @@ public static void sendXLog(XLogPack p) {
203204
Logger.info(p.toString());
204205
}
205206
}
206-
207+
public static void send(SummaryPack p) {
208+
p.objHash = conf.objHash;
209+
sendDirect(p);
210+
}
207211
static DataUdpAgent udpNet = DataUdpAgent.getInstance();
208212

209213
public static void sendDirect(Pack p) {

0 commit comments

Comments
 (0)