blob.png

        这个脚本去/tmp下的文件取值,这个值定时任务一分钟生成一个,获取到之后去zabbix的web界面进行展示。

#!/bin/bash
# at 2016-11-28 
# by jifucha
if [ $# -ne 2 ];then
  echo " error parameter"
  exit 1
fi
# set global variable
Project="$1"
Option="$2"
File_dir="/tmp/java_jmap_${Project}.tmp"
# set function   
Jmap_heap_Eden_info() {
  Par="$1"
  if [ -n "${Par}" ];then
   grep -A 3 "Eden" ${File_dir}|grep  "${Par}"|awk '{print $3}'
  fi
}
Jmap_heap_Perm_info() {
  Par="$1"
  if [ -n "${Par}" ];then
    grep -A 3 "Perm\ Generation" ${File_dir}|grep "${Par}"|tail -1|awk '{print $3 }'
  fi
}
Jmap_heap_Old_info() {
  Par="$1"
  if [ -n "${Par}" ];then
     grep -A 3 "Old\ Generation" ${File_dir}|grep "${Par}"|tail -1|awk '{print $3 }' 
  fi
}
Jmap_heap_new_one_info() {
  Par="$1"
  if [ -n "${Par}" ];then
     grep -A 3 "From\ Space" ${File_dir}|grep "${Par}"|tail -1|awk '{print $3 }' 
  fi
}
Jmap_heap_new_two_info() {
  Par="$1"
  if [ -n "${Par}" ];then
     grep -A 3 "To\ Space" ${File_dir}|grep "${Par}"|tail -1|awk '{print $3 }' 
  fi
}
# set case function transfer
case "$Option" in
   eden_capacity)
     Jmap_heap_Eden_info capacity
     ;;
   eden_used)
     Jmap_heap_Eden_info used
     ;;
   eden_free)
     Jmap_heap_Eden_info free
         ;;
   perm_capacity)
     Jmap_heap_Perm_info capacity
     ;;                  
   perm_used)            
     Jmap_heap_Perm_info used
     ;;                  
   perm_free)            
     Jmap_heap_Perm_info free
     ;;
   old_capacity)
     Jmap_heap_Old_info capacity
     ;;                  
   old_used)             
     Jmap_heap_Old_info used
     ;;                  
   old_free)             
     Jmap_heap_Old_info free
     ;;
   one_capacity)
     Jmap_heap_new_one_info capacity
     ;;
   one_used)
     Jmap_heap_new_one_info used
     ;;
   one_free)
     Jmap_heap_new_one_info free
     ;;
   two_capacity)
     Jmap_heap_new_two_info capacity
     ;;
   two_used)
     Jmap_heap_new_two_info used
     ;;
   two_free)
     Jmap_heap_new_two_info free
esac