16 Commits

Author SHA1 Message Date
fangshunjian
3d258f645f 1、修改内存利用率获取方式 2019-01-11 12:26:45 +06:00
fangshunjian
492050c0ea Merge branch 'master' into dev
Conflicts:
	.gitignore
2019-01-11 10:51:10 +06:00
fangshunjian
aebc5f8718 添加 ignore 文件 2019-01-11 10:48:44 +06:00
fangshunjian
76f6fa284d 1、增加 cpu性能信息是否显示cpu每一核的开关 2018-12-21 18:52:46 +06:00
fangshunjian
48e8a81442 Merge branch 'dev' of git@192.168.10.125:nms/nmsclient.git into dev 2018-11-26 10:49:34 +08:00
fangshunjian
48966d406c 脚本中增加开机自启动(boot-up) 选项 2018-11-26 10:49:12 +08:00
wangwenrui
1dfcb42efe 逆向任务解压覆盖失败 2018-11-21 16:59:14 +08:00
fangshunjian
1a5f97d11d 1、nc启动时根据配置文件随机sleep n秒,防止批量执行nc启动导致dc无法处理 2018-11-21 13:48:39 +08:00
wangwenrui
be4890a108 尝试次数 2018-11-19 13:41:47 +08:00
wangwenrui
aaab21e98c 尝试次数bug修改 2018-11-16 14:18:15 +08:00
wangwenrui
607a04b995 install 2018-11-02 18:07:41 +08:00
wangwenrui
a2d6943a22 安装 jdk > jre 2018-11-01 19:09:15 +08:00
wangwenrui
3773c6e2e3 安装目录修改 2018-11-01 14:14:56 +08:00
fangshunjian
4e1c230d88 Merge remote-tracking branch 'origin/dev' into dev 2018-10-18 16:03:04 +08:00
fangshunjian
2aa74c2eb9 1、修改nc 周期启动 不能正确执行的 bug,去掉 ./ ,第三方监测脚本 赋予 777 权限
2、修改 log4j 配置文件 error 日志不能正确输出的问题
2018-10-18 16:02:47 +08:00
方顺健
f4ae72e55c Update nmsagent.sh
加强 OS_TYPE 读取方式
2018-10-09 11:23:16 +08:00
15 changed files with 91 additions and 42 deletions

5
.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
<<<<<<< HEAD
/bin
=======
/bin/
>>>>>>> refs/heads/master

View File

@@ -1,15 +0,0 @@
log4j.rootLogger = debug,stdout,logfile
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout.ConversionPattern = %d %p [%c] [%t] - <%m>%n
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
#----------------------debug---------------------
log4j.appender.logfile = org.apache.log4j.RollingFileAppender
log4j.appender.logfile.MaxFileSize = 50MB
log4j.appender.logfile.MaxBackupIndex = 20
log4j.appender.logfile.File = ./nc_logs/nmsclient.log
log4j.appender.logfile.layout.ConversionPattern = %d %p [%c] [%t] - <%m>%n
log4j.appender.logfile.layout = org.apache.log4j.PatternLayout

View File

@@ -1,8 +1,8 @@
#!/bin/bash
# --- set default value
DEFAULT_DATA_DIR="/home/nms/nmsdata"
DEFAULT_INSTALL_DIR="/home/nms/nmsclient"
DEFAULT_DATA_DIR="/home/ceiec/nms/nmsdata"
DEFAULT_INSTALL_DIR="/home/ceiec/nms/nmsclient"
# --- set install dir
PRG="$0"
@@ -46,10 +46,10 @@ fi
# --- install jdk
cd "$INSTALL_DIR"/..
NMS_JDK="$(pwd)/nmsjdk"
JDK_DIR="$(pwd)/jdk1.7.0_80"
JDK_BIN_FILE=$CUR_PRGDIR"/jre_install/jdk-7u80-linux-i586.tar.gz"
JDK_DIR="$(pwd)/jre1.7.0_80"
JDK_BIN_FILE=$CUR_PRGDIR"/jre_install/jre-7u80-linux-i586.tar.gz"
if [ "`uname -i`" = "x86_64" ];then
JDK_BIN_FILE=$CUR_PRGDIR"/jre_install/jdk-7u80-linux-x64.tar.gz"
JDK_BIN_FILE=$CUR_PRGDIR"/jre_install/jre-7u80-linux-x64.tar.gz"
fi
if [ $install_jdk = 1 ]
then

View File

