仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 755|回复: 8
打印 上一主题 下一主题

[shell编程] 带来一篇几个经常使用的Linux操纵体系监控剧本

[复制链接]
分手快乐 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-14 20:17:32 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
欢迎大家来到仓酷云论坛!
本文先容了几个经常使用的Linux监控剧本,能够完成主机网卡流量、体系情况、主机磁盘空间、CPU和内存的利用情形等方面的主动监控与报警。依据本人的需求写出的shell剧本更能满意需求,更能细化主机监控的周全性。
本文先容了几个经常使用的Linux监控剧本,能够完成主机网卡流量、体系情况、主机磁盘空间、CPU和内存的利用情形等方面的主动监控与报警。依据本人的需求写出的shell剧本更能满意需求,更能细化主机监控的周全性。
比来时不时有互联网的伴侣问我关于办事器监控方面的成绩,问经常使用的办事器监控除用开源软件,好比:cacti,nagios监控外是不是能够本人写shell剧本呢?依据本人的需求写出的shell剧本更能满意需求,更能细化主机监控的周全性。
上面是我经常使用的几个主机监控的剧本,人人能够依据本人的情形再举行修正,但愿能给人人一点匡助。
1、检察主机网卡流量
[color=#333333!important]












1


[color=#b85c00!important]#!/bin/bash#network#Mike.Xuwhile:;dotime=date+%m"-"%d""%k":"%Mday=date+%m"-"%drx_before=ifconfigeth0|sed-n"8"p|awk{print$2}|cut-c7-tx_before=ifconfigeth0|sed-n"8"p|awk{print$6}|cut-c7-sleep2rx_after=ifconfigeth0|sed-n"8"p|awk{print$2}|cut-c7-tx_after=ifconfigeth0|sed-n"8"p|awk{print$6}|cut-c7-rx_result=$[(rx_after-rx_before)/256]tx_result=$[(tx_after-tx_before)/256]echo"$timeNow_In_Speed:"$rx_result"kbpsNow_OUt_Speed:"$tx_result"kbps"sleep2done




2、体系情况监控
[color=#333333!important]












1


[color=#b85c00!important]#!/bin/sh#systemstat.sh#Mike.XuIP=192.168.1.227top-n2|grep"Cpu"》./temp/cpu.txtfree-m|grep"Mem"》./temp/mem.txtdf-k|grep"sda1"》./temp/drive_sda1.txt#df-k|grepsda2》./temp/drive_sda2.txtdf-k|grep"/mnt/storage_0"》./temp/mnt_storage_0.txtdf-k|grep"/mnt/storage_pic"》./temp/mnt_storage_pic.txttime=`date+%m"."%d""%k":"%M`connect=`netstat-na|grep"219.238.148.30:80"|wc-l`echo"$time$connect"》./temp/connect_count.txt




3、监控主机的磁盘空间,当利用空间凌驾90%就经由过程发mail来发告诫
[color=#333333!important]












1


[color=#b85c00!important]#!/bin/bash#monitoravailablediskspaceSPACE=df|sed-n//$/p|gawk{print$5}|seds/%//if[$SPACE-ge90]thenitchenyi@gmail.comfi




4、监控CPU和内存的利用情形
<divid="crayon-5268daf2631be562868773"class="crayon-syntaxcrayon-theme-classiccrayon-font-monacocrayon-os-pcprint-yescrayon-wrapped"data-settings="minimizescroll-mou搜索引擎优化verwrap"style="margin:12px0px;padding:0px;border:1pxsolid#999999!important;font-size:12px!important;background-color:#fdfdfd!important;box-sizing:border-box;overflow:hidden!important;position:relative!important;direction:ltr!important;width:668px;font-family:monaco,monacoregular,couriernew,monospace;text-shadow:none!important;max-width:700px;float:none;clear:both;line-height:15px!important;height:auto;">[color=#333333!important]












<divclass="crayon-main"style="margin:0px;padding:0px;border:0px;width:666px;overflow:hidden;max-width:700px;position:relative;z-index:1;background-position:0px50%;">
1

[color=#317cc5!important]2

3

[color=#317cc5!important]4

5

[color=#317cc5!important]6

7

[color=#317cc5!important]8

9

[color=#317cc5!important]10

11

[color=#317cc5!important]12

13

[color=#317cc5!important]14

15

[color=#317cc5!important]16

17

[color=#317cc5!important]18

19


<divclass="crayon-pre"style="margin:0px;padding:0px;border:none!important;background-image:none!important;overflow:visible;">[color=#b85c00!important]#!/bin/bash#scripttocapturesystemstatisticsOUTFILE=/home/xu/capstats.csv

[color=#002d7a!important]DATE[color=#006fe0!important]=[color=#008000!important]date+%m/%d/%Y

[color=#002d7a!important]TIME[color=#006fe0!important]=[color=#008000!important]date+%k:%m:%s

[color=#002d7a!important]TIMEOUT[color=#006fe0!important]=[color=#008000!important]uptime

[color=#002d7a!important]VMOUT[color=#006fe0!important]=[color=#008000!important]vmstat12

[color=#002d7a!important]USERS[color=#006fe0!important]=[color=#008000!important]echo$TIMEOUT|gawk[color=#333333!important]{print[color=#006fe0!important][color=#333333!important][color=#333333!important]$[color=#ce0000!important]4[color=#333333!important]}[color=#008000!important]

[color=#002d7a!important]LOAD[color=#006fe0!important]=[color=#008000!important]echo$TIMEOUT|gawk[color=#333333!important]{print[color=#006fe0!important][color=#333333!important][color=#333333!important]$[color=#ce0000!important]9[color=#333333!important]}[color=#008000!important]|sed"s/,//[color=#006fe0!important][color=#008000!important]

[color=#008000!important]FREE=echo[color=#006fe0!important][color=#333333!important][color=#333333!important]$VMOUT[color=#006fe0!important][color=#006fe0!important]|[color=#006fe0!important]sed[color=#006fe0!important][color=#006fe0!important]-n[color=#006fe0!important][color=#008000!important]/[0-9]/p[color=#006fe0!important][color=#006fe0!important]|[color=#006fe0!important]sed[color=#006fe0!important][color=#006fe0!important]-n[color=#006fe0!important][color=#008000!important]2p[color=#006fe0!important][color=#006fe0!important]|[color=#006fe0!important]gawk[color=#006fe0!important][color=#008000!important]{print$4}[color=#006fe0!important][color=#008000!important]

<divclass="crayon-line"id="crayon-5268daf2631be562868773-17"style="margin:0px;padding:0px5px;border:0px;font-size:inherit!important;font-family:inherit;line-height:inherit!important;height:inherit!important;background-position:0px50%;">[color=#008000!important]IDLE=echo[color=#006fe0!important][color=#333333!important][color=#333333!important]$VMOUT[color=#006fe0!important][color=#006fe0!important]|[color=#006fe0!important]sed[color=#006fe0!important][color=#006fe0!important]-n[color=#006fe0!important][color=#008000!important]/[0-9]/p[color=#006fe0!important]
沙发
发表于 2015-1-15 16:31:14 | 只看该作者

带来一篇几个经常使用的Linux操纵体系监控剧本

我一直以为自己的阅读理解能力比较强,平常的文章只要大部分字是认识的,只要仔细读读想想就能明白个八九不离十了……但是楼主的帖子我连看两遍,又看了一些回帖,才勉强看懂一些……
爱飞 该用户已被删除
板凳
发表于 2015-1-24 15:39:45 | 只看该作者
在学习的过程中,我们用的是VM虚拟机,开始时真的不真的该怎么去做,特别是我的是命令窗口界面,别人的是图形界面,我都不知道怎么调过来。
小妖女 该用户已被删除
地板
发表于 2015-2-2 11:01:39 | 只看该作者
Linux简单,占内存少,特别是对于程序开发人员来说很方便,如果说windows的成功在于其方便用户的窗口管理界面。
再现理想 该用户已被删除
5#
发表于 2015-2-7 19:29:01 | 只看该作者
我们这一代90后,从小接触的是windows98,家里条件好的自己有电脑装的是2000,后来又有了XP,上大学时又有了win7。
莫相离 该用户已被删除
6#
发表于 2015-2-23 13:51:35 | 只看该作者
熟悉操作是日常学习Linux中的三大法宝。以下是作者学习Linux的一些个人经验,供参考:
乐观 该用户已被删除
7#
发表于 2015-3-7 11:33:55 | 只看该作者
我们这一代90后,从小接触的是windows98,家里条件好的自己有电脑装的是2000,后来又有了XP,上大学时又有了win7。
冷月葬花魂 该用户已被删除
8#
发表于 2015-3-15 07:30:33 | 只看该作者
永中office 2004增强版安装只需要默认安装即可使用并操作大多与win系统雷同,打印机的配置和管理,记录光盘等。
精灵巫婆 该用户已被删除
9#
发表于 2015-3-22 00:09:22 | 只看该作者
为了更好的学习这门课程,我不仅课上认真听讲,课下也努力学习,为此还在自己的电脑上安装了Ubuntu系统。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-11 14:57

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表