Skip to content

Commit

Permalink
Merge pull request #10 from uavorg/master
Browse files Browse the repository at this point in the history
merge master
  • Loading branch information
BeliefYou8 committed Jun 14, 2018
2 parents fa8a2b4 + ec99cbf commit 73f6259
Show file tree
Hide file tree
Showing 22 changed files with 605 additions and 93 deletions.
14 changes: 13 additions & 1 deletion com.creditease.uav.agent.buildComponent/bin/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ do
done
fi

JAVA_VERSION=`java -version 2>&1 |awk 'NR==1{ gsub(/"/,""); print $3 }'`
if [[ ${JAVA_VERSION:0:1} -eq "9" ]];then
export JRE_HOME=$JAVA_HOME
fi

echo "using $executeJava"

netcardIndex=
Expand All @@ -46,7 +51,14 @@ cd ..
export CLASSPATH=bin/com.creditease.uav.base-1.0-boot.jar
echo $CLASSPATH
javaAgent="-javaagent:../uavmof/com.creditease.uav.agent/com.creditease.uav.monitorframework.agent-1.0-agent.jar"
javaOpts="-server -Xms64m -Xmx256m -Xss256k -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:+CMSIncrementalPacing -XX:CMSIncrementalDutyCycleMin=0 -XX:CMSIncrementalDutyCycle=10 -XX:+UseParNewGC -XX:+UseCMSCompactAtFullCollection -XX:-CMSParallelRemarkEnabled -XX:CMSFullGCsBeforeCompaction=0 -XX:CMSInitiatingOccupancyFraction=70 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=."

if [[ ${JAVA_VERSION:0:1} -eq "9" ]];then
javaOpts="-server -Xms64m -Xmx256m -Xss256k -Djdk.attach.allowAttachSelf=true -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=."
else
javaOpts="-server -Xms64m -Xmx256m -Xss256k -XX:-UseSplitVerifier -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:+CMSIncrementalPacing -XX:CMSIncrementalDutyCycleMin=0 -XX:CMSIncrementalDutyCycle=10 -XX:+UseParNewGC -XX:+UseCMSCompactAtFullCollection -XX:-CMSParallelRemarkEnabled -XX:CMSFullGCsBeforeCompaction=0 -XX:CMSInitiatingOccupancyFraction=70 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=."
fi
#javaOpts="-server -Xms64m -Xmx256m -Xss256k -XX:-UseSplitVerifier -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:+CMSIncrementalPacing -XX:CMSIncrementalDutyCycleMin=0 -XX:CMSIncrementalDutyCycle=10 -XX:+UseParNewGC -XX:+UseCMSCompactAtFullCollection -XX:-CMSParallelRemarkEnabled -XX:CMSFullGCsBeforeCompaction=0 -XX:CMSInitiatingOccupancyFraction=70 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=."

$executeJava $javaAgent $javaOpts -XX:OnOutOfMemoryError='kill -9 %p' -DNetCardIndex=$netcardIndex -DNetCardName=$netcardName -DJAppID=$2 -DJAppGroup=UAV -classpath $CLASSPATH com.creditease.mscp.boot.MSCPBoot -p $1 &

# add crontab process watcher
Expand Down
15 changes: 14 additions & 1 deletion com.creditease.uav.agent.buildComponent/bin/start.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
:: The second param is JAppID, if not set, the default value is 'MonitorAgent'
@echo off

title=UAV
set profile=agent
if not [%1] == [] set profile=%1

