ubuntu下netstat和mrtg监控安装.docx

上传人:b****7 文档编号:10900228 上传时间:2023-02-23 格式:DOCX 页数:10 大小:17.33KB
下载 相关 举报
ubuntu下netstat和mrtg监控安装.docx_第1页
第1页 / 共10页
ubuntu下netstat和mrtg监控安装.docx_第2页
第2页 / 共10页
ubuntu下netstat和mrtg监控安装.docx_第3页
第3页 / 共10页
ubuntu下netstat和mrtg监控安装.docx_第4页
第4页 / 共10页
ubuntu下netstat和mrtg监控安装.docx_第5页
第5页 / 共10页
点击查看更多>>
下载资源
资源描述

ubuntu下netstat和mrtg监控安装.docx

《ubuntu下netstat和mrtg监控安装.docx》由会员分享,可在线阅读,更多相关《ubuntu下netstat和mrtg监控安装.docx(10页珍藏版)》请在冰豆网上搜索。

ubuntu下netstat和mrtg监控安装.docx

ubuntu下netstat和mrtg监控安装

连接数监控:

连接数监控为ubuntu自带监控系统netstat

用法:

功能说明:

Netstat用于显示与IP、TCP、UDP和ICMP协议相关的统计数据,一般用于检验本机各端口的网络连接情况

参  数:

-a或–all显示所有连线中的Socket。

-A<网络类型>或–<网络类型>列出该网络类型连线中的相关地址。

-c或–continuous持续列出网络状态。

-C或–cache显示路由器配置的快取信息。

-e或–extend显示网络其他相关信息。

-F或–fib显示FIB。

-g或–groups显示多重广播功能群组组员名单。

-h或–help在线帮助。

-i或–interfaces显示网络界面信息表单。

-l或–listening显示监控中的服务器的Socket。

-M或–masquerade显示伪装的网络连线。

-n或–numeric直接使用IP地址,而不通过域名服务器。

-N或–netlink或–symbolic显示网络硬件外围设备的符号连接名称。

-o或–timers显示计时器。

-p或–programs显示正在使用Socket的程序识别码和程序名称。

-r或–route显示RoutingTable。

-s或–statistice显示网络工作信息统计表。

-t或–tcp显示TCP传输协议的连线状况。

-u或–udp显示UDP传输协议的连线状况。

-v或–verbose显示指令执行过程。

-V或–version显示版本信息。

-w或–raw显示RAW传输协议的连线状况。

-x或–unix此参数的效果和指定”-Aunix”参数相同。

–ip或–inet此参数的效果和指定”-Ainet”参数相同

注意:

标红为常用参数

也可用nethogs:

下载和安装nethogs:

$sudoapt-getinstallnethogs

使用nethogs:

$sudonethogseth0

注意:

该程序需要root权限,默认是监控eth0网卡,所以直接输入sudonethogs也可以,如果有多网卡的话就必须进行指定。

系统硬件监控:

MRTG

安装mrtg

切换到超级用户:

 

sudo-sH 

安装软件:

  

apt-getinstallmrtg 

apt-getinstallsnmpd 

编辑snmpd:

 

vim/etc/snmp/snmpd.conf

在文件末尾加入:

 #sec.namesourcecommunity 

#com2secparanoiddefaultpublic#kommentieren 

com2secreadonlydefaultpublic#<-auskommentieren 

#com2secreadwritedefaultprivate

重启snmpd服务:

 

/etc/init.d/snmpdrestart 

重新生成mrtg的配置文件:

 

cfgmakerpublic@localhost>/etc/mrtg.cfg 

(注意)如果仅仅监视一个IP地址采用如下命令:

 

cfgmakerpublic@主机ip>>/etc/mrtg.cfg 

生成mrtg的主页:

 

indexmaker/etc/mrtg.cfg>/var/www/mrtg/index.html 

访问:

 

二安装CPU负载监视[默认5分钟采集一次] 

切换到超级用户:

 

sudo-sH 

安装软件:

 

apt-getinstallsysstat 

建立CPU脚本:

 

mkdir/opt/mrtg 

vim/opt/mrtg/mrtg.cpu

 

#!

/bin/bash 

cpuusr=`/usr/bin/sar-u13|grepAverage|awk'{print$3}'` 

cpusys=`/usr/bin/sar-u13|grepAverage|awk'{print$5}'` 

UPtime=`/usr/bin/uptime|awk'{print$3""$4""$5}'` 

echo$cpuusr 

echo$cpusys 

echo$UPtime 

hostname 

