监控web应用脚本
#!/bin/bash
result=`curl -s http://192.168.1.220:8080/inote/selfcheck/check.html`
if [[ $result = *ok* ]]; then
echo 'success'
else
echo 'error'
fi
result=`curl -s http://192.168.1.220:8080/inote/selfcheck/check.html`
if [[ $result = *ok* ]]; then
echo 'success'
else
echo 'error'
fi
监控CPU的load值(队列中的线程数):不大于3正常,超过5不正常
[
root@slave3 ~]# uptime
15:48:07 up 4:10, 1 user, load average: 0.00, 0.00, 0.00
15:48:07 up 4:10, 1 user, load average: 0.00, 0.00, 0.00
load average后面的值为:过去1分钟、5分钟、15分钟内系统的load值。
cpu的利用率
top | grep Cpu
Cpu(s): 0.0%us, 0.1%sy, 0.0%ni, 99.1%id, 0.7%wa, 0.0%hi, 0.0%si, 0.0%st
us:用户时间,高好
sy:内核时间,低好
ni:系统在调整进程优先级花费的时间
id:空闲时间,低好
wa:cpu等待io操作花费的时间,低好
hi:系统处理硬件中断所耗费的时间
si:软件中断所耗费的时间
st:丢失时间,强制等待虚拟cpu的时间,较高表示两个虚拟机抢占cpu频繁
磁盘剩余空间
[
root@slave3 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_slave3-lv_root 6.5G 3.2G 3.0G 52% /
tmpfs 499M 0 499M 0% /dev/shm
/dev/sda1 477M 49M 403M 11% /boot
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_slave3-lv_root 6.5G 3.2G 3.0G 52% /
tmpfs 499M 0 499M 0% /dev/shm
/dev/sda1 477M 49M 403M 11% /boot
网络traffic
[
root@master ~]# sar -n DEV 1 1
Linux 2.6.32-504.8.1.el6.x86_64 (master) 2015年03月11日 _x86_64_ (1 CPU)
16时12分11秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
16时12分12秒 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
16时12分12秒 eth0 204.08 3.06 192.32 0.42 0.00 0.00 0.00
16时12分12秒 eth1 0.00 0.00 0.00 0.00 0.00 0.00 0.00
平均时间: IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
平均时间: lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
平均时间: eth0 204.08 3.06 192.32 0.42 0.00 0.00 0.00
平均时间: eth1 0.00 0.00 0.00 0.00 0.00 0.00 0.00
Linux 2.6.32-504.8.1.el6.x86_64 (master) 2015年03月11日 _x86_64_ (1 CPU)
16时12分11秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
16时12分12秒 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
16时12分12秒 eth0 204.08 3.06 192.32 0.42 0.00 0.00 0.00
16时12分12秒 eth1 0.00 0.00 0.00 0.00 0.00 0.00 0.00
平均时间: IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
平均时间: lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
平均时间: eth0 204.08 3.06 192.32 0.42 0.00 0.00 0.00
平均时间: eth1 0.00 0.00 0.00 0.00 0.00 0.00 0.00
rxpck/s :每秒接受的数据包数
txpck/s :每秒发送的数据包数
rxkB/s :每秒接受的字节数
txkB/s :每秒发送的字节数
rxcmp/s :每秒接受的压缩包数
txcmp/s :每秒发送的压缩包数
rxmcst/s :每秒接受的广播包数
磁盘I/O:-d查看使用情况,-k表示kb
[
root@master ~]# iostat -d -k
Linux 2.6.32-504.8.1.el6.x86_64 (master) 2015年03月11日 _x86_64_ (1 CPU)
Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 0.53 5.61 0.90 94809 15281
dm-0 0.82 5.34 0.90 90121 15272
dm-1 0.02 0.08 0.00 1288 0
Linux 2.6.32-504.8.1.el6.x86_64 (master) 2015年03月11日 _x86_64_ (1 CPU)
Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 0.53 5.61 0.90 94809 15281
dm-0 0.82 5.34 0.90 90121 15272
dm-1 0.02 0.08 0.00 1288 0
Device:设备名
tps:每秒处理的io请求数
kB_read/s:每秒从设备读取的字节数
kB_wrtn/s:每秒从设备写入的字节数
kB_read:读取的数据总量
kB_wrtn:写入的数据总量
内存使用:-m按兆看
[
root@master ~]# free -m
total used free shared buffers cached
Mem: 996 213 783 0 37 54
-/+ buffers/cache: 121 874
total used free shared buffers cached
Mem: 996 213 783 0 37 54
-/+ buffers/cache: 121 874
Swap: 815 0 815
Mem:物理内存
Swap:虚拟内存
shared:多个进程共享的内存空间大小
buffers:缓冲区大小
cached:缓存的大小
Swap更值得关注,swap内存使用过多,表示物理内存不够用了。
访问量排名前10的IP
cat access.log | cut -f1 -d " " | sort | uniq -c | sort -k 1 -n -r | head -10
cut -f1 -d " ":将前面的输入用" "分割,并显示第一行,cut为选取工具
sort | uniq -c:排序去重统计个数
sort -k 1 -n -r :倒叙统计第一列
head -10:头10个
访问量排名前10的url
cat access.log | cut -f7 -d " " | sort | uniq -c | sort -k 1 -n -r | head -10
查看耗时最长的页面
cat access.log | sort -k 2 -n -r | head -10
统计404请求的占比
export total_line=`wc -l access.log | cut -f1 -d " "` && export not_find_line=`awk '$6=='404'{print $6}' access.log | wc -l ` && expr $not_find_line \* 100 / $total_line
首先算出access.log的总行数,通过export导出为total_line变量,然后通过awk命令输出404请求的行,通过wc -l统计404请求的行数,导出为not_find_line变量,最后通过expr命令,计算出百分比
替换文件中的abc为asf并输出前两行,s表示替换
sed 's/abc/asf/' access.log | head -2
删除包含404单词的行,d表示删除命令
sed '/404/d' access.log
输出包含404的行中的第5第6列
awk ‘/404/{print $5,$6}' access.log
查看文件,显示行号
cat -n access.log
分页显示文件:enter下一行 空格 下一页 F下一瓶 B上一瓶
more access.log
查看文件,高亮显示查找的词
less accexss.log
输入 /GET就会高亮显示GET
显示文件末尾2行
tail -n2 access.log
监控文件
tail -f access.log
统计文件多少行
wc -l access.log
统计文件的字节数
wc -c access.log
文件中最长的行的长度
wc -L access.log
统计文件的单词数
wc -w access.log
查找文件夹下的文件绝对路径
find /home/hadoop -name hdfs-site.xml
返回:/home/hadoop/hadoop/conf/hdfs-site.xml
通过命令行访问网页
curl
www.baidu.com
curl -i
www.baidu.com 带header信息
curl -I
www.baidu.com 只返回header信息