Skip to content

Commit 114a267

Browse files
authored
Merge pull request #321 from scouter-project/dev
Dev
2 parents 7e241ba + 8875ea9 commit 114a267

Some content is hidden

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

44 files changed

+1576
-682
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ public final static synchronized Configure getInstance() {
8585
@ConfigDesc("Path to file reading directory of java process ID file")
8686
public String counter_object_registry_path = "/tmp/scouter";
8787

88+
@ConfigDesc("Activating netstat counter - too many sockets(ESTABLISHED, TIME_WAIT...) may cause heavy cpu load.")
89+
public boolean counter_netstat_enabled = true;
90+
8891
//Log
8992
@ConfigDesc("")
9093
public boolean log_udp_object = false;
@@ -216,6 +219,7 @@ private void apply() {
216219

217220
this.counter_enabled = getBoolean("counter_enabled", true);
218221
this.log_udp_object = getBoolean("log_udp_object", false);
222+
this.counter_netstat_enabled = getBoolean("counter_netstat_enabled", true);
219223

220224
this.log_dir = getValue("log_dir", "./logs");
221225
this.log_rotation_enalbed = getBoolean("log_rotation_enalbed", true);
@@ -416,4 +420,4 @@ public static void main(String[] args) {
416420
System.out.println(key + " : " + ConfigValueUtil.toValue(defMap.get(key)) + (descMap.containsKey(key) ? " (" + descMap.get(key) + ")" : ""));
417421
}
418422
}
419-
}
423+
}

