Skip to content
Merged

Dev #166

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
4 changes: 2 additions & 2 deletions scouter.agent.host/src/scouter/agent/Configure.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public final static synchronized Configure getInstance() {
public int cpu_fatal_history = 3;

//Memory
public boolean mem_alert_enabled = true;
public boolean mem_alert_enabled = false;
public long mem_alert_interval_ms = 30000;
public int mem_warning_pct = 80;
public int mem_fatal_pct = 90;
Expand Down Expand Up @@ -216,7 +216,7 @@ private void apply() {
this.cpu_warning_history = getInt("cpu_warning_history", 3);
this.cpu_fatal_history = getInt("cpu_fatal_history", 3);

this.mem_alert_enabled = getBoolean("mem_alert_enabled", true);
this.mem_alert_enabled = getBoolean("mem_alert_enabled", false);
this.mem_alert_interval_ms = getLong("mem_alert_interval_ms", 30000);
this.mem_warning_pct = getInt("mem_warning_pct", 80);
this.mem_fatal_pct = getInt("mem_fatal_pct", 90);
Expand Down
10 changes: 6 additions & 4 deletions scouter.agent.java/src/scouter/agent/Configure.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ public final static synchronized Configure getInstance() {
public String log_dir ="";
public boolean log_rotation_enabled =true;
public int log_keep_days =7;
public boolean _log_trace_enabled = false;
public boolean _log_trace_use_logger = false;
public boolean _trace = false;
public boolean _trace_use_logger = false;

//Hook
public String hook_args_patterns = "";
Expand All @@ -168,6 +168,7 @@ public final static synchronized Configure getInstance() {
public String hook_method_patterns = "";
public String hook_method_ignore_prefixes = "get,set";
public String hook_method_ignore_classes = "";
public String hook_method_exclude_patterns = "";
private StringSet _hook_method_ignore_classes = new StringSet();
public boolean hook_method_access_public_enabled = true;
public boolean hook_method_access_private_enabled = false;
Expand Down Expand Up @@ -376,6 +377,7 @@ private void apply() {
this.profile_connection_open_enabled = getBoolean("profile_connection_open_enabled", true);
this._summary_connection_leak_fullstack_enabled = getBoolean("_summary_connection_leak_fullstack_enabled", false);
this.hook_method_patterns = getValue("hook_method_patterns", "");
this.hook_method_exclude_patterns = getValue("hook_method_exclude_patterns", "");
this.hook_method_access_public_enabled = getBoolean("hook_method_access_public_enabled", true);
this.hook_method_access_protected_enabled = getBoolean("hook_method_access_protected_enabled", false);
this.hook_method_access_private_enabled = getBoolean("hook_method_access_private_enabled", false);
Expand Down Expand Up @@ -503,8 +505,8 @@ private void apply() {
this.log_dir = getValue("log_dir", "");
this.log_rotation_enabled = getBoolean("log_rotation_enabled", true);
this.log_keep_days = getInt("log_keep_days", 7);
this._log_trace_enabled = getBoolean("_log_trace_enabled", false);
this._log_trace_use_logger = getBoolean("_log_trace_use_logger", false);
this._trace = getBoolean("_trace", false);
this._trace_use_logger = getBoolean("_trace_use_logger", false);

this.enduser_trace_endpoint_url = getValue("enduser_trace_endpoint_url", "_scouter_browser.jsp");
this.enduser_perf_endpoint_hash = HashUtil.hash(this.enduser_trace_endpoint_url);
Expand Down
4 changes: 2 additions & 2 deletions scouter.agent.java/src/scouter/agent/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public static void println(String id, String message, Throwable t) {
}

public static void trace(Object message) {
if(conf._log_trace_enabled) {
if(conf._log_trace_use_logger) {
if(conf._trace) {
if(conf._trace_use_logger) {
println(build("SCOUTER-TRC", toString(message)), true);
} else {
System.out.println(build("SCOUTER-TRC", toString(message)));
Expand Down
27 changes: 22 additions & 5 deletions scouter.agent.java/src/scouter/agent/asm/MethodASM.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,25 @@

package scouter.agent.asm;

import java.util.List;

import scouter.agent.ClassDesc;
import scouter.agent.Configure;
import scouter.agent.asm.util.AsmUtil;
import scouter.agent.asm.util.HookingSet;
import scouter.agent.netio.data.DataProxy;
import scouter.agent.trace.TraceMain;
import scouter.org.objectweb.asm.*;
import scouter.org.objectweb.asm.ClassVisitor;
import scouter.org.objectweb.asm.Label;
import scouter.org.objectweb.asm.MethodVisitor;
import scouter.org.objectweb.asm.Opcodes;
import scouter.org.objectweb.asm.Type;
import scouter.org.objectweb.asm.commons.LocalVariablesSorter;

import java.util.List;

public class MethodASM implements IASM, Opcodes {

private List<HookingSet> target = HookingSet.getHookingMethodSet(Configure.getInstance().hook_method_patterns);
private List<HookingSet> excludeTarget = HookingSet.getHookingMethodSet(Configure.getInstance().hook_method_exclude_patterns);

Configure conf = Configure.getInstance();

Expand All @@ -47,7 +52,7 @@ public ClassVisitor transform(ClassVisitor cv, String className, ClassDesc class
for (int i = 0; i < target.size(); i++) {
HookingSet mset = target.get(i);
if (mset.classMatch.include(className)) {
return new MethodCV(cv, mset, className);
return new MethodCV(cv, mset, excludeTarget, className);
}
}
return cv;
Expand All @@ -58,10 +63,12 @@ class MethodCV extends ClassVisitor implements Opcodes {

public String className;
private HookingSet mset;
private List<HookingSet> excludeTarget;

public MethodCV(ClassVisitor cv, HookingSet mset, String className) {
public MethodCV(ClassVisitor cv, HookingSet mset, List<HookingSet> excludeTarget, String className) {
super(ASM4, cv);
this.mset = mset;
this.excludeTarget = excludeTarget;
this.className = className;
}

Expand All @@ -74,6 +81,16 @@ public MethodVisitor visitMethod(int access, String name, String desc, String si
if (AsmUtil.isSpecial(name)) {
return mv;
}

// check exclude method set
for (int i = 0; i < excludeTarget.size(); i++) {
HookingSet excludeSet = excludeTarget.get(i);
if (excludeSet.classMatch.include(className)) {
if (excludeSet.isA(name, desc)) {
return mv;
}
}
}

Configure conf = Configure.getInstance();
boolean isPublic = conf.hook_method_access_public_enabled;
Expand Down
8 changes: 4 additions & 4 deletions scouter.agent.java/src/scouter/agent/asm/util/HookingSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public int get(String method, String desc) {

public static Map<String, HookingSet> getHookingSet(String arg) {
String[] c = StringUtil.split(arg, ',');
Map<String, HookingSet> classSet = new HashMap<String, HookingSet>();
Map<String, HookingSet> classMap = new HashMap<String, HookingSet>();
for (int i = 0; i < c.length; i++) {
String s = c[i];
int x = s.lastIndexOf(".");
Expand All @@ -88,14 +88,14 @@ public static Map<String, HookingSet> getHookingSet(String arg) {
String cname = s.substring(0, x).replace('.', '/');
String mname = s.substring(x + 1);

HookingSet methodSet = classSet.get(cname);
HookingSet methodSet = classMap.get(cname);
if (methodSet == null) {
methodSet = new HookingSet();
classSet.put(cname, methodSet);
classMap.put(cname, methodSet);
}
methodSet.add(mname);
}
return classSet;
return classMap;
}

public static List<HookingSet> getHookingMethodSet(String patterns) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
public class ServicePerf {

private MeterResource activeCounter = new MeterResource();
private Configure conf = Configure.getInstance();

@Counter
public void getServicePerf(CounterBasket pw) {
Expand Down Expand Up @@ -108,6 +109,11 @@ public void getServicePerf(CounterBasket pw) {
public void summay(CounterBasket pw) {
long time = System.currentTimeMillis();
long now = DateUtil.getMinUnit(time) / 5;

if(conf.getBoolean("_dev_summary_test", false)) {
now = time / 1000 / 15;
}

if (now == last_sent)
return;
last_sent = now;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.management.MBeanServer;
import javax.management.ObjectName;

import scouter.agent.Configure;
import scouter.agent.Logger;
import scouter.agent.ObjTypeDetector;
Expand Down Expand Up @@ -85,7 +87,6 @@ public boolean equals(Object obj) {
}
}
private MBeanServer server;
private String version;
List<MBeanObj> beanList = new ArrayList<MBeanObj>();
public long collectCnt = 0;
@Counter
Expand Down Expand Up @@ -147,18 +148,6 @@ private void getMBeanList() {
if (type == null) {
continue;
}
if (StringUtil.isEmpty(version) && "Server".equals(type)) { // Server
// Bean
try {
Object value = server.getAttribute(mbean, "serverInfo");
if (value != null) {
version = value.toString().split("/")[1];
Logger.println("Tomcat version = " + version);
}
} catch (Exception e) {
e.printStackTrace();
}
}
if ("GlobalRequestProcessor".equals(type)) {
String port = mbean.getKeyProperty("name");
try {
Expand Down
2 changes: 1 addition & 1 deletion scouter.agent.java/src/scouter/agent/trace/TraceSQL.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public static void end(Object stat, Throwable thr, int updatedCount) {
LocalContext lCtx = (LocalContext) stat;
TraceContext tCtx = lCtx.context;

Logger.trace("affected row = " + updatedCount);
//Logger.trace("affected row = " + updatedCount);

SqlStep3 step = (SqlStep3) lCtx.stepSingle;
tCtx.lastSqlStep = step;
Expand Down
2 changes: 1 addition & 1 deletion scouter.agent.java/src/scouter/agent/util/AsyncRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private void alert(LeakInfo2 leakInfo2) {
}
DataProxy.sendAlert(AlertLevel.WARN, "CONNECTION_NOT_CLOSE", "Connection may not closed", mv);

if(conf._log_trace_enabled) Logger.trace("[Force-Close-InnerObject]" + System.identityHashCode(leakInfo2.innerObject));
if(conf._trace) Logger.trace("[Force-Close-InnerObject]" + System.identityHashCode(leakInfo2.innerObject));

boolean closeResult = leakInfo2.closeManager.close(leakInfo2.innerObject);
//Logger.println("G003", "connection auto closed:" + closeResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import scouter.Version;
import scouter.client.net.LoginMgr;
import scouter.client.net.LoginResult;
import scouter.client.popup.LoginDialog;
import scouter.client.popup.LoginDialog.ILoginDialog;
import scouter.client.preferences.PreferenceConstants;
Expand Down Expand Up @@ -119,8 +120,8 @@ public void preWindowOpen() {
if (index > -1) {
String id = accountInfo.substring(0, index);
String pwd = accountInfo.substring(index + 1, accountInfo.length());
boolean result = LoginMgr.silentLogin(server, id, pwd);
if (result) {
LoginResult result = LoginMgr.silentLogin(server, id, pwd);
if (result.success) {
autoLogined = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@
import org.eclipse.jface.action.Action;
import org.eclipse.swt.widgets.Display;

import scouter.client.Images;
import scouter.client.net.LoginMgr;
import scouter.client.net.LoginResult;
import scouter.client.popup.LoginDialog;
import scouter.client.server.Server;
import scouter.client.server.ServerManager;
import scouter.client.util.ConsoleProxy;
import scouter.client.util.ImageUtil;
import scouter.util.StringUtil;


Expand All @@ -44,9 +43,9 @@ public OpenServerAction(int serverId) {
public void run() {
Server server = ServerManager.getInstance().getServer(serverId);
if (StringUtil.isNotEmpty(server.getUserId()) && StringUtil.isNotEmpty(server.getPassword())) {
boolean result = LoginMgr.silentLogin(server, server.getUserId(), server.getPassword());
if (result == false) {
ConsoleProxy.errorSafe("Failed opening server");
LoginResult result = LoginMgr.silentLogin(server, server.getUserId(), server.getPassword());
if (result.success == false) {
ConsoleProxy.errorSafe(result.getErrorMessage());
}
} else {
LoginDialog dialog = new LoginDialog(Display.getDefault(), null, LoginDialog.TYPE_OPEN_SERVER, server.getIp() + ":" + server.getPort());
Expand Down
23 changes: 15 additions & 8 deletions scouter.client/src/scouter/client/net/LoginMgr.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@
import scouter.util.SysJMX;

public class LoginMgr{
public static boolean login(int serverId, String user, String password){
public static LoginResult login(int serverId, String user, String password){
Server server = ServerManager.getInstance().getServer(serverId);
String encrypted = CipherUtil.md5(password);
String encrypted = CipherUtil.sha256(password);
return silentLogin(server, user, encrypted);
}

public static boolean silentLogin(Server server, String user, String encryptedPwd){
public static LoginResult silentLogin(Server server, String user, String encryptedPwd){
LoginResult result = new LoginResult();
try {
MapPack param = new MapPack();
param.put("id", user);
Expand All @@ -46,12 +47,16 @@ public static boolean silentLogin(Server server, String user, String encryptedPw
param.put("hostname", SysJMX.getHostName());

MapPack out = TcpProxy.loginProxy(server.getId(), param);

if (out != null) {
if (out == null) {
result.success = false;
result.errorMessage = "Network connection failed";
} else {
long session = out.getLong("session");
String error = out.getText("error");
if(error != null && session == 0L){
return false;
result.success = false;
result.errorMessage = "Authentication failed";
return result;
}
server.setOpen(true);
long time = out.getLong("time");
Expand Down Expand Up @@ -93,12 +98,14 @@ public static boolean silentLogin(Server server, String user, String encryptedPw
counterEngine.parse(((BlobValue)v1).value);
}
}
return true;
result.success = true;
}
} catch(Exception e){
e.printStackTrace();
result.success = false;
result.errorMessage = "Network connection failed : " + e.getMessage();
}
return false;
return result;
}

public static MapPack getCounterXmlServer(int serverId) {
Expand Down
17 changes: 17 additions & 0 deletions scouter.client/src/scouter/client/net/LoginResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package scouter.client.net;

import scouter.util.StringUtil;

public class LoginResult {

public boolean success;
public String errorMessage;

public String getErrorMessage() {
if (!success && StringUtil.isEmpty(errorMessage)) {
return "Failure to unknown causes";
}
return errorMessage;
}

}
4 changes: 2 additions & 2 deletions scouter.client/src/scouter/client/popup/AccountDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public void run() {
try {
MapPack param = new MapPack();
param.put("id", id);
param.put("pass", CipherUtil.md5(password));
param.put("pass", CipherUtil.sha256(password));
param.put("email", email);
param.put("group", selectedGroup);
MapPack p = (MapPack) tcp.getSingle(RequestCmd.ADD_ACCOUNT, param);
Expand Down Expand Up @@ -355,7 +355,7 @@ public void run() {
try {
MapPack param = new MapPack();
param.put("id", id);
param.put("pass", CipherUtil.md5(password));
param.put("pass", CipherUtil.sha256(password));
param.put("email", email);
param.put("group", selectedGroup);
MapPack p = (MapPack) tcp.getSingle(RequestCmd.EDIT_ACCOUNT, param);
Expand Down
Loading