Linux机器-网卡磁盘监控
1)实时监控网卡流量的通用脚本:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
[root@ceph-node1 ~] # cat /root/net_monit.sh #!/bin/bash PATH= /bin : /usr/bin : /sbin : /usr/sbin : /usr/local/bin : /usr/local/sbin ; export PATH function traffic_monitor { OS_NAME=$( sed -n '1p' /etc/issue ) eth=$1 if [ ! -d /sys/class/net/ $eth ]; then echo -e "Network-Interface Not Found" echo -e "You system have network-interface:\n`ls /sys/class/net`" exit 5 fi while [ "1" ] do STATUS= "fine" RXpre=$( cat /proc/net/dev | grep $eth | tr : " " | awk '{print $2}' ) TXpre=$( cat /proc/net/dev | grep $eth | tr : " " | awk '{print $10}' ) sleep 1 RXnext=$( cat /proc/net/dev | grep $eth | tr : " " | awk '{print $2}' ) TXnext=$( cat /proc/net/dev | grep $eth | tr : " " | awk '{print $10}' ) clear RX=$((${RXnext}-${RXpre})) TX=$((${TXnext}-${TXpre})) if [[ $RX -lt 1024 ]]; then RX= "${RX}B/s" elif [[ $RX -gt 1048576 ]]; then RX=$( echo $RX | awk '{print $1/1048576 "MB/s"}' ) $STATUS= "busy" else RX=$( echo $RX | awk '{print $1/1024 "KB/s"}' ) fi if [[ $TX -lt 1024 ]]; then TX= "${TX}B/s" elif [[ $TX -gt 1048576 ]]; then TX=$( echo $TX | awk '{print $1/1048576 "MB/s"}' ) else TX=$( echo $TX | awk '{print $1/1024 "KB/s"}' ) fi echo -e "===================================" echo -e "Welcome to Traffic_Monitor stage" echo -e "version 1.0" echo -e "Since 2018.7.2" echo -e "Created by wangshibo" echo -e "BLOG: http://www.cnblogs.cn/kevingrace" echo -e "===================================" echo -e "System: $OS_NAME" echo -e "Date: `date +%F`" echo -e "Time: `date +%k:%M:%S`" echo -e "Port: $1" echo -e "Status: $STATUS" echo -e " \t RX \tTX" echo "------------------------------" echo -e "$eth \t $RX $TX " echo "------------------------------" echo -e "Press 'Ctrl+C' to exit" done } if [[ -n "$1" ]]; then traffic_monitor $1 else echo -e "None parameter,please add system netport after run the script! \nExample: 'sh traffic_monitor eth0'" fi [root@ceph-node1 ~] # chmod 755 /root/net_monit.sh [root@ceph-node1 ~] # sh /root/net_monit.sh eth0 #eth0是网卡设备名称,如果是网卡绑定bond0,后面就跟bond0 =================================== Welcome to Traffic_Monitor stage version 1.0 Since 2018.7.2 Created by wangshibo BLOG: http: //www .cnblogs.cn /kevingrace =================================== System: CentOS release 6.9 (Final) Date: 2018-07-02 Time: 15:19:34 Port: eth0 Status: fine RX TX ------------------------------ eth0 417B /s 390B /s ------------------------------ Press 'Ctrl+C' to exit =================================== Welcome to Traffic_Monitor stage version 1.0 Since 2018.7.2 Created by wangshibo BLOG: http: //www .cnblogs.cn /kevingrace =================================== System: CentOS release 6.9 (Final) Date: 2018-07-02 Time: 15:19:35 Port: eth0 Status: fine RX TX ------------------------------ eth0 1.49902KB /s 1.3252KB /s ------------------------------ Press 'Ctrl+C' to exit |
2)监控磁盘的监控脚本
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
|
[root@ceph-node1 ~] # cat disk_monit.sh #!/bin/bash #filename:Monitor_Disk Monitor_Disk(){ mkdir -p /mnt/Monitor_Disk fdisk -l| grep "Disk /dev/" | awk '{print $2,$3$4}' | tr -d ',:' > /mnt/Monitor_Disk/device_list .log N=1;ECHO 90 while read device_line do Device=` echo $device_line| awk '{print $1}' ` Sum=` echo $device_line| awk '{print $2}' ` df -h | grep "$Device" | sort > /mnt/Monitor_Disk/ ${N}_partitions.log echo echo "** 第$N块硬盘($Device):${Sum} **" | grep -E "$Device|$Sum|$N" --color= yes echo "------------------------------------" echo -e "linux分区 挂载目录 总大小 已用 剩余 已用百分比 文件系统 ID system \ 块大小 预留空间 "> /mnt/Monitor_Disk/ ${N}_Over.log echo -e "========= ======== ===== === === ========== ======= == ====== \ ====== ======== ">> /mnt/Monitor_Disk/ ${N}_Over.log Num_Partition=` cat /mnt/Monitor_Disk/ ${N}_partitions.log| wc -l` n=0 while read partition_line do Partition_Name=` echo $partition_line| awk '{print $1}' ` Mount_Dir=` echo $partition_line| awk '{print $6}' ` Partition_Sum=` echo $partition_line| awk '{print $2}' ` Partition_Used=` echo $partition_line| awk '{print $3}' ` Partition_Leave=` echo $partition_line| awk '{print $4}' ` Partition_Percent=` echo $partition_line| awk '{print $5}' ` Partition_Type=` mount | grep $Partition_Name| awk '{print $5$6}' ` Partition_Id=` fdisk -l | grep $Partition_Name| tr -d '\*' | awk '{print $5}' ` Partition_System=` fdisk -l | grep $Partition_Name| tr -d '\*' | awk '{print $6}' ` Part_Block_Size_B=`tune2fs -l $Partition_Name| grep "Block size" | awk '{print $3}' ` Part_Lift_For_Root_Blocks=`tune2fs -l $Partition_Name| grep "Reserved block count:" |\ awk '{print $4}' ` Part_Block_Size=` echo $Part_Block_Size_B /1024 | bc ` Part_Lift_For_Root=` echo ${Part_Lift_For_Root_Blocks}*${Part_Block_Size} /1024 | bc ` echo -e "$Partition_Name $Mount_Dir $Partition_Sum $Partition_Used $Partition_Leave \ $Partition_Percent $Partition_Type $Partition_Id $Partition_System \ ${Part_Block_Size}K ${Part_Lift_For_Root}M">> /mnt/Monitor_Disk/ ${N}_Over.log let n++ [ $n - eq $Num_Partition ]&&( cat /mnt/Monitor_Disk/ ${N}_Over.log|column -t; echo ) done < /mnt/Monitor_Disk/ ${N}_partitions.log let N++ done < /mnt/Monitor_Disk/device_list .log ECHO 90 rm -fr /mnt/Monitor_Disk } ECHO(){ for ((i=1;i<=$1;i++)) do echo -n "#" [ $i - eq $1 ]&&( echo ; echo ) done } Monitor_Disk [root@ceph-node1 ~] # chmod 755 disk_monit.sh [root@ceph-node1 ~] # sh disk_monit.sh ########################################################################################## ** 第1块硬盘( /dev/sdb ):577.4GB ** ------------------------------------ linux分区 挂载目录 总大小 已用 剩余 已用百分比 文件系统 ID system 块大小 预留空间 ========= ======== ===== === === ========== ======= == ====== ====== ======== /dev/sdb1 /data 530G 42G 461G 9% ext4(rw) 83 Linux 4K 27532M ** 第2块硬盘( /dev/sda ):322.1GB ** ------------------------------------ linux分区 挂载目录 总大小 已用 剩余 已用百分比 文件系统 ID system 块大小 预留空间 ========= ======== ===== === === ========== ======= == ====== ====== ======== /dev/sda1 /boot 283M 76M 193M 29% ext4(rw) 83 Linux 1K 15M /dev/sda3 / 265G 3.1G 248G 2% ext4(rw) 83 Linux 4K 13744M ########################################################################################## |
Linux机器-网卡磁盘监控的更多相关文章
- 监控linux服务器网卡流量
监控linux服务器网卡流量 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 欢迎加入:高级运维工程师之路 598432640 前言:众所周知,我们安装zabbix服务器 ...
- PHP获取网卡的MAC地址原码;目前支持WIN/LINUX系统 获取机器网卡的物理(MAC)地址
声明转换于其它博客当中的. <?php /** 获取网卡的MAC地址原码:目前支持WIN/LINUX系统 获取机器网卡的物理(MAC)地址 **/ class GetMacAddr{ var $ ...
- cacti监控linux和windows磁盘IO
cacti监控linux和windows磁盘IO 标签:cacti linux磁盘IO windows磁盘IO 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则 ...
- Linux简单Shell脚本监控MySQL、Apache Web和磁盘空间
Linux简单Shell脚本监控MySQL.Apache Web和磁盘空间 1. 目的或任务 当MySQL数据库.Apache Web服务器停止运行时,重新启动运行,并发送邮件通知: 当服务器磁盘的空 ...
- 【转载】Linux系统与性能监控
原文地址:http://kerrigan.sinaapp.com/post-7.html Linux System and Performance Monitoring http://www.hous ...
- Linux系统与性能监控
原文地址:http://kerrigan.sinaapp.com/post-7.html Linux System and Performance Monitoring http://www.hous ...
- Linux 服务器运行健康状况监控利器 Spotlight on Unix 的安装与使用
1.本文背景 1.1.Linux 服务器情况 # cat /etc/issueRed Hat Enterprise Linux Server release 6.1 (Santiago)Kernel ...
- Linux系统和性能监控之CPU篇
Linux系统和性能监控之CPU篇 性能优化就是找到系统处理中的瓶颈以及去除这些的过程.本文由sanotes.net站长tonnyom在2009年8月翻译自Linux System and Perfo ...
- Linux双网卡绑定bond详解--单网卡绑定多个IP
Linux双网卡绑定bond详解 1 什么是bond 网卡bond是通过多张网卡绑定为一个逻辑网卡,实现本地网卡的冗余,带宽扩容和负载均衡,在生产场景中是一种常用的技术.Kernels 2.4.12及 ...
随机推荐
- google云函数实现BigQuery数据操作
Google Cloud Function操作BigQuery数据库. 1.部署云函数时在配置文件中(package.json)添加一项 "@google-cloud/bigquery&qu ...
- Teaching Is a Fruitful Way to Learn【教学是一种有效的学习方式】
Teaching Is a Fruitful Way to Learn For thousands of years, people have known that the best way to u ...
- 对文件 I/O,标准 I/O 的缓冲的理解
1.标准I/O缓冲区 要理解标准I/O,就要先知道文件I/O的业务逻辑. 下面图示为文件I/O 如执行下面的代码: write(fd, buf2, sizeof(buf2)); 图中 buf:就是bu ...
- MySQL忘记密码怎么重置
1打开mysql.exe和mysqld.exe所在的文件夹,复制路径地址 输入命令 mysqld --skip-grant-tables 回车,此时就跳过了mysql的用户验证.注意输入此命令之后 ...
- Java石头剪刀布小游戏
package com.neusoft.test; import java.awt.BorderLayout; import java.awt.Choice; import java.awt.Colo ...
- EF实体部分更新的问题
之前遇到只更新部分的问题:如前端修改用户信息(不修改密码),传实体到后台,这个实体是没有密码,这样一来要更新的话,得先去数据库通过传过来的实体的ID读取这条记录,然后将改动的部分填到查出来的记录中,再 ...
- python读取文件
请参考:http://www.cnblogs.com/sysuoyj/archive/2012/03/14/2395789.html
- linux上Kettle定时执行(转换的单步执行,job的单步执行,环境变量,kettle定时功能,效率问题等)转自(http://blog.csdn.net/feng19821209/article/details/5800960)
1,Kettle跨平台使用. 例如:在AIX下(AIX是IBM商用UNIX操作系统,此处在LINUX/UNIX同样适用),运行Kettle的相关步骤如下: 1)进入到Kettle部署的路径 ...
- 8 实现10mins用户登录与注册
1.重新认识登录 2.实现登录功能 (1)Django 自带的authenticate, login模块 from django.contrib.auth import authenticate, l ...
- (1)strchr
const char * strchr ( const char * str, int character ); char * strchr ( char * str, int character ) ...