使脚本可以执行:

 

chmod755/opt/mrtg/mrtg.cpu 

修改/etc/mrtg.cfg在文件最后加入cpu项目 

Target[cpu]:

`/opt/mrtg/mrtg.cpu` 

MaxBytes[cpu]:

100 

Options[cpu]:

gauge,nopercent,growright 

YLegend[cpu]:

CPUloading(%) 

ShortLegend[cpu]:

LegendO[cpu]:

 CPUus; 

LegendI[cpu]:

 CPUsy; 

Title[cpu]:

CPULoading 

PageTop[cpu]:

CPULoading

 

重新生成索引页面:

 

indexmaker/etc/mrtg.cfg>/var/www/mrtg/index.html 

三安装WWW连接数监视[默认5分钟采集一次] 

切换到超级用户:

 

sudo-sH 

建立WWW脚本:

  

vim/opt/mrtg/mrtg.www

 

#!

/bin/bash 

all=`netstat-a|grepwww|awk'{print$5}'|sort|wc-l|awk'{print$1-1}'` 

user=`netstat-a|grepwww|awk'{print$5}'|cut-d":

"-f1|sort|uniq|wc-l|awk'{print$1-1}'` 

if["$all"="-1"];then 

echo0 

else 

echo$all 

fi 

if["$user"="-1"];then 

echo0 

else 

echo$user 

fi 

UPtime=`/usr/bin/uptime|awk'{print$3""$4""$5}'` 

echo$UPtime 

hostname 

使脚本可以执行:

 

chmod755/opt/mrtg/mrtg.www 

修改/etc/mrtg.cfg在文件最后加入www项目 

Target[www]:

`/opt/mrtg/mrtg.www` 

MaxBytes[www]:

500 

Options[www]:

nopercent,growright 

YLegend[www]:

OnlineUsers 

ShortLegend[www]:

LegendI[www]:

 Connect:

 

LegendO[www]:

 Online:

 

Title[www]:

WWWConnect 

PageTop[www]:

WWWConnect

 

重新生成索引页面:

 

indexmaker/etc/mrtg.cfg>/var/www/mrtg/index.html

四安装内存使用监视[默认5分钟采集一次] 

切换到超级用户:

 

sudo-sH 

建立RAM脚本:

 

vim/opt/mrtg/mrtg.ram 

#!

/bin/bash 

#runthisscripttocheckthememusage. 

totalmem=`/usr/bin/free|grepMem|awk'{print$2}'` 

usedmem=`/usr/bin/free|grepMem|awk'{print$3}'` 

UPtime=`/usr/bin/uptime|awk'{print$3""$4""$5}'` 

echo$totalmem 

echo$usedmem 

echo$UPtime 

hostname 

使脚本可以执行:

 

chmod755/opt/mrtg/mrtg.ram 

修改/etc/mrtg.cfg在文件最后加入ram项目 

Target[ram]:

`/opt/mrtg/mrtg.ram` 

#Unscaled[ram]:

dwym 

MaxBytes[ram]:

2048000 

Title[ram]:

Memory 

ShortLegend[ram]:

kmg[ram]:

kB,MB 

kilo[ram]:

1024 

YLegend[ram]:

 MemoryUsage:

 

Legend1[ram]:

 TotalMemory:

 

Legend2[ram]:

 UsedMemory:

 

LegendI[ram]:

 TotalMemory:

 

LegendO[ram]:

 UsedMemory:

 

Options[ram]:

growright,gauge,nopercent 

PageTop[ram]:

Memory

 

重新生成索引页面:

 

indexmaker/etc/mrtg.cfg>/var/www/mrtg/index.html 

五安装CPU温度监视[默认5分钟采集一次] 

切换到超级用户:

 

sudo-sH 

安装软件:

 

apt-getinstallmbmon 

建立CPU温度脚本:

 

vim/opt/mrtg/mrtg.temp 

#!

/bin/bash 

/usr/bin/mbmon-c1-i-T4-u-n 

exit0 

使脚本可以执行:

 

chmod755/opt/mrtg/mrtg.temp 

修改/etc/mrtg.cfg在文件最后加入cpu项目 

Target[temp]:

`/opt/mrtg/mrtg.temp` 

MaxBytes[temp]:

100 

Title[temp]:

CPUTemperature 

PageTop[temp]:

CPUTemperature

 

Options[temp]:

gauge,absolute,unknaszero,growright 

YLegend[temp]:

Temperature(C) 

ShortLegend[temp]:

(C) 

Legend1[temp]:

CPUTemperature 