scouter.agent.host/src/scouter/agent/counter/task/HostPerf.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ public class HostPerf {
5050
@Counter
5151
public void process(CounterBasket pw) {
5252
try {
53-
netstat();
53+
if (Configure.getInstance().counter_netstat_enabled) {
54+
netstat();
55+
}
5456
domain(pw);
5557
} catch (Exception e) {
5658
Logger.println("A140", 10, "HostPerf", e);

scouter.agent.java/src/scouter/agent/AgentCommonContant.java renamed to scouter.agent.java/src/scouter/agent/AgentCommonConstant.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Common constants for scouter agent.
66
*
77
*/
8-
public class AgentCommonContant {
8+
public class AgentCommonConstant {
99
public static final String SPRING_REQUEST_MAPPING_POSTFIX_FLAG = " [:SRM]";
1010
public static final String REQUEST_ATTRIBUTE_INITIAL_TRACE_CONTEXT = "__scouter__itc__";
1111
public static final String REQUEST_ATTRIBUTE_TRACE_CONTEXT = "__scouter__tc__";
@@ -16,6 +16,8 @@ public class AgentCommonContant {
1616

1717
public static final String ASYNC_SERVLET_DISPATCHED_PREFIX = "f>";
1818

19+
private static final char at = '@';
20+
1921
/**
2022
* remove " [:SRM]" from service name
2123
*/
@@ -29,4 +31,28 @@ public static String removeSpringRequestMappingPostfixFlag(String org) {
2931
return pre;
3032
}
3133
}
34+
35+
public static String normalizeHashCode(String text) {
36+
if(text == null) return text;
37+
int atPos = text.lastIndexOf(at);
38+
if(atPos > 0 && text.length() >= atPos + 8 + 1) {
39+
String hexa = text.substring(atPos+1, atPos+1+8);
40+
try {
41+
Long.parseLong(hexa, 16);
42+
} catch (NumberFormatException e) {
43+
return text;
44+
}
45+
if (text.length() > atPos + 8 + 1) {
46+
return text.substring(0, atPos+1) + text.substring(atPos+1+8);
47+
} else {
48+
return text.substring(0, atPos+1);
49+
}
50+
}
51+
return text;
52+
}
53+
54+
public static void main(String[] args) {
55+
String serviceName = "xxxiej.s@dfljoeif@0000000f";
56+
System.out.println(normalizeHashCode(serviceName));
57+
}
3258
}

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

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,27 @@
2626
import scouter.lang.value.ListValue;
2727
import scouter.lang.value.MapValue;
2828
import scouter.net.NetConstants;
29-
import scouter.util.*;
30-
31-
import java.io.*;
32-
import java.util.*;
29+
import scouter.util.DateUtil;
30+
import scouter.util.FileUtil;
31+
import scouter.util.HashUtil;
32+
import scouter.util.StringEnumer;
33+
import scouter.util.StringKeyLinkedMap;
34+
import scouter.util.StringSet;
35+
import scouter.util.StringUtil;
36+
import scouter.util.SysJMX;
37+
import scouter.util.SystemUtil;
38+
import scouter.util.ThreadUtil;
39+
40+
import java.io.File;
41+
import java.io.FileInputStream;
42+
import java.io.FileOutputStream;
43+
import java.io.InputStream;
44+
import java.io.OutputStream;
45+
import java.util.HashMap;
46+
import java.util.HashSet;
47+
import java.util.Map;
48+
import java.util.Properties;
49+
import java.util.Set;
3350

3451
public class Configure extends Thread {
3552
public static boolean JDBC_REDEFINED = false;
@@ -105,6 +122,8 @@ public final static synchronized Configure getInstance() {
105122
public boolean profile_http_header_enabled;
106123
@ConfigDesc("Service URL prefix for Http header profile")
107124
public String profile_http_header_url_prefix = "/";
125+
@ConfigDesc("http header names for profiling with comma separator")
126+
public String profile_http_header_keys = "";
108127
@ConfigDesc("Http Parameter profile")
109128
public boolean profile_http_parameter_enabled;
110129
@ConfigDesc("Service URL prefix for Http parameter profile")
@@ -362,6 +381,8 @@ public final static synchronized Configure getInstance() {
362381
public String hook_exception_exlude_class_patterns = "";
363382
@ConfigDesc("Exception handler patterns - exceptions passed to these methods are treated as error on xlog view. (ex) my.app.myHandler.handleException")
364383
public String hook_exception_handler_method_patterns = "";
384+
@ConfigDesc("Exception handler exclude class name patterns(can not include star-* in patterns)\n - (ex) my.app.MyManagedException,MyBizException")
385+
public String hook_exception_hanlder_exclude_class_patterns = "";
365386

366387
@ConfigDesc("Hook for supporting async servlet")
367388
public boolean hook_async_servlet_enabled = true;
@@ -479,6 +500,8 @@ public final static synchronized Configure getInstance() {
479500
public boolean __control_connection_leak_autoclose_enabled = false;
480501
public boolean __ip_dummy_test = false;
481502

503+
public Set<String> _profile_http_header_keys = null;
504+
482505
//internal variables
483506
private String objExtType = "";
484507
private int objHash;
@@ -568,7 +591,14 @@ private void apply() {
568591
this.profile_http_parameter_enabled = getBoolean("profile_http_parameter_enabled", false);
569592
this.profile_spring_controller_method_parameter_enabled = getBoolean("profile_spring_controller_method_parameter_enabled", false);
570593
this.profile_summary_mode_enabled = getBoolean("profile_summary_mode_enabled", false);
594+
595+
this.profile_http_parameter_url_prefix = getValue("profile_http_parameter_url_prefix", "/");
596+
this.profile_http_header_url_prefix = getValue("profile_http_header_url_prefix", "/");
597+
this.profile_http_header_keys = getValue("profile_http_header_keys", "");
598+
this._profile_http_header_keys = StringUtil.splitAndTrimToSet(this.profile_http_header_keys, ',', true);
599+
571600
this.xlog_lower_bound_time_ms = getInt("xlog_lower_bound_time_ms", 0);
601+
572602
this.trace_service_name_header_key = getValue("trace_service_name_header_key", null);
573603
this.trace_service_name_get_key = getValue("trace_service_name_get_key");
574604
this.trace_service_name_post_key = getValue("trace_service_name_post_key");
@@ -665,6 +695,7 @@ private void apply() {
665695
this.hook_exception_class_patterns = getValue("hook_exception_class_patterns", "");
666696
this.hook_exception_exlude_class_patterns = getValue("hook_exception_exlude_class_patterns", "");
667697
this.hook_exception_handler_method_patterns = getValue("hook_exception_handler_method_patterns", "");
698+
this.hook_exception_hanlder_exclude_class_patterns = getValue("hook_exception_hanlder_exclude_class_patterns", "");
668699

669700
this.hook_async_servlet_enabled = getBoolean("_hook_async_servlet_enabled", true);
670701

@@ -713,8 +744,7 @@ private void apply() {
713744
this.profile_fullstack_stmt_leak_enabled = getBoolean("profile_fullstack_stmt_leak_enabled", false);
714745

715746
this.net_udp_collection_interval_ms = getInt("net_udp_collection_interval_ms", 100);
716-
this.profile_http_parameter_url_prefix = getValue("profile_http_parameter_url_prefix", "/");
717-
this.profile_http_header_url_prefix = getValue("profile_http_header_url_prefix", "/");
747+
718748
this.trace_http_client_ip_header_key = getValue("trace_http_client_ip_header_key", "");
719749
this.trace_interservice_enabled = getBoolean("trace_interservice_enabled", true);
720750
this.trace_response_gxid_enabled = getBoolean("trace_response_gxid_enabled", false);
@@ -1021,6 +1051,7 @@ public void printConfig() {
10211051
static {
10221052
ignoreSet.add("property");
10231053
ignoreSet.add("__experimental");
1054+
ignoreSet.add("_profile_http_header_keys");
10241055
}
10251056

10261057
public MapValue getKeyValueInfo() {

scouter.agent.java/src/scouter/agent/asm/SpringReqMapASM.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
package scouter.agent.asm;
1818

19-
import scouter.agent.AgentCommonContant;
19+
import scouter.agent.AgentCommonConstant;
2020
import scouter.agent.ClassDesc;
2121
import scouter.agent.Configure;
2222
import scouter.agent.Logger;
@@ -174,7 +174,7 @@ public void visitCode() {
174174
sb.append("<").append(methodType).append(">");
175175
}
176176

177-
sb.append(AgentCommonContant.SPRING_REQUEST_MAPPING_POSTFIX_FLAG);
177+
sb.append(AgentCommonConstant.SPRING_REQUEST_MAPPING_POSTFIX_FLAG);
178178

179179
String serviceUrl = sb.toString();
180180
Logger.println("[Apply Spring F/W REST URL] " + serviceUrl);

scouter.agent.java/src/scouter/agent/asm/UserExceptionHandlerASM.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@
2727
import scouter.org.objectweb.asm.Opcodes;
2828
import scouter.org.objectweb.asm.Type;
2929
import scouter.org.objectweb.asm.commons.LocalVariablesSorter;
30+
import scouter.util.StringUtil;
3031

3132
import java.util.List;
3233

3334
public class UserExceptionHandlerASM implements IASM, Opcodes {
34-
private List<HookingSet> target = HookingSet.getHookingMethodSet(Configure.getInstance().hook_exception_handler_method_patterns);
35+
List<HookingSet> target = HookingSet.getHookingMethodSet(Configure.getInstance().hook_exception_handler_method_patterns);
36+
public static String[] exceptionExcludeClasseNames = StringUtil.split(Configure.getInstance().hook_exception_hanlder_exclude_class_patterns, ',');
37+
3538

3639
public ClassVisitor transform(ClassVisitor cv, String className, ClassDesc classDesc) {
3740
for (int i = 0; i < target.size(); i++) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ public static int sendGroup(String text) {
270270
udpCollect.add(new TextPack(TextTypes.GROUP, hash, text));
271271
return hash;
272272
}
273-
private static IntLinkedSet hashMessage = new IntLinkedSet().setMax(500);
273+
private static IntLinkedSet hashMessage = new IntLinkedSet().setMax(10000);
274274
public static int sendHashedMessage(String text) {
275275
int hash = HashUtil.hash(text);
276276
if (hashMessage.contains(hash)) {

scouter.agent.java/src/scouter/agent/netio/request/handle/AgentThread.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717
package scouter.agent.netio.request.handle;
18-
import scouter.agent.AgentCommonContant;
18+
import scouter.agent.AgentCommonConstant;
1919
import scouter.agent.Configure;
2020
import scouter.agent.Logger;
2121
import scouter.agent.counter.task.MakeStack;
@@ -62,7 +62,7 @@ public Pack threadDetail(Pack param) {
6262
p.put("State", new TextValue("n/a"));
6363

6464
p.put("Service Txid", new TextValue(Hexa32.toString32(ctx.txid)));
65-
p.put("Service Name", new TextValue(AgentCommonContant.removeSpringRequestMappingPostfixFlag(ctx.serviceName)));
65+
p.put("Service Name", new TextValue(AgentCommonConstant.removeSpringRequestMappingPostfixFlag(ctx.serviceName)));
6666
long etime = System.currentTimeMillis() - ctx.startTime;
6767
p.put("Service Elapsed", new DecimalValue(etime));
6868
}
@@ -91,7 +91,7 @@ public Pack threadKill(Pack param) {
9191
MapPack p = ThreadUtil.getThreadDetail(thread);
9292
if (ctx != null) {
9393
p.put("Service Txid", new TextValue(Hexa32.toString32(ctx.txid)));
94-
p.put("Service Name", new TextValue(AgentCommonContant.removeSpringRequestMappingPostfixFlag(ctx.serviceName)));
94+
p.put("Service Name", new TextValue(AgentCommonConstant.removeSpringRequestMappingPostfixFlag(ctx.serviceName)));
9595
long etime = System.currentTimeMillis() - ctx.startTime;
9696
p.put("Service Elapsed", new DecimalValue(etime));
9797
String sql = ctx.sqltext;
@@ -117,7 +117,7 @@ public Pack threadList(Pack param) {
117117
TraceContext ctx = TraceContextManager.getContext(tid);
118118
if (ctx != null) {
119119
txid.add(new TextValue(Hexa32.toString32(ctx.txid)));
120-
service.add(new TextValue(AgentCommonContant.removeSpringRequestMappingPostfixFlag(ctx.serviceName)));
120+
service.add(new TextValue(AgentCommonConstant.removeSpringRequestMappingPostfixFlag(ctx.serviceName)));
121121
long etime = System.currentTimeMillis() - ctx.startTime;
122122
elapsed.add(new DecimalValue(etime));
123123
} else {
@@ -154,7 +154,7 @@ public Pack activeThreadList(Pack param) {
154154
name.add(ctx.thread.getName());
155155
stat.add(ctx.thread.getState().name());
156156
txid.add(new TextValue(Hexa32.toString32(ctx.txid)));
157-
service.add(new TextValue(AgentCommonContant.removeSpringRequestMappingPostfixFlag(ctx.serviceName)));
157+
service.add(new TextValue(AgentCommonConstant.removeSpringRequestMappingPostfixFlag(ctx.serviceName)));
158158
ip.add(ctx.remoteIp);
159159
long etime = System.currentTimeMillis() - ctx.startTime;
160160
elapsed.add(new DecimalValue(etime));
@@ -180,7 +180,7 @@ public Pack activeThreadList(Pack param) {
180180
name.add("[No Thread] wait on deferred queue");
181181
stat.add("n/a");
182182
txid.add(new TextValue(Hexa32.toString32(ctx.txid)));
183-
service.add(new TextValue(AgentCommonContant.removeSpringRequestMappingPostfixFlag(ctx.serviceName)));
183+
service.add(new TextValue(AgentCommonConstant.removeSpringRequestMappingPostfixFlag(ctx.serviceName)));
184184
ip.add(ctx.remoteIp);
185185
long etime = System.currentTimeMillis() - ctx.startTime;
186186
elapsed.add(new DecimalValue(etime));

scouter.agent.java/src/scouter/agent/plugin/WrContext.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import scouter.agent.netio.data.DataProxy;
44
import scouter.agent.trace.TraceContext;
5+
import scouter.lang.enumeration.ParameterizedMessageLevel;
56
import scouter.lang.step.HashedMessageStep;
67
import scouter.lang.step.MessageStep;
8+
import scouter.lang.step.ParameterizedMessageStep;
79
import scouter.util.HashUtil;
810
import scouter.util.SysJMX;
911

@@ -73,6 +75,22 @@ public String desc() {
7375
return ctx.desc;
7476
}
7577

78+
public void text1(String text) {
79+
ctx.text1 = text;
80+
}
81+
82+
public String text1() {
83+
return ctx.text1;
84+
}
85+
86+
public void text2(String text) {
87+
ctx.text2 = text;
88+
}
89+
90+
public String text2() {
91+
return ctx.text2;
92+
}
93+
7694
public String httpMethod() {
7795
return ctx.http_method;
7896
}
@@ -118,6 +136,34 @@ public void hashProfile(String msg, int value, int elapsed) {
118136
ctx.profile.add(step);
119137
}
120138

139+
/**
140+
* add xlog profile
141+
* profile display like --> #elasped(if the value is not -1) formatted message
142+
* @param msg message format (ex- "Hello, my name is %s and my age is %s)"
143+
* @param elapsed any value to display on a profile.
144+
* @param params message format parameters.
145+
*/
146+
public void parameterizedProfile(int level, String msg, int elapsed, String... params) {
147+
ParameterizedMessageStep step = new ParameterizedMessageStep();
148+
step.setMessage(DataProxy.sendHashedMessage(msg), params);
149+
step.setElapsed(elapsed);
150+
step.setLevel(ParameterizedMessageLevel.of(level));
151+
step.start_time = (int) (System.currentTimeMillis() - ctx.startTime);
152+
153+
if (ctx.profile_thread_cputime) {
154+
step.start_cpu = (int) (SysJMX.getCurrentThreadCPU() - ctx.startCpu);
155+
}
156+
ctx.profile.add(step);
157+
}
158+
159+
public void parameterizedProfile(String msg, String... params) {
160+
parameterizedProfile(0, msg, -1, params);
161+
}
162+
163+
public void parameterizedProfile(int level, String msg, String... params) {
164+
parameterizedProfile(level, msg, -1, params);
165+
}
166+
121167
public long txid() {
122168
return ctx.txid;
123169
}

scouter.agent.java/src/scouter/agent/trace/TraceContext.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ public TraceContext(boolean profile_summary) {
106106
public String login;
107107
public String desc;
108108

109+
public String text1;
110+
public String text2;
111+
109112
public String web_name;
110113
public int web_time;
111114

0 commit comments

Comments
 (0)