Expand All @@ -18,5 +19,17 @@ if not exist C:\Windows\System32\drivers\npf.sys (move lib\npf.sys C:\Windows\Sy

set CLASSPATH=bin/com.creditease.uav.base-1.0-boot.jar
set javaAgent="-javaagent:../uavmof/com.creditease.uav.agent/com.creditease.uav.monitorframework.agent-1.0-agent.jar"
set javaOpts=-server -Xms64m -Xmx256m -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:+CMSIncrementalPacing -XX:CMSIncrementalDutyCycleMin=0 -XX:CMSIncrementalDutyCycle=10 -XX:+UseParNewGC

java -version 2>java.version
for /f "tokens=3 delims= " %%i in (java.version) do (
set FLAG=%%i
goto :next
)
:next
set JAVA_VERSION=%FLAG:~1,-1%
set JudgeFlag=%JAVA_VERSION:~0,2%
if "%JudgeFlag%" == "9." (
set javaOpts=-server -Xms64m -Xmx256m -Djdk.attach.allowAttachSelf=true -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=.) else (
set javaOpts=-server -Xms64m -Xmx256m -XX:-UseSplitVerifier -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:+CMSIncrementalPacing -XX:CMSIncrementalDutyCycleMin=0 -XX:CMSIncrementalDutyCycle=10 -XX:+UseParNewGC)

%executeJava% %javaAgent% %javaOpts% -Djava.library.path=./lib -DNetCardIndex=0 -DJAppID=%appID% -DJAppGroup=UAV -classpath "%CLASSPATH%" com.creditease.mscp.boot.MSCPBoot -p %profile%
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ public void run() {

long timeFlag = (System.currentTimeMillis() / 10) * 10;

String pid = this.cName.substring("MO-".length() > this.cName.length() ? 0 : 3);
// get all monitor's MBean
MonitorDataFrame mdf = new MonitorDataFrame(this.getWorkerId(), "M", timeFlag);

mdf.addExt("pid", pid);

needProcessCheck = doCaptureMonitorData(timeFlag, mdf);

// if needProcessCheck is still true, need see if the appserver is still alive
Expand All @@ -121,7 +123,8 @@ public void run() {

// get all profile's MBean
MonitorDataFrame pmdf = new MonitorDataFrame(this.getWorkerId(), "P", timeFlag);

pmdf.addExt("pid", pid);

needProcessCheck = doCaptureProfileData(timeFlag, pmdf);

// if needProcessCheck is still true, need see if the appserver is still alive
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,12 @@ public void run() {

long timeFlag = (System.currentTimeMillis() / 10) * 10;

String pid = this.cName.substring("MO-".length() > this.cName.length() ? 0 : 3);

// get all monitor's MBean
MonitorDataFrame mdf = new MonitorDataFrame(this.getWorkerId(), "M", timeFlag);

mdf.addExt("pid", pid);

needProcessCheck = doCaptureMonitorData(mbsc, timeFlag, mdf);

// if needProcessCheck is still true, need see if the appserver is still alive
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ private String getJSEURL() {
private void doCaptureProfileData(long timeFlag) {

MonitorDataFrame pmdf = new MonitorDataFrame(this.getWorkerId(), "P", timeFlag);
pmdf.addExt("pid", this.cName.substring("MO-".length() > this.cName.length() ? 0 : 3));

if (state.getProfileTimestamp() == 0) {
state.setProfileTimestamp(System.currentTimeMillis());
Expand Down Expand Up @@ -637,12 +638,13 @@ private boolean doCaptureMonitorData(long timeFlag, MBeanServerConnection mbsc)

// build MDF
MonitorDataFrame mdf = new MonitorDataFrame(this.getWorkerId(), "M", timeFlag);
mdf.addExt("pid", this.cName.substring("MO-".length() > this.cName.length() ? 0 : 3));

mdf.addData("server", smr.toJSONString());

// add appgroup to MDF
mdf.addExt("appgroup", this.getAppGroup());

/**
* if there is data, we handle MDF using monitor data handler to process the monitor data
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,28 @@ public void handle(MonitorDataFrame profileData) {
DetectorManager asmd = (DetectorManager) this.getConfigManager().getComponent(this.feature,
"AppServerMonitorDetector_TimerWorker");

if (null != afc && null != asmd) {
if (afc == null || asmd == null) {

JVMAgentInfo jvmAgentInfo = asmd.getJVMAgentInfo(profileData.getServerId());
log.warn(this, "can't find agent feature component [logagent], this feature may not start. LogAgent-null("
+ (afc == null) + "), DetectorManager-null(" + (asmd == null) + ")");

return;
}

JVMAgentInfo jvmAgentInfo = asmd.getJVMAgentInfo(profileData.getServerId());

if (null == jvmAgentInfo) {
log.warn(this, "can't find jvm agent info for serverid [" + profileData.getServerId()
+ "], the jvm may be dead.");
return;
}
if (jvmAgentInfo == null) {

afc.exchange("logagent.profiledata.notify", profileData, jvmAgentInfo);
jvmAgentInfo = asmd.getJVMAgentInfo("MO-" + profileData.getExt("pid"));
}
else {
log.warn(this, "can't find agent feature component [logagent], this feature may not start. LogAgent-null("
+ (afc == null) + "), DetectorManager-null(" + (asmd == null) + ")");

if (jvmAgentInfo == null) {

log.warn(this,
"can't find jvm agent info for serverid [" + profileData.getServerId() + "], the jvm may be dead.");
return;
}

afc.exchange("logagent.profiledata.notify", profileData, jvmAgentInfo);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,16 @@ public List<Map<String, String>> getUserByQuery(String email) {

String userQueryField = ldapConfig.get("userQueryField");

String email1 = email + suffix;

String filter = "(|(" + userCNField + "=" + email + ")(" + userQueryField + "=" + email + ")(" + userQueryField
+ "=" + email1 + "))";
String email1=email.indexOf("@") >0?email:email+suffix;

String primaryKey = ldapConfig.get("primaryKey");

/**
* "|"或 聚集操作
* primaryKey 采用userPrincipalName字段查询 带后缀的账号
* userCNField CN中文名查询
*/
String filter = "(|("+primaryKey + "=" +email1+")(" + userCNField + "=" + email + "))";

/**
* 查询ldap 获取list信息
Expand Down Expand Up @@ -353,6 +359,10 @@ public Map<String, Object> getEmailListByQuery(String email) {

List<SearchResult> sResultList = ldapApiQuery("", filter);
// filter 只能查询到一个结果
if (sResultList.isEmpty()) {
result.put("msg", "result is empty.");
return result;
}
SearchResult sResult = sResultList.get(0);
if (null == sResult) {
result.put("msg", "emailList query,result is empty.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public class JVMToolHelper {
private static Method method_VMId;
private static Method method_GetSystemProperties;
private static Method method_LoadAgent;
private static Method method_StartLocalManagementAgent;

private static Class<?> hostIdentifierClass;
private static Class<?> monitoredVmClass;
Expand Down Expand Up @@ -263,10 +264,18 @@ private static void startVMAgent(Object vm) {
if (jvmProperties.get(JMX_CONNECTOR_ADDRESS) == null) {

Properties systemProperties = (Properties) method_GetSystemProperties.invoke(vm, (Object[]) null);

String agent = systemProperties.getProperty("java.home") + File.separator + "lib" + File.separator
+ "management-agent.jar";
method_LoadAgent.invoke(vm, new Object[] { agent });
String jversion = (String) systemProperties.get("java.version");
if(null != jversion && jversion.startsWith("9.")){

if(null == method_StartLocalManagementAgent ) {
return;
}
method_StartLocalManagementAgent.invoke(vm, (Object[]) null);
}else {
String agent = systemProperties.getProperty("java.home") + File.separator + "lib" + File.separator
+ "management-agent.jar";
method_LoadAgent.invoke(vm, new Object[] { agent });
}
}
}
catch (Exception e) {
Expand All @@ -277,6 +286,7 @@ private static void startVMAgent(Object vm) {
private static void initJVMToolJarClassLoader() {

String javaHome = System.getProperty("java.home");
String javaVersion = System.getProperty("java.version");

String tools = javaHome + File.separator + ".." + File.separator + "lib" + File.separator + "tools.jar";

Expand All @@ -298,7 +308,10 @@ private static void initJVMToolJarClassLoader() {
method_VMId = virtualMachineDescriptor.getMethod("id", (Class[]) null);
method_GetSystemProperties = virtualMachine.getMethod("getSystemProperties", (Class[]) null);
method_LoadAgent = virtualMachine.getMethod("loadAgent", new Class[] { String.class });

if(null != javaVersion && javaVersion.startsWith("9.")) {
method_StartLocalManagementAgent = virtualMachine.getMethod("startLocalManagementAgent", (Class[]) null);
}

// java process
hostIdentifierClass = JVMToolClassloader.loadClass("sun.jvmstat.monitor.HostIdentifier");
monitoredVmClass = JVMToolClassloader.loadClass("sun.jvmstat.monitor.MonitoredVm");
Expand Down Expand Up @@ -443,14 +456,18 @@ public static String getLineSeperator() {
minorGC.add("Garbage collection optimized for throughput Young Collector");
// -XgcPrio:deterministic
minorGC.add("Garbage collection optimized for deterministic pausetimes Young Collector");

// -XX:+UseG1GC
minorGC.add("G1 Young Generation");

// Oracle (Sun) HotSpot
// -XX:+UseSerialGC
fullGC.add("MarkSweepCompact");
// -XX:+UseParallelGC and (-XX:+UseParallelOldGC or -XX:+UseParallelOldGCCompacting)
fullGC.add("PS MarkSweep");
// -XX:+UseConcMarkSweepGC
fullGC.add("ConcurrentMarkSweep");
// -XX:+UseG1GC
fullGC.add("G1 Old Generation");

// Oracle (BEA) JRockit
// -XgcPrio:pausetime
Expand Down Expand Up @@ -533,7 +550,7 @@ public static Map<String, Long> readHeapPoolUsage(List<MemoryPoolMXBean> pmbList

Map<String, Long> m = new LinkedHashMap<String, Long>();

for (MemoryPoolMXBean mpmb : pmbList) {
/*for (MemoryPoolMXBean mpmb : pmbList) {
String jvmMemPoolName = getHeapPoolName(mpmb.getName().trim());
Expand All @@ -543,6 +560,29 @@ public static Map<String, Long> readHeapPoolUsage(List<MemoryPoolMXBean> pmbList
m.put(jvmMemPoolName + "_commit", mu.getCommitted());
m.put(jvmMemPoolName + "_max", mu.getMax());
m.put(jvmMemPoolName + "_init", mu.getInit());
}*/

Set<String> addedSet = new HashSet<String>();

for (MemoryPoolMXBean mpmb : pmbList) {

String jvmMemPoolName = getHeapPoolName(mpmb.getName().trim());
MemoryUsage mu = mpmb.getUsage();

if(addedSet.contains(jvmMemPoolName)) {

m.put(jvmMemPoolName + "_use", (Long)m.get(jvmMemPoolName + "_use") + mu.getUsed());
m.put(jvmMemPoolName + "_commit", (Long)m.get(jvmMemPoolName + "_commit") + mu.getCommitted());
m.put(jvmMemPoolName + "_max", (Long)m.get(jvmMemPoolName + "_max") + mu.getMax());
m.put(jvmMemPoolName + "_init", (Long)m.get(jvmMemPoolName + "_init") + mu.getInit());
}else {

addedSet.add(jvmMemPoolName);
m.put(jvmMemPoolName + "_use", mu.getUsed());
m.put(jvmMemPoolName + "_commit", mu.getCommitted());
m.put(jvmMemPoolName + "_max", mu.getMax());
m.put(jvmMemPoolName + "_init", mu.getInit());
}
}

return m;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
import java.io.OutputStream;
import java.io.PushbackInputStream;

import sun.misc.CEFormatException;
import sun.misc.CEStreamExhausted;

// Referenced classes of package sun.misc:
// CharacterDecoder, CEFormatException, CEStreamExhausted

Expand Down Expand Up @@ -57,18 +54,18 @@ protected void decodeAtom(PushbackInputStream pushbackinputstream, OutputStream
byte byte2 = -1;
byte byte3 = -1;
if (i < 2)
throw new CEFormatException("BASE64Decoder: Not enough bytes for an atom.");
throw new IOException("BASE64Decoder: Not enough bytes for an atom.");
int j;
do {
j = pushbackinputstream.read();
if (j == -1)
throw new CEStreamExhausted();
throw new IOException();
}
while (j == 10 || j == 13);
decode_buffer[0] = (byte) j;
j = readFully(pushbackinputstream, decode_buffer, 1, i - 1);
if (j == -1)
throw new CEStreamExhausted();
throw new IOException();
if (i > 3 && decode_buffer[3] == 61)
i = 3;
if (i > 2 && decode_buffer[2] == 61)
Expand Down
Loading

0 comments on commit 73f6259

Please sign in to comment.