使用知行之桥EDI系统时,由于业务数据量的增多,难免会遇到一些系统异常情况,为了保证企业生产环境的稳定运行,EDI系统自带了错误邮件通知功能。此功能保证了在EDI系统自动处理数据的过程中可以将异常信息及时告知用户,使用户收到邮件及时处理,保证数据的正常传输。
那么除了一些常见的异常情况,随着企业业务数据量的增大,现有服务器环境可能无法提供足够的磁盘空间存放数据处理的日志和文件,特别是在使用跨平台版本(JAVA版本)的知行之桥EDI系统时,此情况比较常见。基于此背景,我们提供了堆内存占用超过80% 邮件预警以及磁盘空间使用率超过80%邮件预警功能。具体实现步骤如下:文章源自懂站帝-http://www.sfdkj.com/12316.html
一、堆内存占用超过 80% 邮件预警
Java堆内存管理是影响性能的主要因素之一,堆内存过高可能会造成内存溢出,导致进程无法无法访问,从而使EDI系统无法正常运行。为了避免这一问题的出现,提前预警,可以参考以下步骤进行配置:文章源自懂站帝-http://www.sfdkj.com/12316.html
1.新建监控脚本 java_heap_usage_monitor.sh文件,监控脚本的具体代码如下(注:其中_java=/home/java/jdk1.8.0_201/bin/java是当前环境中java执行路径,需要根据自身情况进行修改):文章源自懂站帝-http://www.sfdkj.com/12316.html
1文章源自懂站帝-http://www.sfdkj.com/12316.html 2文章源自懂站帝-http://www.sfdkj.com/12316.html 3文章源自懂站帝-http://www.sfdkj.com/12316.html 4文章源自懂站帝-http://www.sfdkj.com/12316.html 5文章源自懂站帝-http://www.sfdkj.com/12316.html 6文章源自懂站帝-http://www.sfdkj.com/12316.html 7文章源自懂站帝-http://www.sfdkj.com/12316.html 8文章源自懂站帝-http://www.sfdkj.com/12316.html 9文章源自懂站帝-http://www.sfdkj.com/12316.html 10文章源自懂站帝-http://www.sfdkj.com/12316.html 11文章源自懂站帝-http://www.sfdkj.com/12316.html 12文章源自懂站帝-http://www.sfdkj.com/12316.html 13文章源自懂站帝-http://www.sfdkj.com/12316.html 14文章源自懂站帝-http://www.sfdkj.com/12316.html 15文章源自懂站帝-http://www.sfdkj.com/12316.html 16文章源自懂站帝-http://www.sfdkj.com/12316.html 17文章源自懂站帝-http://www.sfdkj.com/12316.html 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
#!/usr/bin/env bash set -e while getopts "v" opt; do case $opt in v) debug_mode=true;; esac done function _log_msg() { if [ $debug_mode ]; then echo $1 fi } function error() { echo $1 >&2 } _java=/home/java/jdk1.8.0_201/bin/java # Check if arcesb service is live arcesb_pid=$(ps -aux | grep -e "java.*arcesb.jar" | grep -v grep | awk '{ print $2 }') if [ ! -n "$arcesb_pid" ]; then error "Failed to aceess arcesb process." exit 2 fi _log_msg "arcesb pid: $arcesb_pid" # Get java major version if [[ "$_java" ]]; then java_version=$("$_java" -version 2>&1 | awk -F '"' '/version/ {print $2}') _log_msg "java version: $java_version" java_major_version=$(echo $java_version | awk -F '.' '{ print $1}') _log_msg "java major version: $java_major_version" fi if [ $(type -p jmap) ]; then _jmap=jmap else _jmap=/home/java/jdk1.8.0_201/bin/jmap _log_msg "jmap not found, set default to $_jmap" fi # Get arcesb service heap usage raw result if [ "$java_major_version" = "11" ]; then heap_res=$(sudo jhsdb jmap --heap --pid $arcesb_pid) _log_msg "sudo jhsdb jmap --heap --pid $arcesb_pid:" _log_msg "$heap_res" else heap_res=$("$_jmap" -heap $arcesb_pid) _log_msg "sudo $_jmap -heap $arcesb_pid" _log_msg "$heap_res" fi # Get arcesb service heap usage percent if echo "$heap_res" | grep -q -i "garbage-first"; then _log_msg "GC Algorithm: G1" key_word="g1 heap" elif echo "$heap_res" | grep -q -i "parallel gc"; then _log_msg "GC Algorithm: Parallel GC" key_word="old gen" elif echo "$heap_res" | grep -q -i "mark sweep"; then _log_msg "GC Algorithm: Mark Sweep" key_word="tenured" else error "Unknow GC Algorithm" fi if type -p bc > /dev/null; then echo "$heap_res" | grep -i "$key_word" -A 10 | grep -e "used$" | head -1 | awk '{ print $1 }' | awk -F '%' '{ print "scale=0;" $1 " / 1" }' | bc -l else _log_msg "bc command not found" echo "$heap_res" | grep -i "$key_word" -A 10 | grep -e "used$" | head -1 | awk '{ print $1 }' | awk -F '%' '{ print $1 }' | awk -F '.' '{ print $1 }' fi if [ "$?" != "0" ]; then error "Failed to parse the result of java heap usage." exit 3 fi |
2.将监控脚本 java_heap_usage_monitor.sh文件拷贝至部署EDI的服务器。 3.给予java_heap_usage_monitor.sh文件执行权限,修改文件权限命令如下:
1 |
sudo chmod a+x java_heap_usage_monitor.sh |
4.在服务器上测试监控脚本是否工作,执行以下命令,成功执行可以看到当前EDI系统占用堆内存的大小:
1 |
./java_heap_usage_monitor.sh |
5.在EDI系统页面创建Script端口,修改监控脚本 java_heap_usage_monitor.sh文件的存放路径,以及邮件预警收件箱地址。

