Skip to content
Merged

Dev #156

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions scouter.agent.java/src/scouter/agent/Configure.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public final static synchronized Configure getInstance() {
public int profile_fullstack_max_lines = 0;
public boolean profile_sql_escape_enabled = true;
public boolean _profile_fullstack_sql_connection_enabled = false;
public boolean profile_fullstack_rs_leak_enabled = false;
public boolean profile_fullstack_stmt_leak_enabled = false;

//Trace
public int trace_user_mode = 2; // 0:Remote IP, 1:JSessionID, 2:SetCookie
Expand All @@ -114,6 +116,9 @@ public final static synchronized Configure getInstance() {
public String trace_webserver_time_header_key = "X-Forwarded-Time";
public int _trace_fullstack_socket_open_port = 0;

public boolean trace_rs_leak_enabled = false;
public boolean trace_stmt_leak_enabled = false;

//Dir
public File plugin_dir = new File("./plugin");
public File dump_dir = new File("./dump");
Expand Down Expand Up @@ -421,6 +426,9 @@ private void apply() {
this.profile_fullstack_sql_error_enabled = getBoolean("profile_fullstack_sql_error_enabled", false);
this.profile_fullstack_sql_commit_enabled = getBoolean("profile_fullstack_sql_commit_enabled", false);
this.profile_fullstack_max_lines = getInt("profile_fullstack_max_lines", 0);
this.profile_fullstack_rs_leak_enabled = getBoolean("profile_fullstack_rs_leak_enabled", false);
this.profile_fullstack_stmt_leak_enabled = getBoolean("profile_fullstack_stmt_leak_enabled", false);

this.net_udp_collection_interval_ms = getInt("net_udp_collection_interval_ms", 100);
this.profile_http_parameter_url_prefix = getValue("profile_http_parameter_url_prefix", "/");
this.profile_http_header_url_prefix = getValue("profile_http_header_url_prefix", "/");
Expand Down Expand Up @@ -458,6 +466,10 @@ private void apply() {
this.trace_webserver_enabled = getBoolean("trace_webserver_enabled", false);
this.trace_webserver_name_header_key = getValue("trace_webserver_name_header_key", "X-Forwarded-Host");
this.trace_webserver_time_header_key = getValue("trace_webserver_time_header_key", "X-Forwarded-Time");

this.trace_rs_leak_enabled = getBoolean("trace_rs_leak_enabled", false);
this.trace_stmt_leak_enabled = getBoolean("trace_stmt_leak_enabled", false);

// SUMMARY최대 갯수를 관리한다.
this.summary_enabled = getBoolean("summary_enabled", true);
this._summary_sql_max_count = getInt("_summary_sql_max_count", 5000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ public MethodVisitor visitMethod(int access, String name, String desc, String si

} else if ("getUpdateCount".equals(name) && "()I".equals(desc)) {
return new PsUpdateCountMV(mv);
}
} else if ("close".equals(name) && "()V".equals(desc)) {
return new PsCloseMV(mv);
}
}
return mv;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
* limitations under the License.
*/
package scouter.agent.asm;

import scouter.agent.ClassDesc;
import scouter.agent.Configure;
import scouter.agent.Logger;
import scouter.agent.asm.jdbc.RsCloseMV;
import scouter.agent.asm.jdbc.RsInitMV;
import scouter.agent.asm.jdbc.RsNextMV;
import scouter.agent.asm.util.HookingSet;
import scouter.org.objectweb.asm.ClassVisitor;
Expand Down Expand Up @@ -63,7 +65,10 @@ public ResultSetCV(ClassVisitor cv) {
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
if ("next".equals(name) && "()Z".equals(desc)) {

if ("<init>".equals(name)) {
return new RsInitMV(access, desc, mv);
} else if ("next".equals(name) && "()Z".equals(desc)) {
return new RsNextMV(mv);
} else if ("close".equals(name) && "()V".equals(desc)) {
return new RsCloseMV(mv);
Expand Down
40 changes: 40 additions & 0 deletions scouter.agent.java/src/scouter/agent/asm/jdbc/PsCloseMV.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2015 Scouter Project.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package scouter.agent.asm.jdbc;


import scouter.agent.trace.TraceSQL;
import scouter.org.objectweb.asm.MethodVisitor;
import scouter.org.objectweb.asm.Opcodes;

public class PsCloseMV extends MethodVisitor implements Opcodes {
private static final String TRACESQL = TraceSQL.class.getName().replace('.', '/');
private static final String METHOD = "stmtClose";
private static final String SIGNATURE = "(Ljava/lang/Object;)V";

public PsCloseMV(MethodVisitor mv) {
super(ASM4, mv);
}

@Override
public void visitInsn(int opcode) {
if ((opcode >= IRETURN && opcode <= RETURN)) {
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, METHOD, SIGNATURE,false);
}
mv.visitInsn(opcode);
}
}
5 changes: 5 additions & 0 deletions scouter.agent.java/src/scouter/agent/asm/jdbc/PsInitMV.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public class PsInitMV extends LocalVariablesSorter implements Opcodes {
private final static String METHOD = "prepare";
private final static String SIGNATURE = "(Ljava/lang/Object;Lscouter/agent/trace/SqlParameter;Ljava/lang/String;)V";

private final static String METHOD_INIT = "stmtInit";
private final static String SIGNATURE_INIT = "(Ljava/lang/Object;)V";

private String owner;
private int sqlIdx = -1;
private boolean isUstatement = false;
Expand All @@ -57,6 +60,8 @@ public PsInitMV(int access, String desc, MethodVisitor mv, String owner) {
@Override
public void visitInsn(int opcode) {
if (sqlIdx >= 0 && (opcode >= IRETURN && opcode <= RETURN)) {
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, METHOD_INIT, SIGNATURE_INIT, false);

mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, owner, TraceSQL.PSTMT_PARAM_FIELD, "Lscouter/agent/trace/SqlParameter;");
Expand Down
46 changes: 46 additions & 0 deletions scouter.agent.java/src/scouter/agent/asm/jdbc/RsInitMV.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2015 Scouter Project.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package scouter.agent.asm.jdbc;

import scouter.agent.trace.TraceSQL;
import scouter.org.objectweb.asm.MethodVisitor;
import scouter.org.objectweb.asm.Opcodes;
import scouter.org.objectweb.asm.commons.LocalVariablesSorter;

/**
* BCI for a constructor of Resultset
* @author Gun Lee (gunlee01@gmail.com)
*/
public class RsInitMV extends LocalVariablesSorter implements Opcodes {

private final static String TRACESQL = TraceSQL.class.getName().replace('.', '/');
private final static String METHOD = "rsInit";
private final static String SIGNATURE = "(Ljava/lang/Object;)V";

public RsInitMV(int access, String desc, MethodVisitor mv) {
super(ASM4, access, desc, mv);
}

@Override
public void visitInsn(int opcode) {
if ((opcode >= IRETURN && opcode <= RETURN)) {
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, METHOD, SIGNATURE, false);
}
mv.visitInsn(opcode);
}
}
40 changes: 19 additions & 21 deletions scouter.agent.java/src/scouter/agent/counter/task/JBossJMXPerf.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public boolean equals(Object obj) {

private List<MBeanServer> servers;

List<CtxObj> ctxList = new ArrayList<CtxObj>();
List<MBeanObj> beanList = new ArrayList<MBeanObj>();

public long collectCnt = 0;

Expand All @@ -118,36 +118,34 @@ public void process(CounterBasket pw) {
AgentHeartBeat.clearSubObjects();
dirtyConfig = false;
}
getContextList();
getMbeanList();
}
collectCnt++;
MBeanServer server = servers.get(0);
for (CtxObj ctx : ctxList) {
if (ctx.valueType == ValueEnum.DECIMAL) {
for (MBeanObj beanObj : beanList) {
if (beanObj.valueType == ValueEnum.DECIMAL) {
try {
MeterKey key = new MeterKey(ctx.mbeanHash, ctx.counter);
long v = CastUtil.clong(server.getAttribute(ctx.mbean, ctx.attrName));
if (deltas.contains(ctx.counter)) {
MeterKey key = new MeterKey(beanObj.mbeanHash, beanObj.counter);
long v = CastUtil.clong(server.getAttribute(beanObj.mbean, beanObj.attrName));
if (deltas.contains(beanObj.counter)) {
v = getDelta(key, v);
MeterResource meter = getMeter(key);
meter.add(v);
v = (long) meter.getSum(60);
long sum = (long) meter.getSum(300) / 5;

pw.getPack(ctx.objName, TimeTypeEnum.REALTIME).add(ctx.counter, new DecimalValue(v));
pw.getPack(ctx.objName, TimeTypeEnum.FIVE_MIN).add(ctx.counter, new DecimalValue(sum));
pw.getPack(beanObj.objName, TimeTypeEnum.REALTIME).add(beanObj.counter, new DecimalValue(v));
pw.getPack(beanObj.objName, TimeTypeEnum.FIVE_MIN).add(beanObj.counter, new DecimalValue(sum));
} else {
MeterResource meter = getMeter(key);
meter.add(v);
double d = meter.getAvg(30);
double avg = meter.getAvg(300);
FloatValue value = new FloatValue((float) d);
FloatValue avgValue = new FloatValue((float) avg);
pw.getPack(ctx.objName, TimeTypeEnum.REALTIME).add(ctx.counter, value);
pw.getPack(ctx.objName, TimeTypeEnum.FIVE_MIN).add(ctx.counter, avgValue);
pw.getPack(beanObj.objName, TimeTypeEnum.REALTIME).add(beanObj.counter, new DecimalValue(v));
pw.getPack(beanObj.objName, TimeTypeEnum.FIVE_MIN).add(beanObj.counter, avgValue);
}
} catch (Exception e) {
errors.add(ctx.attrName);
errors.add(beanObj.attrName);
collectCnt = 0;
e.printStackTrace();
}
Expand Down Expand Up @@ -180,8 +178,8 @@ private String getReqProcType() {
return CounterConstants.REQUESTPROCESS;
}

private void getContextList() {
ctxList.clear();
private void getMbeanList() {
beanList.clear();

for (final MBeanServer server : servers) {
Set<ObjectName> mbeans = server.queryNames(null, null);
Expand Down Expand Up @@ -239,8 +237,8 @@ private void getContextList() {
private void add(String objName, ObjectName mbean, String type, byte decimal, String attrName, String counterName) {
if (errors.contains(attrName))
return;
CtxObj cObj = new CtxObj(objName, mbean, type, ValueEnum.DECIMAL, attrName, counterName);
ctxList.add(cObj);
MBeanObj cObj = new MBeanObj(objName, mbean, type, ValueEnum.DECIMAL, attrName, counterName);
beanList.add(cObj);
}

private static String checkObjName(String name) {
Expand All @@ -264,7 +262,7 @@ private static String checkObjName(String name) {
return sb.toString();
}

class CtxObj {
class MBeanObj {
public int mbeanHash;
public String objName;
public ObjectName mbean;
Expand All @@ -273,7 +271,7 @@ class CtxObj {
public String attrName;
public String counter;

public CtxObj(String objName, ObjectName mbean, String objType, byte valueType, String attrName, String counter) {
public MBeanObj(String objName, ObjectName mbean, String objType, byte valueType, String attrName, String counter) {

this.objName = objName;
this.mbean = mbean;
Expand All @@ -286,7 +284,7 @@ public CtxObj(String objName, ObjectName mbean, String objType, byte valueType,

@Override
public String toString() {
return "CtxObj [objName=" + objName + ", mbean=" + mbean + ", objType=" + objType + ", valueType="
return "MBeanObj [objName=" + objName + ", mbean=" + mbean + ", objType=" + objType + ", valueType="
+ valueType + ", attrName=" + attrName + ", counter=" + counter + "]";
}

Expand Down
Loading