Skip to content

Commit

Permalink
Merge pull request scouter-project#226 from scouter-project/master
Browse files Browse the repository at this point in the history
Merge for release
  • Loading branch information
bill23-kim authored Aug 15, 2016
2 parents 01a8e5b + df101b2 commit 50b293c
Show file tree
Hide file tree
Showing 93 changed files with 4,271 additions and 391 deletions.
127 changes: 121 additions & 6 deletions scouter.agent.batch/src/scouter/agent/batch/Configure.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,21 @@
import java.util.Map;
import java.util.Properties;


import scouter.agent.util.JarUtil;
import scouter.lang.conf.ConfigDesc;
import scouter.lang.conf.ConfigValueUtil;
import scouter.lang.counters.CounterConstants;
import scouter.lang.value.ListValue;
import scouter.lang.value.MapValue;
import scouter.net.NetConstants;
import scouter.util.FileUtil;
import scouter.util.HashUtil;
import scouter.util.StringEnumer;
import scouter.util.StringKeyLinkedMap;
import scouter.util.StringSet;
import scouter.util.StringUtil;
import scouter.util.SysJMX;
import scouter.util.SystemUtil;

public class Configure {
public static final String CONFIG_SCOUTER_ENABLED = "scouter_enabled";
Expand All @@ -45,7 +53,12 @@ public class Configure {
private File propertyFile;
public static String agent_dir_path;
static {
agent_dir_path = JarUtil.getThisJarFile().getParent();
File jarFile = JarUtil.getThisJarFile();
if(jarFile != null){
agent_dir_path = jarFile.getParent();
}else{
agent_dir_path = new File(".").getAbsolutePath();
}
}

public final static synchronized Configure getInstance() {
Expand All @@ -56,62 +69,102 @@ public final static synchronized Configure getInstance() {
}

// Scouter enable/disable
@ConfigDesc("Enable scouter monitor")
public boolean scouter_enabled = true;
public boolean scouter_stop = false;

// Standalone
@ConfigDesc("Standalone mode")
public boolean scouter_standalone = false;

// Batch basic configuration
@ConfigDesc("Batch ID type(class,args, props)")
public String batch_id_type = ""; // Class, Args, Props
@ConfigDesc("Batch ID(args-index number, props-key string)")
public String batch_id = "";

// SQL
@ConfigDesc("Collect sql statistics")
public boolean sql_enabled = true;
@ConfigDesc("SQL max count")
public int sql_max_count = 100;
@ConfigDesc("Method set for preparestatement hooking")
public String hook_jdbc_pstmt_classes = "";
@ConfigDesc("Method set for statement hooking")
public String hook_jdbc_stmt_classes = "";
@ConfigDesc("Method set for resultset hooking")
public String hook_jdbc_rs_classes = "";

// SFA(Stack Frequency Analyzer) Thread Dump
@ConfigDesc("Stack dump collector")
public boolean sfa_dump_enabled = true;
@ConfigDesc("Stack dump interval(ms)")
public int sfa_dump_interval_ms = 10000;
@ConfigDesc("Stack dump filter(,)")
public String [] sfa_dump_filter = null;
@ConfigDesc("Stack dump directory")
public File sfa_dump_dir = new File(agent_dir_path + "/dump");
@ConfigDesc("Add Stack dump header")
public boolean sfa_dump_header_exists = true;

// dump send time
@ConfigDesc("Collector IP")
public long dump_send_elapsed_ms = 0L;

//Network
@ConfigDesc("Collector IP")
public String net_collector_ip = "127.0.0.1";
@ConfigDesc("Collector UDP Port")
public int net_collector_udp_port = NetConstants.SERVER_UDP_PORT;
@ConfigDesc("Collector TCP Port")
public int net_collector_tcp_port = NetConstants.SERVER_TCP_PORT;
@ConfigDesc("Collector TCP Session Count")
public int net_collector_tcp_session_count = 1;
@ConfigDesc("Collector TCP Socket Timeout(ms)")
public int net_collector_tcp_so_timeout_ms = 60000;
@ConfigDesc("Collector TCP Connection Timeout(ms)")
public int net_collector_tcp_connection_timeout_ms = 3000;
@ConfigDesc("Local UDP Port")
public int net_local_udp_port = NetConstants.LOCAL_UDP_PORT;
@ConfigDesc("UDP Buffer Size")
public int net_udp_packet_max_bytes = 60000;
@ConfigDesc("UDP Collection Interval(ms)")
public long net_udp_collection_interval_ms = 100;

@ConfigDesc("Stack Log TCP Session Count")
public int net_tcp_stack_session_count = 1;

//Object
public String obj_type = "batch";
@ConfigDesc("Object Type")
public String obj_type = CounterConstants.BATCH;
@ConfigDesc("Object Name")
public String obj_name = "";
@ConfigDesc("Host Type")
public String obj_host_type = "";
@ConfigDesc("Host Name")
public String obj_host_name = "";
@ConfigDesc("Activating for using object name as PID")
public boolean obj_name_auto_pid_enabled = false;
@ConfigDesc("Redefining DS, RP type according to main object")
public boolean obj_type_inherit_to_child_enabled = false;

//Dir
@ConfigDesc("Plugin directory")
public File plugin_dir = new File(agent_dir_path + "/plugin");
//public File mgr_agent_lib_dir = new File("./_scouter_");

//Log
@ConfigDesc("")
public boolean _log_asm_enabled;

@ConfigDesc("Log directory")
public String log_dir ="";
@ConfigDesc("Retaining log according to date")
public boolean log_rotation_enabled =true;
@ConfigDesc("Keeping period of log")
public int log_keep_days =7;
@ConfigDesc("")
public boolean _trace = false;
@ConfigDesc("")
public boolean _trace_use_logger = false;

//internal variables
Expand All @@ -136,6 +189,9 @@ private Configure() {
reload();
}

private Configure(boolean b) {
}

public File getPropertyFile() {
if (propertyFile != null) {
return propertyFile;
Expand Down Expand Up @@ -189,8 +245,6 @@ private void apply() {
}else if("props".equals(this.batch_id_type)){
this.batch_id = getValue("batch_id", "JobId");
}
this.obj_name = getValue("obj_name", "batch");
// end for batch

// SQL
this.sql_max_count = getInt("sql_max_count", 100);
Expand Down Expand Up @@ -257,6 +311,9 @@ private void apply() {
this.net_collector_tcp_connection_timeout_ms = getInt("net_collector_tcp_connection_timeout_ms", 3000);
this.net_collector_tcp_so_timeout_ms = getInt("net_collector_tcp_so_timeout_ms", 60000);

this.net_local_udp_port = getInt("net_local_udp_port", NetConstants.LOCAL_UDP_PORT);
this.net_tcp_stack_session_count = getInt("net_tcp_stack_session_count", 1);


this.sql_enabled = getBoolean("sql_enabled", true);
this.hook_jdbc_pstmt_classes = getValue("hook_jdbc_pstmt_classes", "");
Expand All @@ -274,6 +331,7 @@ private void apply() {
this._trace_use_logger = getBoolean("_trace_use_logger", false);
this.log_ignore_set = getStringSet("mgr_log_ignore_ids", ",");

resetObjInfo();
}

public int getObjHash() {
Expand All @@ -296,6 +354,37 @@ public boolean isIgnoreLog(String id) {
return log_ignore_set.hasKey(id);
}


public synchronized void resetObjInfo() {
this.obj_type = getValue("obj_type", CounterConstants.BATCH);
String detected = CounterConstants.HOST;
if (SystemUtil.IS_LINUX) {
detected = CounterConstants.LINUX;
} else if (SystemUtil.IS_WINDOWS) {
detected = CounterConstants.WINDOWS;
} else if (SystemUtil.IS_MAC_OSX) {
detected = CounterConstants.OSX;
} else if (SystemUtil.IS_AIX) {
detected = CounterConstants.AIX;
} else if (SystemUtil.IS_HP_UX) {
detected = CounterConstants.HPUX;
}
this.obj_host_type = getValue("obj_host_type", detected);
this.obj_host_name = getValue("obj_host_name", SysJMX.getHostName());
this.objHostName = "/" + this.obj_host_name;
this.objHostHash = HashUtil.hash(this.objHostName);
this.obj_name_auto_pid_enabled = getBoolean("obj_name_auto_pid_enabled", false);

this.obj_name = getValue("obj_name", "batch");
this.objName = this.objHostName + "/" + this.obj_name;
// make hash value
try { this.objHash = HashUtil.hash( objName.getBytes("UTF-8")); }catch(Throwable ex){}

System.setProperty("scouter.objname", this.objName);
System.setProperty("scouter.objtype", this.obj_type);
System.setProperty("scouter.dir", agent_dir_path);
}

private StringSet getStringSet(String key, String deli) {
StringSet set = new StringSet();
String v = getValue(key);
Expand Down Expand Up @@ -382,12 +471,38 @@ public boolean saveText(String text) {
}
return false;
}

public void printConfig() {
Logger.info("Configure -Dscouter.config=" + propertyFile);
}

public MapValue getKeyValueInfo() {
StringKeyLinkedMap<Object> defMap = ConfigValueUtil.getConfigDefault(new Configure(true));
StringKeyLinkedMap<Object> curMap = ConfigValueUtil.getConfigDefault(this);
MapValue m = new MapValue();
ListValue nameList = m.newList("key");
ListValue valueList = m.newList("value");
ListValue defList = m.newList("default");
StringEnumer enu = defMap.keys();
while (enu.hasMoreElements()) {
String key = enu.nextString();
if (ignoreSet.contains(key))
continue;
nameList.add(key);
valueList.add(ConfigValueUtil.toValue(curMap.get(key)));
defList.add(ConfigValueUtil.toValue(defMap.get(key)));
}
return m;
}

public StringKeyLinkedMap<String> getConfigureDesc() {
return ConfigValueUtil.getConfigDescMap(this);
}

private static HashSet<String> ignoreSet = new HashSet<String>();
static {
ignoreSet.add("property");
ignoreSet.add("__experimental");
}

}
1 change: 1 addition & 0 deletions scouter.agent.batch/src/scouter/agent/batch/JavaAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import scouter.util.logo.Logo;
import scouter.agent.batch.AgentTransformer;
import scouter.agent.batch.task.BatchMonitor;

public class JavaAgent {
private static Instrumentation instrumentation;
Expand Down
6 changes: 4 additions & 2 deletions scouter.agent.batch/src/scouter/agent/batch/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,15 @@ private static synchronized void openFile(String prefix) throws IOException {
return;
}

String name = prefix + ((conf.batch_id == null)?"batch":conf.batch_id + "_" + SysJMX.getProcessPID());

if (conf.log_rotation_enabled) {
File file = new File(conf.log_dir, "scouter-" + prefix + "-" + DateUtil.yyyymmdd() + ".log");
File file = new File(conf.log_dir, "scouter-" + name + "-" + DateUtil.yyyymmdd() + ".log");
FileWriter fw = new FileWriter(file, true);
pw = new PrintWriter(fw);
logfile = file;
} else {
File file = new File(conf.log_dir, "scouter-" + prefix + ".log");
File file = new File(conf.log_dir, "scouter-" + name + ".log");
pw = new PrintWriter(new FileWriter(file, true));
logfile = file;
}
Expand Down
66 changes: 66 additions & 0 deletions scouter.agent.batch/src/scouter/agent/batch/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package scouter.agent.batch;

import java.io.File;

import scouter.Version;
import scouter.agent.batch.netio.data.net.UdpAgent;
import scouter.agent.batch.netio.data.net.UdpLocalServer;
import scouter.agent.batch.netio.request.ReqestHandlingProxy;
import scouter.agent.batch.netio.service.net.TcpRequestMgr;
import scouter.lang.pack.ObjectPack;
import scouter.util.SysJMX;
import scouter.util.ThreadUtil;
import scouter.util.logo.Logo;

public class Main {
public static void main(String[] args) {
Logo.print(true);
System.out.println("Scouter Batch Agent Version " + Version.getServerFullVersion());
Logger.println("A01", "Scouter Batch Agent Version " + Version.getServerFullVersion());

ReqestHandlingProxy.load(ReqestHandlingProxy.class);
UdpLocalServer.getInstance();
TcpRequestMgr.getInstance();

File exit = new File(SysJMX.getProcessPID() + ".scouter");
try {
exit.createNewFile();
} catch (Exception e) {
String tmp = System.getProperty("user.home", "/tmp");
exit = new File(tmp, SysJMX.getProcessPID() + ".scouter.run");
try {
exit.createNewFile();
} catch (Exception k) {
System.exit(1);
}
}
exit.deleteOnExit();
System.out.println("System JRE version : " + System.getProperty("java.version"));
long startTime = System.currentTimeMillis();
long currentTime;
while (true) {
currentTime = System.currentTimeMillis();
if((currentTime - startTime) >= 10000){
UdpAgent.sendUdpPack(getObjectPack());
startTime = currentTime;
}
if (exit.exists() == false) {
System.exit(0);
}
ThreadUtil.sleep(1000);

}

}

static public ObjectPack getObjectPack(){
Configure conf = Configure.getInstance();
ObjectPack pack = new ObjectPack();
pack.alive = true;
pack.objHash = conf.getObjHash();
pack.objName = conf.getObjName();
pack.objType = conf.obj_type;
pack.version = Version.getAgentFullVersion();
return pack;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void visitInsn(int opcode) {
mv.visitVarInsn(Opcodes.ILOAD, lvPosReturn);
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, TRACESQL, ADD_METHOD, ADD_SIGNATURE,false);
break;
/* case Type.BOOLEAN:
/* case Type.BOOLEAN:
lvPosReturn = newLocal(returnType);
mv.visitVarInsn(Opcodes.ISTORE, lvPosReturn);
mv.visitVarInsn(ALOAD, 0);
Expand All @@ -106,17 +106,17 @@ public void visitInsn(int opcode) {
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, TRACESQL, ADD_METHOD, ADD_SIGNATURE,false);
mv.visitVarInsn(Opcodes.ILOAD, lvPosReturn);
break;*/
default:
}

// Return 결과 셋팅
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, owner, TraceSQL.CURRENT_TRACESQL_FIELD, "Lscouter/agent/batch/trace/TraceSQL;");
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, TRACESQL, END_METHOD, END_SIGNATURE,false);
}

mv.visitInsn(opcode);
}

@Override
public void visitMaxs(int maxStack, int maxLocals) {
Label endFinally = new Label();
Expand All @@ -134,13 +134,11 @@ public void visitMaxs(int maxStack, int maxLocals) {

mv.visitMaxs(maxStack + 8, maxLocals + 2);
}

public static void main(String[] args) {
Type type = Type.getReturnType("(Z)[I");
System.out.println("type = " + type.getSort());
System.out.println("dim = " + type.getDimensions());
System.out.println("element = " + type.getElementType());

}

}
Loading

0 comments on commit 50b293c

Please sign in to comment.