@@ -1,8 +1,8 @@
#!/bin/bash
# --- set default value
DEFAULT_DATA_DIR="/home/nms/nmsdata"
DEFAULT_INSTALL_DIR="/home/nms/nmsclient"
DEFAULT_DATA_DIR="/home/ceiec/nms/nmsdata"
DEFAULT_INSTALL_DIR="/home/ceiec/nms/nmsclient"
# --- set install dir
PRG="$0"
@@ -55,10 +55,10 @@ fi
# --- install jdk
cd "$INSTALL_DIR"/..
NMS_JDK="$(pwd)/nmsjdk"
JDK_DIR="$(pwd)/jdk1.7.0_80"
JDK_BIN_FILE=$CUR_PRGDIR"/jre_install/jdk-7u80-linux-i586.tar.gz"
JDK_DIR="$(pwd)/jre1.7.0_80"
JDK_BIN_FILE=$CUR_PRGDIR"/jre_install/jre-7u80-linux-i586.tar.gz"
if [ "`uname -i`" = "x86_64" ];then
JDK_BIN_FILE=$CUR_PRGDIR"/jre_install/jdk-7u80-linux-x64.tar.gz"
JDK_BIN_FILE=$CUR_PRGDIR"/jre_install/jre-7u80-linux-x64.tar.gz"
fi
if [ $install_jdk = 1 ]
then

View File

@@ -21,8 +21,18 @@
# resolve links - $0 may be a softlink
PRG="$0"
#OS_TYPE=$( lsb_release -d| cut -d: -f2| cut -f2 )
#echo $OS_TYPE
if [ -f /etc/redhat-release ]; then
OS_TYPE=`cat /etc/redhat-release`
else
islsb=`which lsb_release | wc -l`
if [ "$islsb" != "0" ]; then
OS_TYPE=$( lsb_release -d| cut -d: -f2| cut -f2 )
else
OS_TYPE=`uname -a | awk '{print $1" "$2" "$3}'`
fi
fi
echo $OS_TYPE
while [ -h "$PRG" ]; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
@@ -185,6 +195,17 @@ if [ "$1" = "start" ] ; then
fi
handleTask
fi
elif [ "$1" = "boot-up" ]; then
#设置开机自启动
if [ -z "$(cat /etc/rc.local|grep -E "^\s*$NMSCLEINT_HOME/shell/startup.sh")" ]
then
echo "">> /etc/rc.local
echo "########## nmsclient开机启动 ###########" >> /etc/rc.local
echo $NMSCLEINT_HOME"/shell/startup.sh" >> /etc/rc.local
echo "Boot-up settings complete!"
else
echo "Boot-up has been set up without modification."
fi
elif [ "$1" = "stop" ]; then
getPid
if [ -n "$proc_id" ]

View File

@@ -112,6 +112,14 @@ public class NmsClient{
AlarmUtil.sendNMSErrorMsg(ErrorCode.DeamonNotExist, Utils.getLocalIp(), "i18n_client.NmsClient.ncDeamonStartException_n81i" + e.getMessage());
}
try {
int sleep = (int)(1+Math.random()*Contants.STARTUP_SLEEP_SECOND);
logger.debug(String.format("startup sleep %ss", sleep));
Thread.sleep(sleep*1000);
} catch (Exception e) {
logger.error("",e);
}
/**
* 相关业务操作入口
*/

View File

