工作使用命令

一、查看日志要使用的命令

grep -c '出现的字符串' 日志文件.log                    查看该字符串在该日志文件出现的次数

grep   "\[19:" 日志文件.log                              注意的是要使用转义符号

如果想看日志的某一个时间段且出现的某个字符串:

 grep "^\[\(09\|10\):" /data/logs/login-resin-stdout.log

 grep 'com.renren.security.logintrack.captcha.util.MemCacheUtil' /data/logs/login-resin-stdout.log.20120803 | awk -F '.' '{split($9,tmp,"(");print tmp[1];}' | sort |uniq -c

awk '{arr[$i]++;}END{for (i in arr){print i,arr[i]}}'统计该字符出现的次数

grep '\[13:' /data/logs/login-resin-stdout.log|awk -F ' ' '{ arr[split($21,tmp,":")];print tmp[2] }'|awk '{arr[$i]++;}END{for (i in arr){print i,arr[i]}}'

-F的参数表示 对于日志行的分割分割标志是'. ',用awk得到第九列的数据然后截取(得到的数据存放在tmp数组中,最后排序并统计

该命令的用途是统计发生异常的方法在日志文件中出现了多少次?

#!/bin/bash

. /etc/profile

if [ "$0" != "bin/daily.sh" ]
then
  echo "Please run this script at the root directory"
  exit 1
fi

export SVN_TOP_COMM_TODAY=$2
export SVN_TOP_COMM_YESTERDAY=$1

#SVN_TOP_COMM_DATADIR=data/$SVN_TOP_COMM_TODAY
#if [ ! -d $SVN_TOP_COMM_DATADIR ]
#then
# mkdir -p $SVN_TOP_COMM_DATADIR
#fi

#export SVN_TOP_COMM_REPOS_FILE="trunk"
#export SVN_TOP_COMM_REPOS_PATH="svn://svn.d.xiaonei.com"
#. bin/generate_detail.sh > $SVN_TOP_COMM_DATADIR/detail_of_$SVN_TOP_COMM_REPOS_FILE.txt
#. bin/generate_summary.sh >  $SVN_TOP_COMM_DATADIR/summary_of_$SVN_TOP_COMM_REPOS_FILE.html

#cd $SVN_TOP_COMM_DATADIR
#java -cp "../../lib/*" xce.tools.EmailSender ../../etc/oce.properties

VAL=`ls .. | grep svn| grep -v public| grep -v conf| grep -v committer| grep -v outdated| grep -v svnbackup| grep -v 3g`
echo $VAL
echo 'start ...'
for i in $VAL
do
  PROJECT=`echo $i|cut -c 5-`
  export SVN_TOP_COMM_REPOS_FILE=$PROJECT
  export SVN_TOP_COMM_REPOS_PATH="svn://svn.d.xiaonei.com/"$PROJECT
  echo $SVN_TOP_COMM_REPOS_FILE,$SVN_TOP_COMM_REPOS_PATH  
  . bin/generate_summary.sh
#>  $SVN_TOP_COMM_DATADIR/summary_of_$SVN_TOP_COMM_REPOS_FILE.html  
done

二、文件的替换

将test.log文件中的@XIAONEI.OPI.COM字符串全部替换成空字符串 g代表整个文件

sed 's/@XIAONEI.OPI.COM/''/g' -i test.log

三、给文件生成一个软链接

ln -s /data/project-data/svn_log/svn_login/trunk/ /data/project-data/trunk/target/renren-profile-1.0-SNAPSHOT/自己定义一个软链接的文件名称 

删除软链接 rm -rf   symbolic_name   注意不是rm -rf   symbolic_name/

四、查看java内存情况

pmap -d 进程号能够查看该进程占用多少内存以及内存的详细情况,尤其关注private内存使用

pmap 进程号  查看进程占用的资源数目   top也能看

java进程数目   ps -eLf | grep java | wc -l

free -lot 内存使用总结很好

top  按P降序查看cpu的使用率,按M降序查看内存的使用率

vmstat 1 100

-a  能够查看内存页有多少是激活的有多少是不激活的


使用man指令查看各个参数是做什么用的

kswapd进程是负责内存空间总是被释放中

pdflush进程负责内存的数据跟文件系统中的数据进行同步

ps -ef|grep kswapd

ps -ef|grep pdflush

查看内存信息cat /proc/meminfo

sar -B显示pageout和pagein情况是默认收集24的统计信息,很强大分析问题定位非常好。

内存和交换区的使用率

sar -r 1 10 1秒刷新数据而且只显示10行


Paging moves individual pages to swap space on the disk; swapping is a bigger operation that moves the entire address space of a process to swap space in one operation。


Swapping can have one of two causes:

  • A process enters sleep mode. This usually happens because the process depends on interactive action and editors, shells, and data entry applications spend most of their time waiting for user input. During this time, they are inactive.
  • A process behaves poorly. Paging can be a serious performance problem when the amount of free memory pages falls below the minimum amount specified, because the paging mechanism is not able to handle the requests for physical memory pages and the swap mechanism is called to free more pages. This significantly increases I/O to disk and will quickly degrade a server’s performance.
  1. Tune the swap space using bigpages, hugetlb, shared memory.

猜你喜欢

转载自he-wen.iteye.com/blog/1631273