Skip to content

Commit

Permalink
Merge pull request #38 from scouter-project/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
bill23-kim committed Oct 18, 2015
2 parents 01708c1 + b150716 commit 2d356b7
Show file tree
Hide file tree
Showing 105 changed files with 2,966 additions and 743 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,10 @@ scouter.agent.java/.settings/*
scouter.enduser.script/.idea/*
scouter.enduser.script/.settings/*
node_modules/
scouter.enduser.script/.externalToolBuilders/
scouter.server/*.scouter
scouter.server/conf/account.xml
scouter.server/conf/account_group.xml
scouter.server/database/
scouter.client.product/plugin_customization.ini
scouter.client/plugin_customization.ini
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ APM means application performance monitoring or application performance manageme
- Opensource WAS - Tomcat, JBoss, Resin ...
- Opensource DB - MariaDB(on closed beta testing now)

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

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

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

<iframe width="560" height="315" src="https://www.youtube.com/embed/iuArTzsD7Ws" frameborder="0" allowfullscreen></iframe>
Expand Down
2 changes: 1 addition & 1 deletion scouter.agent.host/src/scouter/boot/Boot.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static void main(String[] args) throws Throwable {
try {
JarUtil.unJar(JarUtil.getThisJarFile(), new File(lib));
} catch (Exception e) {
System.out.println("Fail to extract jar files");
System.out.println("Fail to extract jar files : " + e.toString());
System.out.println("Please check the permission : " + lib + "/*.*");
}
URL[] jarfiles = getURLs(lib);
Expand Down
22 changes: 22 additions & 0 deletions scouter.agent.java/src/scouter/agent/Configure.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ public final static synchronized Configure getInstance() {
public String hook_jdbc_pstmt = "";
public String hook_jdbc_stmt = "";
public String hook_jdbc_rs = "";

public String hook_dbc_wrapper="";

// /LOAD CONTROL/////
public boolean enable_reject_service = false;
Expand Down Expand Up @@ -231,6 +233,8 @@ public final static synchronized Configure getInstance() {
public boolean enable_hook_future = true;
////////////////////////////////////////////

public boolean enable_dbc_wrapper = true;

public String direct_patch_class = "";

public long max_think_time = DateUtil.MILLIS_PER_FIVE_MINUTE;
Expand All @@ -242,7 +246,13 @@ public final static synchronized Configure getInstance() {
public boolean enable_trace_web = false;
public String key_web_name = "X-Forwarded-Host";
public String key_web_time = "X-Forwarded-Time";

public boolean enable_summary=true;
public int summary_service_max=10000;
public int summary_sql_max=10000;
public int summary_api_max=5000;


/**
* sometimes call by sample application, at that time normally set some
* properties directly
Expand Down Expand Up @@ -292,6 +302,8 @@ public File getPropertyFile() {
}

long last_check = 0;



public synchronized boolean reload(boolean force) {
long now = System.currentTimeMillis();
Expand Down Expand Up @@ -427,6 +439,7 @@ private void apply() {
this.hook_jdbc_pstmt = getValue("hook_jdbc_pstmt", "");
this.hook_jdbc_stmt = getValue("hook_jdbc_stmt", "");
this.hook_jdbc_rs = getValue("hook_jdbc_rs", "");
this.hook_dbc_wrapper= getValue("hook_dbc_wrapper", "");

this.hook_signature ^= this.hook_args.hashCode();
this.hook_signature ^= this.hook_return.hashCode();
Expand Down Expand Up @@ -496,6 +509,8 @@ private void apply() {
this.enable_hook_jsp = getBoolean("enable_hook_jsp", true);
this.enable_hook_future = getBoolean("enable_hook_future", true);

this.enable_dbc_wrapper= getBoolean("enable_dbc_wrapper", true);

this.direct_patch_class = getValue("direct_patch_class", "");
this.max_think_time = getLong("max_think_time", DateUtil.MILLIS_PER_FIVE_MINUTE);

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

//SUMMARY최대 갯수를 관리한다.
this.enable_summary = getBoolean("enable_summary", true);
this.summary_sql_max = getInt("summary_sql_max", 10000);
this.summary_api_max= getInt("summary_api_max", 5000);
this.summary_service_max = getInt("summary_service_max", 10000);


resetObjInfo();
setErrorStatus();
setStaticContents();
Expand Down
29 changes: 12 additions & 17 deletions scouter.agent.java/src/scouter/agent/asm/JDBCDriverASM.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/
package scouter.agent.asm;
import java.util.HashMap;
import java.util.Map;

import scouter.agent.ClassDesc;
import scouter.agent.Configure;
import scouter.agent.Logger;
Expand All @@ -28,15 +28,17 @@
import scouter.org.objectweb.asm.Opcodes;
import scouter.org.objectweb.asm.Type;
import scouter.org.objectweb.asm.commons.LocalVariablesSorter;

public class JDBCDriverASM implements IASM, Opcodes {
private Map<String, MethodSet> reserved = new HashMap<String, MethodSet>();
//user can define driver.connect()
private Map<String, MethodSet> reserved =MethodSet.getHookingSet(Configure.getInstance().hook_dbc_wrapper);
public JDBCDriverASM() {
AsmUtil.add(reserved, "com/ibm/db2/jcc/DB2Driver", "connect(Ljava/lang/String;Ljava/util/Properties;)Ljava/sql/Connection;");
}
public boolean isTarget(String className) {
MethodSet mset = reserved.get(className);
if (mset != null){
return false;
return true;
}
return false;
}
Expand Down Expand Up @@ -77,11 +79,9 @@ public MethodVisitor visitMethod(int access, String name, String desc, String si
// ///////////////////////////////////////////////////////////////////////////
class JDBCDriverMV extends LocalVariablesSorter implements Opcodes {
private static final String TRACE_SQL = TraceSQL.class.getName().replace('.', '/');
private final static String START_METHOD = "startCreateDBC";
private static final String START_SIGNATURE = "(Ljava/lang/String;)Ljava/lang/Object;";
private final static String END_METHOD = "endCreateDBC";
private static final String END_SIGNATURE = "(Ljava/sql/Connection;Ljava/lang/Object;)Ljava/sql/Connection;";
private static final String ERR_SIGNATURE = "(Ljava/lang/Object;Ljava/lang/Throwable;)V";
private final static String CONNECT_METHOD = "driverConnect";
private static final String CONNECT_SIGNATURE = "(Ljava/sql/Connection;Ljava/lang/String;)Ljava/sql/Connection;";
private static final String ERR_SIGNATURE = "(Ljava/lang/String;Ljava/lang/Throwable;)V";

private Label startFinally = new Label();
private Type returnType;
Expand All @@ -93,23 +93,18 @@ public JDBCDriverMV(int access, String desc, MethodVisitor mv, String fullname)
this.returnType = Type.getReturnType(desc);
}
private String fullname;
private int statIdx;
private int strArgIdx;
private boolean isStatic;
@Override
public void visitCode() {
mv.visitVarInsn(Opcodes.ALOAD, strArgIdx);
mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACE_SQL, START_METHOD, START_SIGNATURE,false);
statIdx = newLocal(Type.getType(Object.class));
mv.visitVarInsn(Opcodes.ASTORE, statIdx);
mv.visitLabel(startFinally);
mv.visitCode();
}
@Override
public void visitInsn(int opcode) {
if ((opcode >= IRETURN && opcode <= RETURN)) {
mv.visitVarInsn(Opcodes.ALOAD, statIdx);
mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACE_SQL, END_METHOD, END_SIGNATURE,false);
mv.visitVarInsn(Opcodes.ALOAD, strArgIdx);
mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACE_SQL, CONNECT_METHOD, CONNECT_SIGNATURE,false);
}
mv.visitInsn(opcode);
}
Expand All @@ -122,9 +117,9 @@ public void visitMaxs(int maxStack, int maxLocals) {

int errIdx = newLocal(Type.getType(Throwable.class));
mv.visitVarInsn(Opcodes.ASTORE, errIdx);
mv.visitVarInsn(Opcodes.ALOAD, statIdx);
mv.visitVarInsn(Opcodes.ALOAD, strArgIdx);
mv.visitVarInsn(Opcodes.ALOAD, errIdx);
mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACE_SQL, END_METHOD, ERR_SIGNATURE,false);
mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACE_SQL, CONNECT_METHOD, ERR_SIGNATURE,false);
mv.visitInsn(ATHROW);
mv.visitMaxs(maxStack + 8, maxLocals + 2);
}
Expand Down
140 changes: 86 additions & 54 deletions scouter.agent.java/src/scouter/agent/counter/task/ServicePerf.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,77 +14,109 @@
* limitations under the License.
*/