@@ -421,7 +421,8 @@ public class Common {
if (os.startsWith("Windows")) {
command = scriptFile.getCanonicalPath();
} else if (os.startsWith("Linux")) {
command = "./ " + scriptFile.getCanonicalFile();
// command = "./ " + scriptFile.getCanonicalFile();
command = scriptFile.getCanonicalPath();
}
setInfo.setProcessPath(command); // 设置执行命令
setInfo.setProcessSearchKeyCode(scriptFile.getName()); // 搜索关键字

View File

@@ -135,6 +135,16 @@ public class Contants {
public static final int DATA_SEND_THREAD_PORT;
//主动数据上报间隔 INTERVAL单位 10 S
public static final int DATA_SEND_THREAD_INTERVAL;
/**
* 启动时最大 暂停时间为了缓解一次启动多个nc dc无法处理的情况
* 默认10s
*/
public static final int STARTUP_SLEEP_SECOND;
/**
* 是否CPU監測信息性能描述顯示詳細每一核的信息
*/
public static final boolean DESC_CPU_DETAIL;
static{
SYSTEM_PATH = SysConfig.getSystemDir();
@@ -244,8 +254,15 @@ public class Contants {
DATA_SEND_THREAD_PORT = SysConfig.getIntegerVal("data.send.thread.port", "9527");
//主动数据上报间隔 INTERVAL单位 10 S
DATA_SEND_THREAD_INTERVAL = SysConfig.getIntegerVal("data.send.thread.interval", "10");
/*
* 启动时最大 暂停时间为了缓解一次启动多个nc dc无法处理的情况
* 单位s
*/
STARTUP_SLEEP_SECOND = SysConfig.getIntegerVal("startup.sleep.second", "60");
/**
* 1:cpu desc info contain each cpu core,0:no contain
*/
DESC_CPU_DETAIL = (SysConfig.getIntegerVal("desc.cpu.detail", "0")==1);
// 初始化创建文件夹
if(!new File(localDetecConfPath).exists()){
new File(localDetecConfPath).mkdirs();
@@ -271,6 +288,7 @@ public class Contants {
if(!new File(localTempDataIncomingPath).exists()){
new File(localTempDataIncomingPath).mkdirs();
}
}
private static String formatPath(String path){

View File

@@ -32,6 +32,7 @@ import com.nis.nmsclient.thread.task.TaskReqHandle;
import com.nis.nmsclient.util.DateUtil;
import com.nis.nmsclient.util.FileUtil;
import com.nis.nmsclient.util.FileWrUtil;
import com.nis.nmsclient.util.ProcessUtil;
import com.nis.nmsclient.util.Utils;
/**
@@ -203,7 +204,7 @@ public class SSLServer implements Runnable {
this.sendMessageByChar(SUCCESS);
this.bpReceiveFileByBath(pluginDir.getCanonicalPath());
this.sendMessageByChar(SUCCESS);
ProcessUtil.permit(777, pluginDir);//赋予执行权限
} else if(SERVER_FILE_PUSH.equalsIgnoreCase(msg)){//任务操作:文件推送
this.sendMessageByChar(SUCCESS);
String str = this.receiveMessageByChar();

View File

@@ -54,7 +54,9 @@ public class GzipUtil {
descFile.mkdirs();
}
if(!descFile.isDirectory()){
throw new Exception("compress destination path is not a directory");
// throw new Exception("compress destination path is not a directory");
descFile=descFile.getParentFile();
destDir=descFile.getAbsolutePath();
}
String tarFile = srcFile.getParent() + File.separator + srcFile.getName().substring(0, srcFile.getName().length()-3);
StringBuffer sb = new StringBuffer();

View File

@@ -121,8 +121,10 @@ public class SystemInfo
sb.append(cpuInfos[i].getMhz());// 主频
detectInfo.getDetailDatas().add(sb.toString().replace("%", ""));
// sb2.append(Contants.DETEC_STATE_INFO_FORMATE_POINT+"cpu" + i + " 主频" + cpuInfos[i].getMhz() + "MHz使用率 "
sb2.append(Contants.DETEC_STATE_INFO_FORMATE_POINT+"cpu" + i + " i18n_client.SystemInfo.mhz_n81i" + cpuInfos[i].getMhz() + "MHzi18n_client.SystemInfo.shiyonglv_n81i "
+ CpuPerc.format(cpuList[i].getCombined()) + "; ");
if(Contants.DESC_CPU_DETAIL) {
sb2.append(Contants.DETEC_STATE_INFO_FORMATE_POINT+"cpu" + i + " i18n_client.SystemInfo.mhz_n81i" + cpuInfos[i].getMhz() + "MHzi18n_client.SystemInfo.shiyonglv_n81i "
+ CpuPerc.format(cpuList[i].getCombined()) + "; ");
}
// CPU总体信息情况
userCpuPerc += cpuList[i].getUser();// 用户使用率累加
@@ -188,15 +190,18 @@ public class SystemInfo
// a)物理内存信息
Mem mem = sigar.getMem();
Long memTotal = mem.getTotal();// 内存总量
Long memUsed = mem.getUsed();// 当前内存使用量
Long memFree = mem.getFree();// 当前内存剩余量
//Long memUsed = mem.getUsed();// 当前内存使用量
//Long memFree = mem.getFree();// 当前内存剩余量
Long memFree = mem.getActualFree();//
Long memUsed = mem.getActualUsed();
sb.append(doubleFormat(memTotal / (1024 * 1024 * 1024.0), 2));// 内存总量,单位:"G"
sb.append(SEPARATOR);
sb.append(doubleFormat(memUsed / (1024 * 1024 * 1024.0), 2));// 当前内存使用量,单位:"G"
sb.append(SEPARATOR);
sb.append(doubleFormat(memFree / (1024 * 1024 * 1024.0), 2));// 当前内存剩余量,单位:"G"
sb.append(SEPARATOR);
sb.append(doubleFormat(((memTotal - memFree) * 100.0) / memTotal, 1));// 内存使用率
sb.append(doubleFormat(mem.getUsedPercent(), 1));// 内存使用率
// sb.append(doubleFormat(((memTotal - memFree) * 100.0) / memTotal, 1));// 内存使用率
StringBuffer sb2 = new StringBuffer();
// sb2.append("内存总大小: " + doubleFormat(memTotal / (1024 * 1024 * 1024.0), 2) + "G, 现使用:"
@@ -206,7 +211,7 @@ public class SystemInfo
sb2.append("i18n_client.SystemInfo.memerySize_n81i: " + doubleFormat(memTotal / (1024 * 1024 * 1024.0), 2) + "G, i18n_client.SystemInfo.currentUsed_n81i"
+ doubleFormat(memUsed / (1024 * 1024 * 1024.0), 2) + "G, i18n_client.SystemInfo.spaceRemain_n81i"
+ doubleFormat(memFree / (1024 * 1024 * 1024.0), 2) + "G, i18n_client.SystemInfo.shiyonglv_n81i"
+ doubleFormat(((memTotal - memFree) * 100.0) / memTotal, 1) + "%");
+ doubleFormat(mem.getUsedPercent(), 1) + "%");
detectInfo.getDetailDatas().add(sb.toString());
detectInfo.setDescInfo(sb2.toString());

View File

@@ -207,6 +207,7 @@ public class GetInfoRun implements Runnable{
totalData[index++] = StringUtils.isBlank(functionSb.toString())?detectInfo.getDescInfo():functionSb.toString();// 性能数据
List<String[]> dataList = new LinkedList<String[]>();
logger.debug("write csv data:"+Arrays.toString(totalData));
// 总数据
dataList.add(totalData);
// 详细信息

View File

@@ -153,6 +153,9 @@ public class NewPluginResultMerge {
String checkDelayTime = lines.get(0)[0];// 检测时延(秒)
String checkTimes = lines.get(0)[1]; // 尝试次数
if(lines.get(0).length>3){
checkTimes = lines.get(0)[7]; // 尝试次数
}
String detectInfo = lines.get(0)[2]; // 状态信息(描述信息)
StringBuffer functionSb = new StringBuffer(); // 性能数据
@@ -244,7 +247,7 @@ public class NewPluginResultMerge {
totalData[index++] = totalStatus + "";// 执行状态是否成功是否正常
totalData[index++] = detectInfo; // 状态信息(描述信息)
totalData[index++] = StringUtils.isBlank(functionSb.toString()) ? detectInfo : functionSb.toString();// 性能数据
logger.debug("write csv data:"+Arrays.toString(totalData));
dataList.add(totalData);
// 详细信息
dataList.addAll(lines.subList(1, lines.size()));

View File

@@ -231,7 +231,7 @@ public class PluginResultMerge {
totalData[index++] = totalStatus + "";// 执行状态是否成功是否正常
totalData[index++] = detectInfo; // 状态信息(描述信息)
totalData[index++] = StringUtils.isBlank(functionSb.toString()) ? detectInfo : functionSb.toString();// 性能数据
logger.debug("write csv data:"+Arrays.toString(totalData));
dataList.add(totalData);
// 详细信息
dataList.addAll(lines.subList(1, lines.size()));

View File

@@ -1,4 +1,4 @@
log4j.rootLogger = debug,stdout,logfile
log4j.rootLogger = debug,stdout,logfile,errorLog
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout.ConversionPattern = %d %p [%l] [%t] - <%m>%n
@@ -15,7 +15,6 @@ log4j.appender.logfile.layout.ConversionPattern = %d %p [%l] [%t] - <%m>%n
log4j.appender.logfile.layout = org.apache.log4j.PatternLayout
#----------------------error---------------------
log4j.logger.errorLog = warn,errorLog
log4j.appender.errorLog = org.apache.log4j.RollingFileAppender
log4j.appender.errorLog.MaxFileSize = 50MB
log4j.appender.errorLog.Append = true