Legend2[temp]:

M/BTemperature 

LegendI[temp]:

CPUTemp. 

LegendO[temp]:

M/BTemp. 

重新生成索引页面:

 

indexmaker/etc/mrtg.cfg>/var/www/mrtg/index.html

六硬盘读写监视[默认5分钟采集一次](不可与七同时作用) 

切换到超级用户:

 

sudo-sH 

建立硬盘读写脚本:

  

vim/opt/mrtg/mrtg.disk 

#!

/bin/bash 

hd=sda 

disk=/dev/$hd 

UPtime=`/usr/bin/uptime|awk'{print$3""$4""$5}'` 

KBread_sec=`iostat-x$disk|grep$hd|awk'{print8$}'` 

KBwrite_sec=`iostat-x$disk|grep$hd|awk'{print9$}'` 

echo$KBread_sec 

echo$KBwrite_sec 

echo$UPtime 

hostname 

使脚本可以执行:

 

chmod755/opt/mrtg/mrtg.disk 

修改/etc/mrtg.cfg在文件最后加入硬盘读写 

Target[disk]:

`/opt/mrtg/mrtg.disk` 

Title[disk]:

DiskHDAI/OUtilizationReport 

#Unscaled[disk]:

dwym 

MaxBytes[disk]:

10240000 

PageTop[disk]:

DiskI/OUtilizationReport

 

kmg[disk]:

KB,MB,GB 

LegendI[disk]:

DiskI/OKBread/sec 

LegendO[disk]:

DiskI/OKBwrite/sec 

Legend1[disk]:

DiskI/OKBread/sec 

Legend2[disk]:

DiskI/OKBwrite/sec 

YLegend[disk]:

Megabytes 

ShortLegend[disk]:

Options[disk]:

growright,gauge,nopercent 

重新生成索引页面:

 

indexmaker/etc/mrtg.cfg>/var/www/mrtg/index.html

七磁盘使用 (不可与六同时用)

切换到超级用户:

 

sudo-sH 

建立磁盘使用脚本:

  

vim/opt/mrtg/mrtg.df 

#!

/usr/bin/perl 

foreach$filesystem(`df-kl|grep-v"Filesystem"`) 

@df=split(/\s+/,$filesystem); 

$total+=$df[1]; 

$usage+=$df[2]; 

print"$total\n"; 

print"$usage\n"; 

hostname 

使脚本可以执行:

 

chmod755/opt/mrtg/mrtg.df 

修改/etc/mrtg.cfg在文件最后加入 

Target[disk]:

`/opt/mrtg/mrtg.df` 

Title[disk]:

DiskSpace 

Unscaled[disk]:

dwym 

MaxBytes[disk]:

465247550 

kmg[disk]:

KB,MB,GB 

LegendI[disk]:

TotalDiskSpace 

LegendO[disk]:

UsedDiskSpace 

Legend1[disk]:

TotalDiskSpace 

Legend2[disk]:

UsedDiskSpace 

YLegend[disk]:

Megabytes 

ShortLegend[disk]:

Options[disk]:

growright,nopercent 

PageTop[disk]:

DiskSpace

 

重新生成索引页面:

 

indexmaker/etc/mrtg.cfg>/var/www/mrtg/index.html

八交换分区 

切换到超级用户:

 

sudo-sH 

建立交换分区脚本:

  

vim/opt/mrtg/mrtg.swap 

#!

/bin/bash 

#Thisscripttomonitortheswapusage. 

totalswap=`/usr/bin/free|grepSwap|awk'{print$2}'` 

usedswap=`/usr/bin/free|grepSwap|awk'{print$3}'` 

echo"$totalswap" 

echo"$usedswap" 

使脚本可以执行:

 

chmod755/opt/mrtg/mrtg.swap 

修改/etc/mrtg.cfg在文件最后加入 

Target[swap]:

`/opt/mrtg/mrtg.swap` 

MaxBytes[swap]:

2048000 

Title[swap]:

MemoryStateofServer 

ShortLegend[swap]:

kmg[swap]:

kB,MB 

kilo[swap]:

1024 

YLegend[swap]:

SwapUsage 

Legend1[swap]:

TotalSwap 

Legend2[swap]:

UsedSwap 

LegendI[swap]:

TotalSwap 

LegendO[swap]:

UsedSwap 

Options[swap]:

growright,gauge,nopercent 

PageTop[swap]:

Swap

 

重新生成索引页面:

 

indexmaker/etc/mrtg.cfg>/var/www/mrtg/index.html 

访问

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 历史学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1