[CentOS] LVM on large partitions greater than 2TB
http://lists.centos.org/pipermail/centos/2007-February/032574.html
#!/bin/bash
#
# Script to check memory usage on Linux. Ignores memory used by disk cache.
#
# Requires the bc command
#
print_help() {
echo "Usage:"
echo "[-w] Warning level as a percentage"
echo "[-c] Critical level as a percentage"
exit 0
}
while test -n "$1"; do
case "$1" in
--help|-h)
print_help
exit 0
;;
-w)
warn_level=$2
shift
;;
-c)
critical_level=$2
shift
;;
*)
echo "Unknown Argument: $1"
print_help
exit 3
;;
esac
shift
done
if [ "$warn_level" == "" ]; then
echo "No Warning Level Specified"
print_help
exit 3;
fi
if [ "$critical_level" == "" ]; then
echo "No Critical Level Specified"
print_help
exit 3;
fi
free=`free -m | grep "buffers/cache" | awk '{print $4}'`
used=` free -m | grep "buffers/cache" | awk '{print $3}'`
total=$(($free+$used))
result=$(echo "$used / $total * 100" |bc -l|cut -c -2)
if [ "$result" -lt "$warn_level" ]; then
echo "Memory OK. $result% used."
exit 0;
elif [ "$result" -ge "$warn_level" ] && [ "$result" -le "$critical_level" ]; then
echo "Memory WARNING. $result% used."
exit 1;
elif [ "$result" -gt "$critical_level" ]; then
echo "Memory CRITICAL. $result% used."
exit 2;
fi
##self defined## MEMORY Check
# check_mem = MEMORY at defined warning and critical use %.
command[check_memory]=/usr/local/nagios/libexec/check_memory.sh -w $ARG1$ -c $ARG2$
define command{
command_name check_memory
command_line $USER1$/check_memory.sh -w $ARG1$ -c $ARG2$
}
define service{
use local-service;Name of service template to use
host_name localhost
service_description Memory Use
check_command check_memory!80!90
}
service nagios restart
define service {
use generic-service
host_name
service_description Memory Usage
check_command check_nrpe_1arg!check_memory
}
command[check_memory]=/usr/lib/nagios/plugins/check_memory.sh -w 85 -c 90
#:~$ ./check_memory.sh -w 80 -c 90
Memory OK. 44% used.
#:~$ ./check_memory.sh -w 40 -c 50
Memory WARNING. 44% used.
#!/bin/bash
#
# Script to check memory usage on Linux. Ignores memory used by disk cache.
#
# Requires the bc command
#
print_help() {
echo "Usage:"
echo "[-w] Warning level as a percentage"
echo "[-c] Critical level as a percentage"
exit 0
}
while test -n "$1"; do
case "$1" in
--help|-h)
print_help
exit 0
;;
-w)
warn_level=$2
shift
;;
-c)
critical_level=$2
shift
;;
*)
echo "Unknown Argument: $1"
print_help
exit 3
;;
esac
shift
done
if [ "$warn_level" == "" ]; then
echo "No Warning Level Specified"
print_help
exit 3;
fi
if [ "$critical_level" == "" ]; then
echo "No Critical Level Specified"
print_help
exit 3;
fi
free=`free -m | grep "buffers/cache" | awk '{print $4}'`
used=` free -m | grep "buffers/cache" | awk '{print $3}'`
total=$(($free+$used))
result=$(echo "$used / $total * 100" |bc -l|cut -c -2)
if [ "$result" -lt "$warn_level" ]; then
echo "Memory OK. $result% used."
exit 0;
elif [ "$result" -ge "$warn_level" ] && [ "$result" -le "$critical_level" ]; then
echo "Memory WARNING. $result% used."
exit 1;
elif [ "$result" -gt "$critical_level" ]; then
echo "Memory CRITICAL. $result% used."
exit 2;
fi
;# NSCLIENT PORT NUMBER ; This is the port the NSClientListener.dll will listen to. port=12489
# 'check_nt' command definition define command{ command_name check_nt command_line $USER1$/check_nt -H $HOSTADDRESS$ -p portnumber -s cjr-nagios -v $ARG1$ $ARG2$ }
It is recommended that you configure yum-priorities prior to following this tutorial to avoid having base CentOS packages being overwritten by the RPMForge repository. Instructions to do so can be found on the CentOS Wiki. |
yum install httpd php gcc glibc glibc-common gd gd-devel
/sbin/chkconfig --levels 345 httpd on
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
/etc/init.d/iptables save
/etc/init.d/iptables restart
yum install nagios nagios-plugins nagios-plugins-setuid
htpasswd -c /etc/nagios/htpasswd.users nagiosadmin
nagios -v /etc/nagios/nagios.cfg
/etc/init.d/nagios start
/etc/init.d/httpd start
http://servername/nagios/
and logging in with nagiosadmin
and the password you set.rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
rpm -K rpmforge-release-0.5.2-2.el6.rf.*.rpm
rpm -i rpmforge-release-0.5.2-2.el6.rf.*.rpm
yum install fuse fuse-ntfs-3g
yum --enablerepo=rpmforge install fuse fuse-ntfs-3g
sudo mount -o loop //root.disk /mnt nautilus /mnt # to browse
sudo fsck //root.disk
#!/bin/sh sudo mkdir -p /media/WindowsXP echo "Mounting NTFS Partition" sudo mount -t ntfs /dev/sda1 /media/WindowsXP sleep 1 sudo mkdir -p /media/root.disk echo "Mounting Wubi Disk" sudo mount -o loop /media/WindowsXP/ubuntu/disks/root.disk /media/root.disk sleep 1 echo "Done :)" gksu nautilus /media/root.disk exit 0 &
#!/bin/sh echo "Unmounting Wubi Disk" sudo umount /media/root.disk sleep 1 echo "Unmounting NTFS Partition" sudo umount /media/WindowsXP sleep 1 echo "Done :)" exit 0 &
203.218.148.99 - - [01/Feb/2011:00:02:09 +0800] "GET /blog/2009/11/an_autobiography_of_yang_xianyi.html HTTP/1.1" 200 84058 "http://www.ruanyifeng.com/blog/2009/11/freenomics.html" "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-TW; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13"
访问量 网址1
访问量 网址2
访问量 网址3
...... ......
203.218.148.99 - - [01/Feb/2011:00:02:09 +0800] "GET /blog/2009/11/an_autobiography_of_yang_xianyi.html HTTP/1.1" 200 84058 "http://www.ruanyifeng.com/blog/2009/11/freenomics.html" "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-TW; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13"
awk '$9 == 200 {print $7}' www-01.log | grep -i '^/blog/2011/.*\.html$' | sort | uniq -c | sed 's/^ *//g' > www-01.log.result
/blog/2009/11/an_autobiography_of_yang_xianyi.html
32 /blog/2011/01/guidelines_for_english_translations_in_public_places.html
32 /blog/2011/01/api_for_google_s_url_shortener.html
30 /blog/2011/01/brief_history_of_arm.html
for i in www-*.log.result
do
cat $i >> log.result
done
sort -k2 log.result | uniq -f1 --all-repeated=separate |./log.awk |sort -rn > final.log.result
617 /blog/2011/01/guidelines_for_english_translations_in_public_places.html
455 /blog/2011/01/guidelines_for_english_translations_in_public_places.html223 /blog/2011/01/2010_my_blogging_summary.html
253 /blog/2011/01/2010_my_blogging_summary.html
#!/usr/bin/awk -fBEGIN {
RS="" #将多行记录的分隔符定为一个空行
}{
sum=0 #定义一个表示总和的变量,初值为0
for(i=1;i<=NF;i++){ #遍历所有字段
if((i%2)!=0){ #判断是否为奇数字段
sum += $i #如果是的话,累加这些字段的值
}
}
print sum,$2 #输出总和,后面跟上对应的网址
}
#!/bin/bashif ls ./*.result &> /dev/null #判断当前目录中是否有后缀名为result的文件存在
then
rm *.result #如果有的话,删除这些文件
fitouch log.result #创建一个空文件for i in www-*.log #遍历当前目录中所有log文件
do
echo $i ... #输出一行字,表示开始处理当前文件
awk '$9 == 200 {print $7}' $i|grep -i '^/blog/2011/.*\.html$'|sort|uniq -c|sed 's/^ *//g' > $i.result #生成当前日志的处理结果
cat $i.result >> log.result #将处理结果追加到log.result文件
echo $i.result finished #输出一行字,表示结束处理当前文件
doneecho final.log.result ... #输出一行字,表示最终统计开始sort -k2 log.result | uniq -f1 --all-repeated=separate |./log.awk |sort -rn > final.log.result #生成最终的结果文件final.log.resultecho final.log.result finished #输出一行字,表示最终统计结束