package scouter.agent.counter.task;

package scouter.agent.counter.task;

import scouter.agent.Configure;
import scouter.agent.counter.CounterBasket;
import scouter.agent.counter.anotation.Counter;
import scouter.agent.counter.meter.MeterResource;
import scouter.agent.counter.meter.MeterService;
import scouter.agent.netio.data.DataProxy;
import scouter.agent.summary.ServiceSummary;
import scouter.agent.trace.TraceContextManager;
import scouter.agent.util.DumpUtil;
import scouter.lang.SummaryEnum;
import scouter.lang.TimeTypeEnum;
import scouter.lang.counters.CounterConstants;
import scouter.lang.pack.PerfCounterPack;
import scouter.lang.pack.SummaryPack;
import scouter.lang.value.DecimalValue;
import scouter.lang.value.FloatValue;
import scouter.lang.value.ListValue;

public class ServicePerf {

private MeterResource activeCounter = new MeterResource();

@Counter
public void getServicePerf(CounterBasket pw) {
Configure conf = Configure.getInstance();
MeterService service = MeterService.getInstance();
int elapsed = service.getElapsedTime(30);
float tps = service.getTPS(30);
float err = service.getError(30);
int count = service.getServiceCount(60);
import scouter.util.DateUtil;

public class ServicePerf {

private MeterResource activeCounter = new MeterResource();

@Counter
public void getServicePerf(CounterBasket pw) {
Configure conf = Configure.getInstance();
MeterService service = MeterService.getInstance();
int elapsed = service.getElapsedTime(30);
float tps = service.getTPS(30);
float err = service.getError(30);
int count = service.getServiceCount(60);
int resp90pct = service.getElapsed90Pct(30);
int[] act = TraceContextManager.getActiveCount();
int active = act[0] + act[1] + act[2];
if (conf.auto_dump_trigger <= active) {
DumpUtil.autoDump();

int[] act = TraceContextManager.getActiveCount();
int active = act[0] + act[1] + act[2];
if (conf.auto_dump_trigger <= active) {
DumpUtil.autoDump();
}
activeCounter.add(active);

// active service 30초 평균으로 변경
active = (int) Math.round(activeCounter.getAvg(30));

PerfCounterPack p = pw.getPack(TimeTypeEnum.REALTIME);
p.put(CounterConstants.WAS_ELAPSED_TIME, new DecimalValue(elapsed));
p.put(CounterConstants.WAS_SERVICE_COUNT, new DecimalValue(count));
p.put(CounterConstants.WAS_TPS, new FloatValue(tps));
p.put(CounterConstants.WAS_ERROR_RATE, new FloatValue(err));
activeCounter.add(active);

// active service 30초 평균으로 변경
active = (int) Math.round(activeCounter.getAvg(30));

PerfCounterPack p = pw.getPack(TimeTypeEnum.REALTIME);
p.put(CounterConstants.WAS_ELAPSED_TIME, new DecimalValue(elapsed));
p.put(CounterConstants.WAS_SERVICE_COUNT, new DecimalValue(count));
p.put(CounterConstants.WAS_TPS, new FloatValue(tps));
p.put(CounterConstants.WAS_ERROR_RATE, new FloatValue(err));
p.put(CounterConstants.WAS_ACTIVE_SERVICE, new DecimalValue(active));
p.put(CounterConstants.WAS_ELAPSED_90PCT, new DecimalValue(resp90pct));

ListValue activeSpeed = new ListValue();
activeSpeed.add(act[0]);
activeSpeed.add(act[1]);
activeSpeed.add(act[2]);

p.put(CounterConstants.WAS_ACTIVE_SPEED, activeSpeed);

// UdpProxy.sendAlert(, message)

count = service.getServiceCount(300);
tps = service.getTPS(300);
elapsed = service.getElapsedTime(300);
err = service.getError(300);
int activeSErvice = (int) activeCounter.getAvg(300);

ListValue activeSpeed = new ListValue();
activeSpeed.add(act[0]);
activeSpeed.add(act[1]);
activeSpeed.add(act[2]);

p.put(CounterConstants.WAS_ACTIVE_SPEED, activeSpeed);

// UdpProxy.sendAlert(, message)

count = service.getServiceCount(300);
tps = service.getTPS(300);
elapsed = service.getElapsedTime(300);
err = service.getError(300);
int activeSErvice = (int) activeCounter.getAvg(300);
resp90pct = service.getElapsed90Pct(300);
p = pw.getPack(TimeTypeEnum.FIVE_MIN);
p.put(CounterConstants.WAS_ELAPSED_TIME, new DecimalValue(elapsed));
p.put(CounterConstants.WAS_SERVICE_COUNT, new DecimalValue(count));
p.put(CounterConstants.WAS_TPS, new FloatValue(tps));
p.put(CounterConstants.WAS_ERROR_RATE, new FloatValue(err));

p = pw.getPack(TimeTypeEnum.FIVE_MIN);
p.put(CounterConstants.WAS_ELAPSED_TIME, new DecimalValue(elapsed));
p.put(CounterConstants.WAS_SERVICE_COUNT, new DecimalValue(count));
p.put(CounterConstants.WAS_TPS, new FloatValue(tps));
p.put(CounterConstants.WAS_ERROR_RATE, new FloatValue(err));
p.put(CounterConstants.WAS_ACTIVE_SERVICE, new DecimalValue(activeSErvice));
p.put(CounterConstants.WAS_ELAPSED_90PCT, new DecimalValue(resp90pct));
}

p.put(CounterConstants.WAS_ELAPSED_90PCT, new DecimalValue(resp90pct));
}

private long last_sent = DateUtil.getMinUnit(System.currentTimeMillis()) / 5;

@Counter(interval = 500)
public void summay(CounterBasket pw) {
long time = System.currentTimeMillis();
long now = DateUtil.getMinUnit(time) / 5;
if (now == last_sent)
return;
last_sent = now;
time = (time - 10000) / DateUtil.MILLIS_PER_FIVE_MINUTE * DateUtil.MILLIS_PER_FIVE_MINUTE;

SummaryPack p = ServiceSummary.getInstance().getAndClear(SummaryEnum.APP);
if (p != null) {
p.time = time;
DataProxy.send(p);
}
p = ServiceSummary.getInstance().getAndClear(SummaryEnum.SQL);
if (p != null) {
p.time = time;
DataProxy.send(p);
}
p = ServiceSummary.getInstance().getAndClear(SummaryEnum.APICALL);
if (p != null) {
p.time = time;
DataProxy.send(p);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import scouter.lang.pack.ObjectPack;
import scouter.lang.pack.Pack;
import scouter.lang.pack.PerfCounterPack;
import scouter.lang.pack.SummaryPack;
import scouter.lang.pack.TextPack;
import scouter.lang.pack.XLogPack;
import scouter.lang.pack.XLogProfilePack;
Expand Down Expand Up @@ -203,7 +204,10 @@ public static void sendXLog(XLogPack p) {
Logger.info(p.toString());
}
}

public static void send(SummaryPack p) {
p.objHash = conf.objHash;
sendDirect(p);
}
static DataUdpAgent udpNet = DataUdpAgent.getInstance();

public static void sendDirect(Pack p) {
Expand Down
Loading

0 comments on commit 2d356b7

Please sign in to comment.