Script端口具体代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
<!-- Execute Batch File --> <arc:set attr="Directory" value="/home/arcesb_8056/data/" ></arc:set> <arc:set attr="Name" value='/home/arcesb_8056/data/java_heap_usage_monitor.sh' ></arc:set> <arc:set attr="Arguments" value='' ></arc:set> <arc:set attr="o.Data"/> <arc:call op="sysExecute" out="out"> <arc:check value="[out.sys:error | def | trim]"> <arc:throw code="error" desc="Failed to execute [Name]: [out.sys:error]"/> </arc:check> <arc:set attr="heap.percentage" value="[out.sys:output | def | trim]"/> <arc:check value="[heap.percentage | isnumeric]"> <arc:if exp="[heap.percentage | greaterthan(80)]"> <arc:set attr="Subject" value="Low Java Heap"></arc:set> <arc:set attr="Message" value="Java Heap used [heap.percentage]% of the space."></arc:set> <arc:set attr="To" value="XXX@XXXXXX"></arc:set> <arc:call op="appSendEmail" ></arc:call> </arc:if> <arc:else> <arc:throw code="error" desc="Failed to parse the value [heap.percentage] as numeric!"/> </arc:else> </arc:check> </arc:call> |
6.设置Script端口自动化功能,设置定时接收,可以选择每天8点自动获取检测堆内存使用情况:

7.配置完成后,知行之桥EDI系统每天8点检测堆内存使用情况,若是堆内存使用超过80%会收到如下主题提示的邮件,邮件正文包含当前进程堆内存使用率:

二、磁盘空间使用率超过80%预警
磁盘空间不足也是影响EDI环境正常运行的一大原因,磁盘空间不足会导致数据无法正常处理,日志信息无法写入。同样为了避免这种情况出现,提前预警,可以参考以下方法进行配置:
1.在EDI系统页面新建Script端口,修改邮件预警收件箱地址信息。

Script端口具体代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<!-- Execute Batch File --> <rsb:set attr="Name" value="df" ></rsb:set> <rsb:set attr="Arguments" value='"[_connector.sendfolder]"' ></rsb:set> <rsb:call op="sysExecute" out="out"> <rsb:set attr="disk.mount" value="[out.sys:output | split('\n', 2) | rsplit(' ', 1)]"/> <rsb:set attr="disk.percentage" value="[out.sys:output | split('\n', 2) | rsplit(' ', 2) | replace('%', '')]"/> <rsb:if exp="[disk.percentage | greaterthan(80)]"> <!-- Send Email --> <rsb:set attr="Subject" value="Low Disk Space"></rsb:set> <rsb:set attr="Message" value="Disk [disk.mount] used [disk.percentage]% of the space."></rsb:set> <rsb:set attr="To" value="XXX@XXXXXX"></rsb:set> <rsb:call op="appSendEmail" ></rsb:call> </rsb:if> </rsb:call> |
2.设置Script端口自动化功能,设置定时接收,可以选择每天早上8点自动获取检测磁盘空间使用情况:

3.配置完成后,EDI系统每天8点检测磁盘空间使用情况,若是磁盘空间使用率超过80%会收到如下主题提示的邮件,邮件正文包含当前磁盘空间使用率:
