Submitted by admin on 2011, July 22, 9:48 PM
1/ 简介
在多数情况下,使用MRTG的基本配置来监测系统的网络流量是不够的。你还可能想看一看CPU、磁盘和内存使用的曲线。这一章解释如何在SNMP的MIB文件中找到你要查看的值,如何利用这些信息配置MRTG。
本章中所有的实例使用SNMP的只读COMMUNITY串为“craz33guy”,并且net-snmp-utils的RPM包已经安装。(参考22章,“监测系统性能”)。
2/ 查找和查看Linux的MIBs的内容
MIBs以数据方式居留在内存当中,并通过SNMP进程不断更新。MIB的配置文本文档位于硬盘中,并当每次SNMP重启时加载到内存中。
你能够很容易地使用命令“locate”和过滤器让输出过滤为仅包含“snmp”来找到Fedora的MIBs。就像下面这样例子一样,MIBs的位置在/usr/share/snmp/mibs/目录中:
[root@bigboy tmp]# locate mib | grep snmp/usr/share/doc/net-snmp-5.0.6/README.mib2c/usr/share/snmp/mibs/usr/share/snmp/mibs/DISMAN-SCHEDULE-MIB.txt......[root@bigboy tmp]#由于MIB的配置文件是用文本文件方式存储的,所以我们可以使用“grep”命令来搜索关键词。下面这个例子查找追踪TCP连接的MIBs,RFC1213和TCP MIBs就是返回的结果。
[root@silent mibs]# grep -i tcp /usr/share/snmp/mibs/*.txt | grep connections...RFC1213-MIB.txt: "The limit on the total number of TCP connectionsRFC1213-MIB.txt: "The number of times TCP connections have made a...TCP-MIB.txt: "The number of times TCP connections have made a......[root@silent mibs]#我们可以使用编辑器vi来查看MIBs。不要改变它们,因为这样会导致SNMP失败。MIBs非常复杂,但庆幸的是关键区域则是可以注释的(commented ?)。
MIB里的每一个值都被称为一个对象,且经常与它的目标ID或OID对应。在RFC1213-MIB.txt中,我们可以看到查询对象“tcpActiveOpens ”会返回一个服务器的激活的TCP连接数。字段“SYNTAX(语法)”表明这是一个计数值。
MIBs经常追踪两种类型的值:
计数值被用于随着时间不断增加的项,例如流经NIC的数据包的数目或自启动以来CPU工作的时间。
整数值是随时都在变化的值,这个在追踪内存被使用的统计情况是非常有用。
tcpActiveOpens OBJECT-TYPESYNTAX CounterACCESS read-onlySTATUS mandatoryDESCRIPTION"The number of times TCP connections have made adirect transition to the SYN-SENT state from theCLOSED state."::= { tcp 5 }tcpMaxConn OBJECT-TYPESYNTAX INTEGERACCESS read-onlySTATUS mandatoryDESCRIPTION"The limit on the total number of TCP connectionsthe entity can support. In entities where themaximum number of connections is dynamic, thisobject should contain the value -1."::= { tcp 4 }你会后面发现SNMP和MRTG之间用语的差异。理解它们在使用MRTG追踪MIB的值时是非常重要的。
3/ 测试你的MIB的值
一旦你确定一个感兴趣的Linux系统的MIB值,你就可以使用“snmpwalk”来收集它。多数情况下,MIB的文本别名只是对OID的分支有效,而 不是以额外的“.0”或“.1”结尾的OID的数据叶子。“snmpget”命令在使用分支时将会报错,说这个MIB变量找不到。
在下面这个例子中,我们对别名为”ssCpuRawUser”的OID感兴趣,但是“snmpget”却不能取到值。根据“snmpwalk”显示 的数据我们用“ssCpuRawUser.0”代替。现在“snmpget”就成功执行了,得到了“counter32”类型的数据,且值为 “396271”。
[root@bigboy tmp]# snmpget -v1 -c craz33guy localhost ssCpuRawUserError in packetReason: (noSuchName) There is no such variable name in this MIB.Failed object: UCD-SNMP-MIB::ssCpuRawUser[root@bigboy tmp]#[root@bigboy tmp]# snmpwalk -v1 -c craz33guy localhost ssCpuRawUserUCD-SNMP-MIB::ssCpuRawUser.0 = Counter32: 396241[root@bigboy tmp]# snmpget -v1 -c craz33guy localhost ssCpuRawUser.0UCD-SNMP-MIB::ssCpuRawUser.0 = Counter32: 396271[root@bigboy tmp]#用“snmpget”可以成功执行的MIB值,我们就可以使用MRTG来获得。
4/ MIB与MRTG名词解释之间的区别
要时刻记住MRTG引用MIB的计数值作为计数器的值。引用MIB整数和规格作为规格。默认情况下,MRTG把所有的值当作计数值。(有点不太顺,原文如 下:Always keep in mind that MRTG refers to MIB counter values as counter values. It refers to MIB integer and gauge values as gauge. By default, MRTG considers all values to be counters. )
MRTG并不用计数值来绘制不断增加的曲线,它只使用与最后一次收集时的数据相比改变的值来绘制曲线。CPU使用情况是典型的被MIBs追踪的计数值;幸运的是,你能够编辑MRTG的配置文档来让它以百分比的形式来绘制曲线(后面有详细说明)。
语法类型,MIB对象名称和它是什么的描述是你在配置MRTG时要知道的最重要的事情。这个将在后面说明。
5/ 监测CPU和内存的MIB(?)
名称为“UCD-SNMP-MIB ”追踪MIB对象的关键性能,包括下图中最常用的几个。
5.1/ 在UCD-SNMP-MIB中重要的对象
##UCD-SNMP-MIB
## 对象变量 MIB类型 MRTG类型 描述
## =========== ======= ======== =========
ssCpuRawUser Counter Counter 系统启动之后未授权用户运行的
程序占用CPU的总量
—————————————————————-
ssCpuRawSystem Counter Counter 系统启动之后授权的系统进程
运行的程序占用的CPU总量
—————————————————————-
ssCpuRawNice Counter Counter 运行在非默认优先权级别的
程序占用的CPU总量
—————————————————————-
ssCpuRawIdle Counter Counter 某一时刻空闲CPU所占百分比。
用100减去这个值会对整个CPU的
使用情况有较好的估计
—————————————————————-
6/ 监测TCP/IP的MIB
名称为“TCP-MIB”追踪数据连接信息,包括了非常有用的对象“tcpActiveOpens”和“tcpCurrEstab”。
6.1/ 在TCP-MIB中重要的对象
## TCP-MIB对象变量 MIB类型 MRTG类型 描述
## =============== ======= ======== =========
tcpActiveOpens Counter Counter 衡量已完成的TCP连接数
—————————————————————-
tcpCurrEstab Gauge Gauge 衡量处于“established”
状态的TCP连接数
—————————————————————-
tcpInErrs Counter Counter 带有验证错误的TCP段的数目
—————————————————————-
7/ 手动配置MRTG文档
MRTG的cfgmaker程序只是为网络接口建立配置文档,同时追踪两个OIDs:网络接口的输入和输出数据统计信息。MRTG的程序使用这些配置文档 来决定记录在它的数据目录中的数据类型。indexmaker程序也使用这些信息来建立总的消息,或者对你监测的OIDs进行一个可浏览的网页摘要。
摘要页只显示每天的统计信息。单击摘要图可以看到它后面的详细页面,有每天、每周、每月和每年的曲线。配置文档中的一些参数参阅详细信息,其它的参阅摘要信息。
如果你想监测其它的OIDs,你要手动建立配置文档,因为cfgmaker除了与NIC有关的OIDs之外的OIDs就不知道了。MRTG和 indexmaker程序会自定义的配置文档当中发现(fed ?)独立的OIDs,如果你编辑正确的话,那它就完成你所期望的功能。
7.1/ 参数格式
MRTG配置参数总是跟着一个用“[]”括起来的曲线名称和一个“:”。格式如下:
Parameter[graph name]: value为了便于编辑,针对某一个特定的曲线的参数通常会成组放在一起。每一个曲线能够追踪两个列在目标参数中的OIDs,它通常被放置在曲线名称列表的最上方。这两个OID值用“&”分隔;第一个是输入OID,第二个是输出OID。
7.2/ legend参数
在详细的Web浏览页,每一个曲线都有一个legend被用来显示OID的统计信息的最大值、平均数和当前值。你可以用“legendI”参数来描述输入曲线(第一个OID曲线),用“legendO”参数来描述输出曲线(第二个OID曲线)。
在每一个曲线legend下文的可用空白都是很少的,这样MRTG还有“legend1”和“legend2”两个参数要放在页面的最底部来提供更多的详细资料。参数“legend1”是“legendI”的扩展,参数“legend2”是“legendO”的扩展。
“Ylegend”是Y轴的legend,它的值就是你想比较的值。在默认的MRTG的配置文档中它可能是位或字节每秒流经接口的数据流。下面是一个默认的MRTG的配置档:
YLegend[graph1]: Bits per secondLegend1[graph1]: Incoming Traffic in Bits per SecondLegend2[graph1]: Outgoing Traffic in Bits per SecondLegendI[graph1]: InLegendO[graph1]: Out要是不想让MRTG在曲线底部显示某项legend,可以让该legend的值为空就可以了:
LegendI[graph1]:在后面你将会知道如何在不同的情形中匹配legend与OIDs。
7.3/ 选项参数
选项参数给MRTG提供了曲线格式的一个信息。选项growright保证屏幕右边的数据是最近的曲线的值。这使曲线更直观更容易读懂。MRTG默认的选项是从左边增长。
选项nopercent防止MRTG在曲线的底部的legends处打印出百分比样式的统计信息。选项gauge警告MRTG的一个事实,那就是曲线的值是“gauge”类型的。如果你监测的值是字节类型的,你可以通过选项bits来使输出转换成“bits”类型的。同样,你可以通过选项perminute将曲线的值从每秒转换成每分钟。下面是两种不同曲线的一些实例:
options[graph1]: growright,nopercent,perminuteoptions[graph2]: gauge,bits如果你将一个选项放在顶端并跟着一个“[_]”就表明这个选项会对这个文件当中所有的曲线都有效,例如:
options[_]: growright摘要页的标题由选项Title标明,详细页的标题由选项PageTop标明。“PageTop”选项的值必须用“< H1 >”括起来。
Title[graph1]: Interface eth0PageTop[graph1]: < H1 >Detailed Statistics For Interface eth0 < H1 >7.4/ 缩放比例参数
参数MaxBytes是MRTG在曲线图中数据的最大值。任何超过这个值的都会超过曲线的边界而看不见。
MRTG还是会尽量调整它的曲线使它的最大值一直接近它的曲线的顶端。这种情况即使你设置了最大值也还是会发生。
当你收集一个值,它有已知的最大值,你可能想让这个值一直呆在竖直legend的顶端,那么你可能要关闭MRTG的自动缩放。如果你收集CPU使用 的百分比,而服务器则达到了最大值的60%,通过缩放,MRTG就会使竖直的数据从0%到60%,这个垂直方向波峰就接近曲线的顶端了。
当缩放关闭时,而且MaxBytes被设置为100,那么曲线的值就会从0%到100%,而波峰则只会60%。下面这个例子将详细页面中的每年、每月、每周和每天视图的缩放去掉了,并且设定了最大值为100。
Unscaled[graph1]: ymwdMaxBytes[graph1]: 1007.5/ 定义MIB目标参数
就像前面所说的那样,MRTG总是比较目标参数定义的两个MIB OID的值。我们要指定两个MIB OID对象,SNMP密码和你要查询设备的IP地址,并用“&”将它们分开。
Target[graph1]: mib-object-1.0&mib-object-2.0:<SNMP-password>@<IP-address>在MIB最后的数值,在这里是“.0”,是需要的。下面这个例子返回了LINUX服务器的CPU在用户模式下的综合使用情况。注意输出当中的“.0”是跟在标记的后面的。
[root@silent mibs]# snmpwalk -v 1 -c craz33guy localhost ssCpuRawUserUCD-SNMP-MIB::ssCpuRawUser.0 = Counter32: 926739[root@silent mibs]#7.5.1/ 将MIBs映射到曲线的legend
MRTG的legend映射到MIBs的列表在下面:
Legend Maps To Target MIBLegend1 #1Legend2 #2LegendI #1LegendO #2所以,在下面这个例子中,legend1和legendI描述的是mib-object-1.0,而legend2和legendO描述的是mib-object-2.0。
Target[graph1]: mib-object-1.0&mib-object-2.0:<SNMP-password>@<IP-address>7.5.2/ 只绘制一个MIB值
如果你只想绘制一个MIB的值,你只需像下面例子中一样重复对目标MIB的定义就可以了,这里只绘制mib-object-1。结果MRTG曲线实际上superimposes输入和输出曲线一个接着一个。
Target[graph1]: mib-object-1.0&mib-object-1.0:<SNMP-password>@<IP-address>7.5.3/ Adding MIB Values Together For a Graph
你可以用“+”将一对MIB对象连接起来。下面这个实例将mib-object-1.0和mib-object-3.0添加到一个曲线中,并将mib-object-2.0和mib-object-4.0添加到另一个曲线中。
Target[graph1]: mib-object-1.0&mib-object-2.0:<SNMP-password>@<IP-address> + mib-object-3.0&mib-object-4.0:<SNMP-password>@<IP-address>你还可以使用其它的算术符号,如“-”,“*”和“%”,“(”和“)”也是有效的。在这些符号的左右都必须有空格,要不然你的曲线就会古怪而带有阴影。
7.5.4/ 目标实例:CPU使用情况
在Linux系统中CPU被系统进程、用户进程和一些运行在“nice”模式的进程所占用。下面这个实例将它们都放在一起了。
Target[graph1]:ssCpuRawUser.0&ssCpuRawUser.0:<SNMP-password>@<IP-address> + ssCpuRawSystem.0&ssCpuRawSystem.0:<SNMP-password>@<IP-address> + ssCpuRawNice.0&ssCpuRawNice.0:<SNMP-password>@<IP-address>请确认这些命令在单独的一行中。
7.5.5/ 目标实例:内存使用
下面是一个有关可用内存情况的例子。注意这是一个“gauge”类型的变量。
Target[graph1]: 垃圾广告vailReal.0&memTotalReal.0:<SNMP-password>@<IP-address>options[graph1]: nopercent,growright,gauge接下来,是一个可用内存百分比的例子。注意在数学运算符与下一个目标对象之间有强制的空白。
Target[graph1]: ( 垃圾广告vailReal.0& 垃圾广告vailReal.0:<SNMP-password>@<IP-address> ) * 100 / ( memTotalReal.0&memTotalReal.0:<SNMP-password>@<IP-address> )options[graph1]: nopercent,growright,gauge7.5.6/ 目标实例:新建连接
HTTP流量是由通常是非常短的Web浏览的连接产生的。MIB对象tcpPassiveOpens追踪新建连接,并适合这种类型的数据传输。MIB对象tcpActiveOpens监测从服务器发起的新建连接。在小一点的Web站点,你可能要用选项perminute来使曲线更有意义。
Target[graph1]: tcpPassiveOpens.0& tcpPassiveOpens.0:<SNMP-password>@<IP-address>MaxBytes[graph1]: 1000000Options[graph1]: perminute7.5.7/ 目标实例:全部TCP建立连接
其它像FTP和SSH等协议则建立长时间的连接,当人们下载大的文件或者登陆到服务器上时。MIB对象tcpCurrEstab衡量连接状态为established的连接总数,并且它是一个gauge值。
Target[graph1]: tcpCurrEstab.0&tcpCurrEstab.0:<SNMP-password>@<IP-address>MaxBytes[graph1]: 1000000Options[graph1]: gauge7.5.8/ 目标实例:磁盘分区使用
在这个实例中,让我们来监测系统上的/var和/home分区。
1. 使用df -k列出在使用的分区。
[root@bigboy tmp]# df -kFilesystem 1K-blocks Used Available Use% Mounted on/dev/hda8 505605 128199 351302 27% //dev/hda1 101089 19178 76692 21% /boot/dev/hda5 1035660 122864 860188 13% /home/dev/hda6 505605 8229 471272 2% /tmp/dev/hda3 3921436 890092 2832140 24% /usr/dev/hda2 1510060 171832 1261520 73% /var[root@bigboy tmp]#2. 在snmpd.conf文档中添加两行:
disk /homedisk /var3. 重启SNMP来重读值
[root@bigboy tmp]# service snmpd restart4. 使用snmpwalk来查询MIBdskPercent。
对象dskPercent.1对应snmpd.conf中的对一个磁盘(/home),dskPercent.2对应第二个(/var)。
[root@bigboy tmp]# snmpwalk -v 1 -c craz33guy localhost dskPercent.1UCD-SNMP-MIB::dskPercent.1 = INTEGER: 13[root@bigboy tmp]# snmpwalk -v 1 -c craz33guy localhost dskPercent.2UCD-SNMP-MIB::dskPercent.2 = INTEGER: 73[root@bigboy tmp]#对于这些”gauge”MIB对象,你的MRTG目标可能会是这样子的:
Target[graph1]: dskPercent.1& dskPercent.1:<SNMP-password>@<IP-address>options[graph1]: growright,gauge7.5.9/ 定义全局变量
你要让MRTG知道你所使用的MIBs的位置。MRTG默认使用的路径可能无效。要用全局参数LoadMIBs来明确位置。你还要定义HTML文件保存位置;下面的例子明确了Fedora默认情况下MRTG的HTML文件目录。
LoadMIBs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt, /usr/share/snmp/mibs/TCP-MIB.txtworkdir: /var/www/mrtg/8/ 服务器高级监测实践
你现在能够将你所知道的联合起来建立一个配置文件来监测这些所有的变量,并且你能把它整合到现存的MRTG配置文件中。
8.1/ 一个完整的配置文档
下面是一个用来查询本地CPU,内存,磁盘和TCP连接信息的配置文件脚本。
## File: /etc/mrtg/server-info.cfg## Configuration file for non bandwidth server statistics### Define global options#LoadMIBs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt,/usr/share/snmp/mibs/TCP-MIB.txtworkdir: /var/www/mrtg/## CPU Monitoring# (Scaled so that the sum of all three values doesn't exceed 100)#Target[server.cpu]:ssCpuRawUser.0&ssCpuRawUser.0:craz33guy@localhost + ssCpuRawSystem.0&ssCpuRawSystem.0:craz33guy@localhost + ssCpuRawNice.0&ssCpuRawNice.0:craz33guy@localhostTitle[server.cpu]: Server CPU LoadPageTop[server.cpu]: < H1 >CPU Load - System, User and Nice Processes< /H1 >MaxBytes[server.cpu]: 100ShortLegend[server.cpu]: %YLegend[server.cpu]: CPU UtilizationLegend1[server.cpu]: Current CPU percentage loadLegendI[server.cpu]: UsedLegendO[server.cpu]:Options[server.cpu]: growright,nopercentUnscaled[server.cpu]: ymwd## Memory Monitoring (Total Versus Available Memory)#Target[server.memory]: 垃圾广告vailReal.0&memTotalReal.0:craz33guy@localhostTitle[server.memory]: Free MemoryPageTop[server.memory]: < H1 >Free Memory< /H1 >MaxBytes[server.memory]: 100000000000ShortLegend[server.memory]: BYLegend[server.memory]: BytesLegendI[server.memory]: FreeLegendO[server.memory]: TotalLegend1[server.memory]: Free memory, not including swap, in bytesLegend2[server.memory]: Total memoryOptions[server.memory]: gauge,growright,nopercentkMG[server.memory]: k,M,G,T,P,X## Memory Monitoring (Percentage usage)#Title[server.mempercent]: Percentage Free MemoryPageTop[server.mempercent]: < H1 >Percentage Free Memory< /H1 >Target[server.mempercent]: ( 垃圾广告vailReal.0&垃圾广告vailReal.0:craz33guy@localhost ) * 100 / ( memTotalReal.0&memTotalReal.0:craz33guy@localhost )options[server.mempercent]: growright,gauge,transparent,nopercentUnscaled[server.mempercent]: ymwdMaxBytes[server.mempercent]: 100YLegend[server.mempercent]: Memory %ShortLegend[server.mempercent]: PercentLegendI[server.mempercent]: FreeLegendO[server.mempercent]: FreeLegend1[server.mempercent]: Percentage Free MemoryLegend2[server.mempercent]: Percentage Free Memory## New TCP Connection Monitoring (per minute)#Target[server.newconns]: tcpPassiveOpens.0&tcpActiveOpens.0:craz33guy@localhostTitle[server.newconns]: Newly Created TCP ConnectionsPageTop[server.newconns]: < H1 >New TCP Connections< /H1 >MaxBytes[server.newconns]: 10000000000ShortLegend[server.newconns]: c/sYLegend[server.newconns]: Conns / MinLegendI[server.newconns]: InLegendO[server.newconns]: OutLegend1[server.newconns]: New inbound connectionsLegend2[server.newconns]: New outbound connectionsOptions[server.newconns]: growright,nopercent,perminute## Established TCP Connections#Target[server.estabcons]: tcpCurrEstab.0&tcpCurrEstab.0:craz33guy@localhostTitle[server.estabcons]: Currently Established TCP ConnectionsPageTop[server.estabcons]: < H1 >Established TCP Connections< /H1 >MaxBytes[server.estabcons]: 10000000000ShortLegend[server.estabcons]:YLegend[server.estabcons]: ConnectionsLegendI[server.estabcons]: InLegendO[server.estabcons]:Legend1[server.estabcons]: Established connectionsLegend2[server.estabcons]:Options[server.estabcons]: growright,nopercent,gauge## Disk Usage Monitoring#Target[server.disk]: dskPercent.1&dskPercent.2:craz33guy@localhostTitle[server.disk]: Disk Partition UsagePageTop[server.disk]: < H1 >Disk Partition Usage /home and /var< /H1 >MaxBytes[server.disk]: 100ShortLegend[server.disk]: %YLegend[server.disk]: UtilizationLegendI[server.disk]: /homeLegendO[server.disk]: /varOptions[server.disk]: gauge,growright,nopercentUnscaled[server.disk]: ymwd8.2/ 测试配置
下一步就是测试MRTG能否正确加载这个配置文件。
重启SNMP确认snmpd.conf中的磁盘监测命令被激活。运行/usr/bin/mrtg加上配置文件名三次。
[root@bigboy tmp]# service snmpd restart[root@bigboy tmp]# env LANG=C /usr/bin/mrtg /etc/mrtg/server-stats.cfg8.3/ 建立一个新的MRTG索引页,并包含这个文件
使用第22章中讲到的indexmaker命令包括原来的配置文件(/etc/mrtg/mrtg.cfg)再加上你所创建的新的配置文件(/etc/mrtg/server-stats.cfg)。
[root@bigboy tmp]# indexmaker --output=/var/www/mrtg/index.html \/etc/mrtg/mrtg.cfg /etc/mrtg/server-stats.cfg8.4/ 使用新的MRTG文档来配置cron
最后一步就是确认MRTG使用新的配置文件每隔5分钟就收集一下服务器的资料。只要在/etc/cron.d/mrtg中添加下面一行就可以了:
0-59/5 * * * * root env LANG=C /usr/bin/mrtg /etc/mrtg/server-stats.cfg一些Linux版本可能要求你修改/etc/crontab文件。你还可能需要使用命令service crond restart来重新启动cron以便让它读取新的配置文件。
[root@bigboy tmp]# service crond restart9/ 监测非Linux系统的MIB的值
到目前为止,我们所谈论的MIB都是Linux系统的。其它类型的系统需要额外的MIBs,这些MIBs的安装可能在用户指南中也没有说清楚,或者根本不可用。在这种情况下,你需要知道精确的OID的值。
9.1/ 情景
设想一下你们的小公司购买了二手的Cisco交换机来连接Web服务器到Internet上。在第22章中MRTG的基本配置,“监测系统性能”,提供了有关带宽的统计,但是你还想知道系统的CPU负载。从Cisco网站上下载MIBs,然后使用snmpget,但却不会成功。你不知道下一步该如何去做了。去查找OIDs。
当MIB的值失败时,最好去查找精确的OID的值。像多数的网络设备制造商一样,Cisco有一个FTP站点可供你下载MIBs和OIDs。Cisco的SNMP文件可以在ftp.cisco.com的/pub/mibs目录当中;而OIDs在它下面的oid目录中。
在查看了所有的OID文件之后,你认为CISCO-PROCESS-MIB.oid会包含需要的值,并在其中找到下面这些:
"cpmCPUTotalPhysicalIndex" "1.3.6.1.4.1.9.9.109.1.1.1.1.2""cpmCPUTotal5sec" "1.3.6.1.4.1.9.9.109.1.1.1.1.3""cpmCPUTotal1min" "1.3.6.1.4.1.9.9.109.1.1.1.1.4""cpmCPUTotal5min" "1.3.6.1.4.1.9.9.109.1.1.1.1.5""cpmCPUTotal5secRev" "1.3.6.1.4.1.9.9.109.1.1.1.1.6""cpmCPUTotal1minRev" "1.3.6.1.4.1.9.9.109.1.1.1.1.7""cpmCPUTotal5minRev" "1.3.6.1.4.1.9.9.109.1.1.1.1.8"9.2/ 测试OIDs
就像你看到的一样,所有的OIDs都是开始于1.3.6.1.4.1.9.9.109.1.1.1.1.的一棵相同的树的一部分。这个OIDs提供的值可能不完整,所以最好先用snmpwalk命令来获取根下面所有的值。
[root@bigboy tmp]# snmpwalk -v1 -c craz33guy cisco-switch 1.3.6.1.4.1..9.9.109.1.1.1.1SNMPv2-SMI::enterprises.9.9.109.1.1.1.1.2.1 = INTEGER: 0SNMPv2-SMI::enterprises.9.9.109.1.1.1.1.3.1 = Gauge32: 32SNMPv2-SMI::enterprises.9.9.109.1.1.1.1.4.1 = Gauge32: 32SNMPv2-SMI::enterprises.9.9.109.1.1.1.1.5.1 = Gauge32: 32[root@bigboy tmp]#虽然列在OID的文件当中,但1.1.1.1.6、1.1.1.1.7和1.1.1.1.8却没有被支持。这里注意一下,SNMP将原始OID文件中OID值的开始部分(1.3.6.1.4.1)映射为单词enterprise。
接下来,我们使用命令来设定snmpwalk返回的一个OID值。
[root@bigboy tmp]# snmpget -v1 -c craz33guy cisco-switch \enterprises.9.9.109.1.1.1.1.5.1SNMPv2-SMI::enterprises.9.9.109.1.1.1.1.5.1 = Gauge32: 33[root@bigboy tmp]#成功了!现在你就可以使用这个OID值,enterprises.9.9.109.1.1.1.1.5.1用于MRTG查询了。
10/ 用RRDtool来给MRTG加速
MRTG是一个非常有用的程序,但它有一些限制。每次设备被采集时,所有的曲线和Web页面都要重新建立一次。这就有可能使你的MRTG服务器过载,尤其是当你有大量的设备要监测时,只是那曲线就有可能需要超出5分钟的时间来生成。RRDtool是MRTG的作者写得另一个程序,它能够存储通用的数据,却按照需要来产生曲线。将与整合起来将会有一个引人注目的效率提升。下面实例演示如何快速实施一个通用的解决办法。
10.1/ 情景
RRDtool的用途需要降低监测服务器的负载,由于大量的每次采集产生的MRTG曲线而使服务器的性能较差。
由于空间的制约,RRD数据库需要存放在/var分区中。
服务器有默认Apache对CGI支持的配置,用于产生位于/var/www/cgi-bin目录中的动态内容。
需要一个用RRDtool格式读取MRTG数据的脚本。
MRTG的配置文档为/etc/mrtg/mrtg.cfg。
下面是如何操作:
10.2/ 安装RRDtool
RRDtool和RRDtool PERL模块可以从下面这个站点下载:http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/
但安装则比较严格,因为安装程序在错误的目录当中可能要寻找支持的库文件。
幸运的是,预先要安装的RRDtool和RRDtool perl包现在已经是多数linux发行版的一部分了。
10.3/ 用RRDtool格式来存储MRTG数据
整合的操作可以在几分钟内完成,但步骤却是严格的:
1. 第一步是添加一些新的选项到你的cfgmaker命令中。第一个指示MRTG只存储rrdtool格式的数据,第二个定义数据存储目录/var/mrtg。为了增添安全性,这个目录应该在你的Web服务器根目录的外部。
--global 'LogFormat: rrdtool' --global "workdir: /var/mrtg" --global 'IconDir: /mrtg'最后,你还应该指明一个icon目录,用于存储所有未分类的MRTG页面的图标。RRD的Web接口脚本,我们会在后面用一个不正确(?什么意思)的目录来安装。图标目录/mrtg实际上也是URL的一部分。在Fedora中,我们使用Apache默认的配置,这里MRTG的图标文件存放在/var/www/mrtg目录中。如果你使用了一个非默认的Apache的MRTG配置或使用其它的Linux的发行版本或不同的版本,你要将这些图标复制到自定义的目录当中。
2.第二步建立一个数据repository(库?)目录/var/mrtg,改变它的所有者为apache的用户(通常为apache或nobody),并使它能运行默认的Linux服务器程序。
[root@bigboy tmp]# mkdir /var/mrtg[root@bigboy tmp]# chown apache /var/mrtg[root@bigboy tmp]#注:如果你使用的是SELinux,那你要将目录的背景(context ?)与目录/var/www/html相匹配,这样当你的apache进程能够读取的CGI脚本需要的那些数据库文件。下面这些命令比较这两个目录的背景,并设置为正确的/var/mrtg。
[root@bigboy tmp]# ls -alZ /var/www | grep htmldrwxr-xr-x root root system_u:object_r:httpd_sys_content_t html[root@bigboy tmp]# ls -alZ /var | grep mrtgdrwxr-xr-x apache root root:object_r:var_t mrtg[root@bigboy tmp]# chcon -R -u system_u -r object_r -t httpd_sys_content_t /var/mrtg[root@bigboy tmp]#3. 我们现在需要测试一下RRD文件是否正确地被建立了。使用/etc/mrtg/mrtg.cfg作为源配置文件来运行MRTG,然后测试是否目录/var/mrtg中的内容被改变了。
成功!
[root@bigboy tmp]# ls /var/mrtg/localhost_192.168.1.100.rrd[root@bigboy tmp]#这些文件被正常建立了。接下来,我们需要找一个脚本来读取新的数据格式,并把它用Web格式表现出来。这就是我们接下来要讨论的。
10.4/ MRTG/RRDtool整合脚本
MRTG的官方网站建议mrtg-rrd站点(http://www.fi.muni.cz/~kas/mrtg-rrd/)上有个很好用的脚本。让我们继续来安装它。
1. 使用wget来下载脚本。这个站点上有几个不同的版本,下载最新的那个。
[root@bigboy tmp]# wget ftp://ftp.linux.cz/pub/linux/people/jan_kasprzak/mrtg-rrd/mrtg-rrd-0.7.tar.gz--12:42:12-- ftp://ftp.linux.cz/pub/linux/people/jan_kasprzak/mrtg-rrd/mrtg-rrd-0.7.tar.gz=> `mrtg-rrd-0.7.tar.gz'Resolving ftp.linux.cz... 147.251.48.205Connecting to ftp.linux.cz|147.251.48.205|:21... connected.Logging in as anonymous ... Logged in!.........15:24:50 (53.53 KB/s) - `mrtg-rrd-0.7.tar.gz' saved [20863][root@bigboy tmp]# lsmrtg-rrd-0.7.tar.gz[root@bigboy tmp]#2. 解压
[root@bigboy tmp]# tar -xzvf mrtg-rrd-0.7.tar.gzmrtg-rrd-0.7/mrtg-rrd-0.7/COPYINGmrtg-rrd-0.7/FAQmrtg-rrd-0.7/TODOmrtg-rrd-0.7/Makefilemrtg-rrd-0.7/mrtg-rrd.cgimrtg-rrd-0.7/ChangeLog[root@bigboy tmp]#3. 建立/var/www/cgi-bin/mrtg目录,拷贝文件mrtg-rrd.cgi到里面。
[root@bigboy tmp]# mkdir -p /var/www/cgi-bin/mrtg[root@bigboy tmp]# cp mrtg-rrd-0.7/mrtg-rrd.cgi /var/www/cgi-bin/mrtg/[root@bigboy tmp]#4. 编辑mrtg-rrd.cgi文件,使它调用文件/etc/mrtg/mrtg.cfg的详细配置,或者你将目录当中所有的.cfg文件都包含进去。
单个文件:
## File: mrtg-rrd.cgi (Single File)## EDIT THIS to reflect all your MRTG config filesBEGIN { @config_files = qw(/etc/mrtg/mrtg.cfg); }多个文件:
## File: mrtg-rrd.cgi (multipl .cfg files)## EDIT THIS to reflect all your MRTG config filesBEGIN { @config_files = ; }现在,你就可以通过浏览器来访问你的MRTG RRD曲线了:
http://ip/cgi-bin/mrtg/mrtg-rrd.cgi一旦安装上去,RRDtool的操作对MRTG来说就是透明的了。你要记得当你添加新的MRTG配置时也要添加RRD的声明,添加配置文件到CGI脚本中。我们的服务器终于可以喘口气了^-^.
11/ 疑难解答
这个有关MRTG高级应用的疑难解答与我们在第22章的有些类似。
1.确认目标设备的IP和community串
2.确认你能对目标设备进行SNMP walk。如果不能,修改目标设备上的访问控制或防火墙规则,它们可能阻碍SNMP经过。
3.确认你能够在你的MRTG配置文件中使用snmpget来获得特定OID的值。
4.检查MRTG参数来确认它们都是正确的。如果Guage值被定义成相反的counter或vice,那么会使你的曲线经常变成0值。如果你的参数设置为位,那曲线的结果可能是你期望的8倍。
5.在RRDtool初始化的整合里面有一些错误。
下面的消息显示在MRTG配置文件里CGI脚本不正确
Error: Cannot open config file: No such file or directory“权限禁止”通常是由于权限或SELinuxcontexts不正确而导致的。
Error: RRDs::graph failed, opening '/var/mrtg/localhost_192.168.1.100.rrd': Permission denied在/var/log/httpd/errorlog中“文件或目录不存在”的错误可能是MRTG的IconDir配置不正确所致。
[Wed Jan 04 15:42:13 2006] [error] [client 192.168.1.102] File does not exist: /var/www/html/var,referer: http://bigboy/cgi-bin/mrtg/mrtg-rrd.cgi/[Wed Jan 04 15:45:46 2006] [error] [client 192.168.1.102] script. not found or unable to stat:/var/www/cgi-bin/mrtg/mrtg-l.png, referer: http://bigboy/cgi-bin/mrtg/mrtg-rrd.cgi/这些快捷的步骤在多数情况下是充足的了,也使你的网络更加可管理了。
12/ 总结
使用本章中的指南,你应该可以对任何类型的设备绘制多数可用的SNMP MIB的值了。MRTG是一个优秀的、灵活的监测工具,它应该被任何系统管理员考虑作为服务器管理计划的一部分。
系统监控 | 评论:0
| Trackbacks:0
| 阅读:1253
Submitted by admin on 2011, July 22, 8:15 PM
1.下载 httpd,apr,apr-util,subversion源码包
2.建立svnroot用户
Bash代码
1.groupadd svn
2.useradd svnroot -g svn
3.passwd svn
groupadd svn
useradd svnroot -g svn
passwd svn
3.解压并安装apr,apr-util
4.安装httpd
Bash代码
1.tar xvzf httpd-2.2.17.tar.gz
2.cd httpd-2.2.17
3../configure --prefix=/opt/apache --enable-dav --enable-so
4.make && make install
tar xvzf httpd-2.2.17.tar.gz
cd httpd-2.2.17
./configure --prefix=/opt/apache --enable-dav --enable-so
make && make install 5.安装Subversion
Bash代码
1.tar xvzf subversion-1.6.9.tar.gz
2.tar xvzf subversion-deps-1.6.9.tar.gz
3.cd subversion-1.6.9
4../configure --with-apxs=/opt/apache/bin/apxs --prefix=/opt/subversion --with-apr=/usr/local/apr --with-apr-util=/usr/local/apu --with-ssl --with-zlib=/usr/lib --enable-maintainer-mode
5.make &&make install
tar xvzf subversion-1.6.9.tar.gz
tar xvzf subversion-deps-1.6.9.tar.gz
cd subversion-1.6.9
./configure --with-apxs=/opt/apache/bin/apxs --prefix=/opt/subversion --with-apr=/usr/local/apr --with-apr-util=/usr/local/apu --with-ssl --with-zlib=/usr/lib --enable-maintainer-mode
make &&make install
6.建立代码仓库
Bash代码
1.su svnroot
2.mkdir /home/svnroot/repository
3./opt/subversion/bin/svnadmin create /home/svnroot/repository/test
4.chmod 700 /home/svnroot/repository
5.su
su svnroot
mkdir /home/svnroot/repository
/opt/subversion/bin/svnadmin create /home/svnroot/repository/test
chmod 700 /home/svnroot/repository
su
7. 修改配置
Bash代码
1.vi /opt/apache/conf/httpd.conf
2. //找到下列语句,如果没有则自行添加
3. LoadModule dav_svn_module modules/mod_dav_svn.so
4. LoadModule authz_svn_module modules/mod_authz_svn.so
5. //在后面添加
6. <Location /svn>
7. DAV svn
8. SVNParentPath /home/svnroot/repository/ //svn父目录
9. AuthzSVNAccessFile /home/svnroot/repository/authz.conf //权限配置文件
10. AuthType Basic //连接类型设置
11. AuthName "Subversion.tips" //连接框提示
12. AuthUserFile /home/svnroot/repository/authfile //用户配置文件
13. Require valid-user //采用何种认证
14. </Location>
15.
16.//重启apache
17. # /opt/apache/bin/apachectl restart
18.//打开浏览器访问http://localhost/svn/test/,如果有东西显示就说明成功。
vi /opt/apache/conf/httpd.conf
//找到下列语句,如果没有则自行添加
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so
//在后面添加
<Location /svn>
DAV svn
SVNParentPath /home/svnroot/repository/ //svn父目录
AuthzSVNAccessFile /home/svnroot/repository/authz.conf //权限配置文件
AuthType Basic //连接类型设置
AuthName "Subversion.tips" //连接框提示
AuthUserFile /home/svnroot/repository/authfile //用户配置文件
Require valid-user //采用何种认证
</Location>
//重启apache
# /opt/apache/bin/apachectl restart
//打开浏览器访问http://localhost/svn/test/,如果有东西显示就说明成功。 8.配置权限
Bash代码
1.1)增加用户
2.# htpasswd -c /home/svnroot/repository/authfile 用户名
3.//第一次设置用户时使用-c表示新建一个用户文件。回车后输入用户密码,完成对用户的增加
4.# htpasswd /home/svnroot/repository/authfile 用户名(加入新的用户,就不用-c了)
5.
6.2)权限分配
7.# vi /home/svnroot/repository/authz.conf
8. [groups]
9.admin=useradmin
10.devteamcs = useradmin,user1,user2//这里定义了一个用户组
11.[/]//对所有的项目,所有的用户都有读权限,admin用户有读写权限
12.@admin = rw
13.* = r
14.[test:/]//对test项目,
15.@devteamcs = rw
16.// 在 /usr/local/apache2/conf/httpd.conf 文件中配置,找到文件中的这两行:
17.User daemon
18.Group daemon
19. // 将daemon改为svnroot,组也做相应更改,让apache进程以svnroot的身份运行
20.//改完后是这个样子
21.User svnroot
22.Group svn
23.//重启apache
24. # /opt/apache/bin/apachectl restart
25.访问http://localhost/svn/test ,现在需要身份验证,且通过验证后应该可以看到信息
1)增加用户
# htpasswd -c /home/svnroot/repository/authfile 用户名
//第一次设置用户时使用-c表示新建一个用户文件。回车后输入用户密码,完成对用户的增加
# htpasswd /home/svnroot/repository/authfile 用户名(加入新的用户,就不用-c了)
2)权限分配
# vi /home/svnroot/repository/authz.conf
[groups]
admin=useradmin
devteamcs = useradmin,user1,user2//这里定义了一个用户组
[/]//对所有的项目,所有的用户都有读权限,admin用户有读写权限
@admin = rw
* = r
[test:/]//对test项目,
@devteamcs = rw
// 在 /usr/local/apache2/conf/httpd.conf 文件中配置,找到文件中的这两行:
User daemon
Group daemon
// 将daemon改为svnroot,组也做相应更改,让apache进程以svnroot的身份运行
//改完后是这个样子
User svnroot
Group svn
//重启apache
# /opt/apache/bin/apachectl restart
访问http://localhost/svn/test ,现在需要身份验证,且通过验证后应该可以看到信息 9.结束
linux | 评论:0
| Trackbacks:0
| 阅读:905
Submitted by admin on 2011, July 22, 10:23 AM
# Created by
# /usr/bin/cfgmaker --global 'WorkDir: /var/www/mrtg' --global 'Options[_]: growright,bits' --ifref=ip --output /etc/mrtg/mrtg.cfg public@localhost
### Global Config
EnableIPv6: no
WorkDir: /var/www/mrtg
Language: gb2312
LoadMIBs:/usr/share/snmp/mibs/UCD-SNMP-MIB.txt,/usr/share/snmp/mibs/HOST-RESOURCES-MIB.txt,/usr/share/snmp/mibs/TCP-MIB.txt
######################################################################
# System: host.abc.com
# Description: Linux host.abc.com 2.6.11-2.QL #1 Wed Mar 16 15:22:24 CST 2005 i686
# Contact: Root <root@localhost> (configure /etc/snmp/snmp.local.conf)
# Location: Unknown (edit /etc/snmp/snmpd.conf)
######################################################################
#================================================================================
#监控内网网卡
#Descr: 'eth0' | Name: '' | Ip: '192.168.0.254' | Eth: '00-e0-4c-ab-55-63'
#================================================================================
Target[eth0_lan]: /192.168.0.254:public@localhost:
Options[eth0_lan]: growright
Directory[eth0_lan]: eth0
MaxBytes[eth0_lan]: 100000000
Kmg[eth0_lan]: ,k,M,G,T,P
YLegend[eth0_lan]: Bytes per Second
ShortLegend[eth0_lan]: B/s
Legend1[eth0_lan]: 每秒流入量 (单位 Bytes)
Legend2[eth0_lan]: 每秒流出量 (单位 Bytes)
LegendI[eth0_lan]: 流入:
LegendO[eth0_lan]: 流出:
Title[eth0_lan]: eth0网络流量[流入+流出]
PageTop[eth0_lan]: <H1>eth0网络流量[流入+流出]</H1>
<TABLE>
<TR><TD>系统 :</TD><TD>host.abc.com</TD></TR>
<TR><TD>描述 :</TD><TD>LAN网络接口eth0的网络流量(Bytes/s)</TD></TR>
<TR><TD>位置 :</TD><TD> Shenzhen</TD></TR>
<TR><TD>最大值:</TD><TD>100 MBytes/s</TD></TR>
<TR><TD>管理员:</TD><TD>hajd@optdevelop.com</TD></TR>
<TR><TD>说明 :</TD><TD>eth0 ip=192.168.0.254</TD></TR>
</TABLE>
#================================================================================
#监控外网网卡
#Descr: 'eth1' | Name: '' | Ip: '61.235.102.115' | Eth: '00-e0-4c-3a-cf-ef'
#================================================================================
Target[eth1_lan]: /61.235.102.115:public@localhost:
Options[eth1_lan]: growright
Directory[eth1_lan]: eth1
MaxBytes[eth1_lan]: 2000000
Kmg[eth1_lan]: ,k,M,G,T,P
YLegend[eth1_lan]: Bytes per Second
ShortLegend[eth1_lan]: B/s
Legend1[eth1_lan]: 每秒流入量 (单位 Bytes)
Legend2[eth1_lan]: 每秒流出量 (单位 Bytes)
LegendI[eth1_lan]: 流入:
LegendO[eth1_lan]: 流出:
Title[eth1_lan]: eth0网络流量[流入+流出]
PageTop[eth1_lan]: <H1>eth1网络流量[流入+流出]</H1>
<TABLE>
<TR><TD>系统 :</TD><TD>host.abc.com</TD></TR>
<TR><TD>描述 :</TD><TD>WAN网络接口eth1的网络流量(Bytes/s)</TD></TR>
<TR><TD>位置 :</TD><TD> Shenzhen</TD></TR>
<TR><TD>最大值:</TD><TD>2 MBytes/s</TD></TR>
<TR><TD>管理员:</TD><TD>hajd@optdevelop.com</TD></TR>
<TR><TD>说明 :</TD><TD>eth0 ip=61.235.102.115</TD></TR>
</TABLE>
#================================================================================
#监控主机连续运行时间[运行天数]
#注:不能从SNMP中直接取得数据,使用perl script采集数 (/etc/mrtg/bin/mrtg-upday.pl)
#================================================================================
Target[upday]: `/etc/mrtg/bin/mrtg-updays.pl`
Options[upday]: gauge,nopercent,growright
Directory[upday]: upday
MaxBytes[upday]: 1000
YLegend[upday]: Up Days
ShortLegend[upday]: 天
Legend1[upday]: 主机连续运行时间(天)
Legend2[upday]:
LegendI[upday]: 运行时间:
LegendO[upday]:
Title[upday]: 主机连续运行时间[运行天数]
PageTop[upday]: <h1>主机连续运行时间[运行天数]</h1>
<TABLE>
<TR><TD>系统:</TD><TD>host.abc.com</TD></TR>
<TR><TD>描述:</TD><TD>主机连续运行的时间(天)</TD></TR>
<TR><TD>位置:</TD><TD>ShenZhen</TD></TR>
<TR><TD>最大值:</TD><TD>1000天</TD></TR>
<TR><TD>管理员:</TD><TD>user@abc.com</TD></TR>
<TR><TD>说明:</TD><TD> </TD></TR>
</TABLE>
#================================================================================
#监控系统负载[1分钟+15分钟]
#MIB: .iso.org.dod.internet.private.enterprises.ucdavis.laTable.laEntry.laLoadInt
#注:打开snmpd中的监控功能,在/etc/snmp/snmpd.conf中加入
# view systemview included .1.3.6.1.4.1.2021.10.1.5
#================================================================================
Target[systemload]: .1.3.6.1.4.1.2021.10.1.5.1&.1.3.6.1.4.1.2021.10.1.5.3:public@localhost:
Options[systemload]: gauge,nopercent,growright
Directory[systemload]: load
MaxBytes[systemload]: 3000
YLegend[systemload]: System Load
ShortLegend[systemload]:
Legend1[systemload]: 最近1分钟系统负载(x 100)
Legend2[systemload]: 最近15分钟系统负载(x 100)
LegendI[systemload]: 1分钟负载:
LegendO[systemload]: 15分钟负载:
Title[systemload]: 系统负载(x100)[1分钟+15分钟]
PageTop[systemload]: <h1>系统负载(x100)[1分钟+15分钟]</h1>
<TABLE>
<TR><TD>系统:</TD><TD>host.abc.com</TD></TR>
<TR><TD>描述:</TD><TD>系统负载(x100)[1分钟+15分钟]</TD></TR>
<TR><TD>位置:</TD><TD>Shenzhen</TD></TR>
<TR><TD>最大值:</TD><TD>30 (x 100)</TD></TR>
<TR><TD>管理员:</TD><TD>user@abc.com</TD></TR>
<TR><TD>说明:</TD><TD> </TD></TR>
</TABLE>
#================================================================================
#监控CPU负载[用户+闲置]
#MIB: .iso.org.dod.internet.private.enterprises.ucdavis.systemStats
#注:打开snmpd中的监控功能,在/etc/snmp/snmpd.conf中加入
# view systemview included .1.3.6.1.4.1.2021.11
#================================================================================
Target[cpuload]: .1.3.6.1.4.1.2021.11.50.0&1.3.6.1.4.1.2021.11.53.0:public@localhost:
Options[cpuload]: nopercent,growright
Directory[cpuload]: cpu
MaxBytes[cpuload]: 100
Unscaled[cpuload]: dwym
YLegend[cpuload]: CPU Utilization
ShortLegend[cpuload]: %;
Legend1[cpuload]: CPU用户负载(%)
Legend2[cpuload]: CPU闲置(%)
LegendI[cpuload]: 用户:
LegendO[cpuload]: 闲置:
Title[cpuload]: CPU负载[用户+闲置]
PageTop[cpuload]: <h1>CPU负载[用户+闲置]</h1>
<TABLE>
<TR><TD>系统:</TD><TD>host.abc.com</TD></TR>
<TR><TD>描述:</TD><TD>CPU负载[用户+闲置]</TD></TR>
<TR><TD>位置:</TD><TD>Shenzhen</TD></TR>
<TR><TD>最大值:</TD><TD>100</TD></TR>
<TR><TD>管理员:</TD><TD>user@abc.com</TD></TR>
<TR><TD>说明:</TD><TD></TD></TR>
</TABLE>
#================================================================================
#监控内存使用量[Mem+Swap]
#MIB: .iso.org.dod.internet.mgmt.mib-2.host.hrStorage.hrStorageTable.hrStorageEntry.hrStorageUsed
#注:打开snmpd中的监控,在/etc/snmp/snmpd.conf中加入
# view systemview included .1.3.6.1.2.1.25.2.3.1.6
#================================================================================
Target[memory]: .1.3.6.1.2.1.25.2.3.1.6.2&.1.3.6.1.2.1.25.2.3.1.6.3:public@localhost:
Options[memory]: gauge,growright
Directory[memory]: mem
MaxBytes1[memory]: 514588
MaxBytes2[memory]: 514588
Kmg[memory]: k,M,G,T,P
Kilo[memory]: 1024
Unscaled[memory]: dwym
YLegend[memory]: Bytes
ShortLegend[memory]: B
Legend1[memory]: 已用Mem (Bytes)
Legend2[memory]: 已用Swap(Bytes)
LegendI[memory]: 已用Mem :
LegendO[memory]: 已用Swap:
Title[memory]: 内存使用量[Mem+Swap]
PageTop[memory]: <h1>内存使用量[Mem+Swap]</h1>
<TABLE>
<TR><TD>系统:</TD><TD>host.abc.com</TD></TR>
<TR><TD>描述:</TD><TD>Memory和Swap的使用量(Bytes)</TD></TR>
<TR><TD>位置:</TD><TD>Shenzhen</TD></TR>
<TR><TD>最大值:</TD><TD>Mem=502M,Swap=512M</TD></TR>
<TR><TD>管理员:</TD><TD>user@abc.com</TD></TR>
<TR><TD>说明:</TD><TD> </TD></TR>
</TABLE>
#================================================================================
#监控系统进程数[进程数]
#MIB: .iso.org.dod.internet.mgmt.mib-2.host.hrSystem.hrSystemProcesses
#注:打开snmpd中的系统进程数监控,在/etc/snmp/snmpd.conf中加入
# view systemview included .1.3.6.1.2.1.25.1.6
#================================================================================
Target[process]: .1.3.6.1.2.1.25.1.6.0&.1.3.6.1.2.1.25.1.6.0:public@localhost:
Options[process]: gauge,nopercent,growright
Directory[process]: process
MaxBytes[process]: 1000
YLegend[process]: Processes
ShortLegend[process]: 个
Legend1[process]: 系统进程数(个)
Legend2[process]:
LegendI[process]: 进程数:
LegendO[process]:
Title[process]: 系统进程数[进程数]
PageTop[process]: <h1>系统进程数[进程数]</h1>
<TABLE>
<TR><TD>系统:</TD><TD>host.abc.com</TD></TR>
<TR><TD>描述:</TD><TD>系统进程数(个)</TD></TR>
<TR><TD>位置:</TD><TD>Shenzhen</TD></TR>
<TR><TD>最大值:</TD><TD>1000个</TD></TR>
<TR><TD>管理员:</TD><TD>user@abc.com</TD></TR>
<TR><TD>说明:</TD><TD> </TD></TR>
</TABLE>
#================================================================================
#监控硬盘空间[系统盘+数据盘]
#MIB: .iso.org.dod.internet.private.enterprises.ucdavis.dskTable.dskEntry.dskUsed
#注1:打开snmpd中的监控功能,在/etc/snmp/snmpd.conf中加入
# view systemview included .1.3.6.1.4.1.2021.9.1.8
#注2:打开snmpd中的系统盘和数据盘监控功能,在/etc/snmp/snmpd.conf中加入
# disk / 100000
# disk /mnt/data 500000
#================================================================================
Target[disk]: .1.3.6.1.4.1.2021.9.1.8.1&.1.3.6.1.4.1.2021.9.1.8.2:public@localhost:
Options[disk]: gauge,growright
Directory[disk]: disk
MaxBytes1[disk]: 3000000
MaxBytes2[disk]: 70000000
Kmg[disk]: k,M,G,T,P
Kilo[disk]: 1024
Unscaled[disk]: dwym
YLegend[disk]: Bytes
ShortLegend[disk]: B
Legend1[disk]: 系统盘已用空间
Legend2[disk]: 数据盘已用空间
LegendI[disk]: 系统已用:
LegendO[disk]: 数据已用:
Title[disk]: 硬盘空间[系统盘+数据盘]
PageTop[disk]: <h1>硬盘空间[系统盘+数据盘]</h1>
<TABLE>
<TR><TD>系统:</TD><TD>host.abc.com</TD></TR>
<TR><TD>描述:</TD><TD>系统盘=/(/dev/hda3); 数据盘=/data(/dev/hda5)</TD></TR>
<TR><TD>位置:</TD><TD>Shenzhen</TD></TR>
<TR><TD>最大值:</TD><TD>系统盘=3.0GB; 数据盘=70GB</TD></TR>
<TR><TD>管理员:</TD><TD>user@abc.com</TD></TR>
<TR><TD>说明:</TD><TD> </TD></TR>
</TABLE>
#================================================================================
#监控打开的TCP连接数[TCP连接数]
#MIB: .iso.org.dod.internet.mgmt.mib-2.tcp.tcpCurrEstab
#注:打开snmpd中的监控功能,在/etc/snmp/snmpd.conf中加入
# view systemview included .1.3.6.1.2.1.6.9
#================================================================================
Target[tcpopen]: .1.3.6.1.2.1.6.9.0&.1.3.6.1.2.1.6.9.0:public@localhost:
Options[tcpopen]: gauge,nopercent,growright
Directory[tcpopen]: tcpopen
MaxBytes[tcpopen]: 1000
YLegend[tcpopen]: Tcp Connections
ShortLegend[tcpopen]: 个
Legend1[tcpopen]: 打开的TCP连接数(个)
Legend2[tcpopen]:
LegendI[tcpopen]: TCP连接数:
LegendO[tcpopen]:
Title[tcpopen]: TCP连接数[TCP连接数]
PageTop[tcpopen]: <h1>TCP连接数[TCP连接数]</h1>
<TABLE>
<TR><TD>系统:</TD><TD>host.abc.com</TD></TR>
<TR><TD>描述:</TD><TD>打开的TCP连接数(个)</TD></TR>
<TR><TD>位置:</TD><TD>Shenzhen</TD></TR>
<TR><TD>最大值:</TD><TD>1000个</TD></TR>
<TR><TD>管理员:</TD><TD>user@abc.com</TD></TR>
<TR><TD>说明:</TD><TD> </TD></TR>
</TABLE>
系统监控 | 评论:0
| Trackbacks:0
| 阅读:1002
Submitted by admin on 2011, July 21, 4:58 PM
本方法适用于PHP4.3版本。
总体思路:
一般要调用C语言的函数需要自己写PHP扩展,而以filename.a命名的静态库的函数是以C语言的方式来调用的,所以如何编写PHP扩展也是本文涉及到的重点。编译PHP的步骤是:写PHP扩展->把静态库加入PHP->编译PHP。
我的环境是:Linux Redhat7.3 Apache1.3.29 PHP4.3.4
写PHP扩展:
这部分内容请参考CSDN上Yorgo sun写的文档:http://dev.csdn.net/develop/article/12/12404.shtm。上面的内容很全,说得也非常清楚,即使从来没有写过PHP扩展的人看了也能明白。但在这个文档中没有如何调用静态库的方法,所以在最终编译PHP前要加入以下一步。
把静态库加入PHP:
把要编译的静态库链接存入环境变量。假设静态库的文件名叫libnpc.a,放在/home目录下。在PHP的安装目录下输入如下命令:export LDFLAGS=”–L/home –lnpc”
这个环境变量的作用就是让PHP在编译时知道要把这个库也一起编译进去。
编译PHP:
和普通编译PHP没什么大区别,就是要在./configure的时候加上你的扩展,具体见编写PHP扩展部分。
当编译好之后可以通过unset LDFLAGS来删除之前的环境变量。
php | 评论:0
| Trackbacks:0
| 阅读:924
Submitted by admin on 2011, July 20, 5:19 PM
1.修改squid的squid.conf文件
acl snmppublic snmp_community public #设置snmp监控的共同体为public
snmp_port 3401 #设置snmp监控端口
snmp_access allow snmppublic all #允许所有的计算机访问snmppublic
重启squid
2.生成MRTG配置文件
进入mrtg目录命令行下---->
cfgmaker public@localhost --global "WorkDir: /root/www/mrtg" --output mrtg.cfg
在/root/www/mrtg下生成监控的页面,可订制
3.将squid目录下的mib.txt文件改名为squid.mib,复制到mrtg/bin下
4.修改mrtg/bin下的mrtg.cfg配置文件
EnableIPv6: no
RunAsDaemon: yes #设置mrtg后台运行,默认5分钟刷新一次
Options[_]: growright, bits
Language: GB2312
LoadMIBs: squid.mib #装载复制过来的mib文件
WorkDir: C:\www\mrtg #设置页面存放的路径
PageFoot[^]: <i>Page managed by <a href="mailto:houw@yingnet.com">houw</a></i>
Target[cacheServerRequests]: cacheServerRequests&cacheServerRequests:public@localhost:3401
MaxBytes[cacheServerRequests]: 10000000
Title[cacheServerRequests]: Server Requests @ localhost
Options[cacheServerRequests]: growright, nopercent
PageTop[cacheServerRequests]: <h1>Server Requests @ localhost</h1>
YLegend[cacheServerRequests]: requests/sec
ShortLegend[cacheServerRequests]: req/s
LegendI[cacheServerRequests]: Requests
LegendO[cacheServerRequests]:
Legend1[cacheServerRequests]: Requests
Legend2[cacheServerRequests]:
Target[cacheServerErrors]: cacheServerErrors&cacheServerErrors:public@localhost:3401
MaxBytes[cacheServerErrors]: 10000000
Title[cacheServerErrors]: Server Errors @ localhost
Options[cacheServerErrors]: growright, nopercent
PageTop[cacheServerErrors]: <h1>Server Errors @ localhost</h1>
YLegend[cacheServerErrors]: errors/sec
ShortLegend[cacheServerErrors]: err/s
LegendI[cacheServerErrors]: Errors
LegendO[cacheServerErrors]:
Legend1[cacheServerErrors]: Errors
Legend2[cacheServerErrors]:
Target[cacheServerInOutKb]: cacheServerInKb&cacheServerOutKb:public@localhost:3401 * 1024
MaxBytes[cacheServerInOutKb]: 1000000000
Title[cacheServerInOutKb]: Server In/Out Traffic @ localhost
Options[cacheServerInOutKb]: growright, nopercent
PageTop[cacheServerInOutKb]: <h1>Server In/Out Traffic @ localhost</h1>
YLegend[cacheServerInOutKb]: Bytes/sec
ShortLegend[cacheServerInOutKb]: Bytes/s
LegendI[cacheServerInOutKb]: Server In
LegendO[cacheServerInOutKb]: Server Out
Legend1[cacheServerInOutKb]: Server In
Legend2[cacheServerInOutKb]: Server Out
Target[cacheHttpHits]: cacheHttpHits&cacheHttpHits:public@localhost:3401
MaxBytes[cacheHttpHits]: 10000000
Title[cacheHttpHits]: HTTP Hits @ localhost
Options[cacheHttpHits]: growright, nopercent
PageTop[cacheHttpHits]: <h1>HTTP Hits @ localhost</h1>
YLegend[cacheHttpHits]: hits/sec
ShortLegend[cacheHttpHits]: hits/s
LegendI[cacheHttpHits]: Hits
LegendO[cacheHttpHits]:
Legend1[cacheHttpHits]: Hits
Legend2[cacheHttpHits]:
Target[cacheHttpErrors]: cacheHttpErrors&cacheHttpErrors:public@localhost:3401
MaxBytes[cacheHttpErrors]: 10000000
Title[cacheHttpErrors]: HTTP Errors @ localhost
Options[cacheHttpErrors]: growright, nopercent
PageTop[cacheHttpErrors]: <h1>HTTP Errors @ localhost</h1>
YLegend[cacheHttpErrors]: errors/sec
ShortLegend[cacheHttpErrors]: err/s
LegendI[cacheHttpErrors]: Errors
LegendO[cacheHttpErrors]:
Legend1[cacheHttpErrors]: Errors
Legend2[cacheHttpErrors]:
Target[cacheIcpPktsSentRecv]: cacheIcpPktsSent&cacheIcpPktsRecv:public@localhost:3401
MaxBytes[cacheIcpPktsSentRecv]: 10000000
Title[cacheIcpPktsSentRecv]: ICP Packets Sent/Received
Options[cacheIcpPktsSentRecv]: growright, nopercent
PageTop[cacheIcpPktsSentRecv]: <h1>ICP Packets Sent/Recieved @ localhost</h1>
YLegend[cacheIcpPktsSentRecv]: packets/sec
ShortLegend[cacheIcpPktsSentRecv]: pkts/s
LegendI[cacheIcpPktsSentRecv]: Pkts Sent
LegendO[cacheIcpPktsSentRecv]: Pkts Received
Legend1[cacheIcpPktsSentRecv]: Pkts Sent
Legend2[cacheIcpPktsSentRecv]: Pkts Received
Target[cacheIcpKbSentRecv]: cacheIcpKbSent&cacheIcpKbRecv:public@localhost:3401 * 1024
MaxBytes[cacheIcpKbSentRecv]: 1000000000
Title[cacheIcpKbSentRecv]: ICP Bytes Sent/Received
Options[cacheIcpKbSentRecv]: growright, nopercent
PageTop[cacheIcpKbSentRecv]: <h1>ICP Bytes Sent/Received @ localhost</h1>
YLegend[cacheIcpKbSentRecv]: Bytes/sec
ShortLegend[cacheIcpKbSentRecv]: Bytes/s
LegendI[cacheIcpKbSentRecv]: Sent
LegendO[cacheIcpKbSentRecv]: Received
Legend1[cacheIcpKbSentRecv]: Sent
Legend2[cacheIcpKbSentRecv]: Received
Target[cacheHttpInOutKb]: cacheHttpInKb&cacheHttpOutKb:public@localhost:3401 * 1024
MaxBytes[cacheHttpInOutKb]: 1000000000
Title[cacheHttpInOutKb]: HTTP In/Out Traffic @ localhost
Options[cacheHttpInOutKb]: growright, nopercent
PageTop[cacheHttpInOutKb]: <h1>HTTP In/Out Traffic @ localhost</h1>
YLegend[cacheHttpInOutKb]: Bytes/second
ShortLegend[cacheHttpInOutKb]: Bytes/s
LegendI[cacheHttpInOutKb]: HTTP In
LegendO[cacheHttpInOutKb]: HTTP Out
Legend1[cacheHttpInOutKb]: HTTP In
Legend2[cacheHttpInOutKb]: HTTP Out
Target[cacheCurrentSwapSize]: cacheCurrentSwapSize&cacheCurrentSwapSize:public@localhost:3401
MaxBytes[cacheCurrentSwapSize]: 1000000000
Title[cacheCurrentSwapSize]: Current Swap Size @ localhost
Options[cacheCurrentSwapSize]: gauge, growright, nopercent
PageTop[cacheCurrentSwapSize]: <h1>Current Swap Size @ localhost</h1>
YLegend[cacheCurrentSwapSize]: swap size
ShortLegend[cacheCurrentSwapSize]: Bytes
LegendI[cacheCurrentSwapSize]: Swap Size
LegendO[cacheCurrentSwapSize]:
Legend1[cacheCurrentSwapSize]: Swap Size
Legend2[cacheCurrentSwapSize]:
Target[cacheNumObjCount]: cacheNumObjCount&cacheNumObjCount:public@localhost:3401
MaxBytes[cacheNumObjCount]: 10000000
Title[cacheNumObjCount]: Num Object Count @ localhost
Options[cacheNumObjCount]: gauge, growright, nopercent
PageTop[cacheNumObjCount]: <h1>Num Object Count @ localhost</h1>
YLegend[cacheNumObjCount]: # of objects
ShortLegend[cacheNumObjCount]: objects
LegendI[cacheNumObjCount]: Num Objects
LegendO[cacheNumObjCount]:
Legend1[cacheNumObjCount]: Num Objects
Legend2[cacheNumObjCount]:
Target[cacheCpuUsage]: cacheCpuUsage&cacheCpuUsage:public@localhost:3401
MaxBytes[cacheCpuUsage]: 100
AbsMax[cacheCpuUsage]: 100
Title[cacheCpuUsage]: CPU Usage @ localhost
Options[cacheCpuUsage]: absolute, gauge, noinfo, growright, nopercent
Unscaled[cacheCpuUsage]: dwmy
PageTop[cacheCpuUsage]: <h1>CPU Usage @ localhost</h1>
YLegend[cacheCpuUsage]: usage %
ShortLegend[cacheCpuUsage]:%
LegendI[cacheCpuUsage]: CPU Usage
LegendO[cacheCpuUsage]:
Legend1[cacheCpuUsage]: CPU Usage
Legend2[cacheCpuUsage]:
Target[cacheMemUsage]: cacheMemUsage&cacheMemUsage:public@localhost:3401 * 1024
MaxBytes[cacheMemUsage]: 2000000000
Title[cacheMemUsage]: Memory Usage
Options[cacheMemUsage]: gauge, growright, nopercent
PageTop[cacheMemUsage]: <h1>Total memory accounted for @ localhost</h1>
YLegend[cacheMemUsage]: Bytes
ShortLegend[cacheMemUsage]: Bytes
LegendI[cacheMemUsage]: Mem Usage
LegendO[cacheMemUsage]:
Legend1[cacheMemUsage]: Mem Usage
Legend2[cacheMemUsage]:
Target[cacheSysPageFaults]: cacheSysPageFaults&cacheSysPageFaults:public@localhost:3401
MaxBytes[cacheSysPageFaults]: 10000000
Title[cacheSysPageFaults]: Sys Page Faults @ localhost
Options[cacheSysPageFaults]: growright, nopercent
PageTop[cacheSysPageFaults]: <h1>Sys Page Faults @ localhost</h1>
YLegend[cacheSysPageFaults]: page faults/sec
ShortLegend[cacheSysPageFaults]: PF/s
LegendI[cacheSysPageFaults]: Page Faults
LegendO[cacheSysPageFaults]:
Legend1[cacheSysPageFaults]: Page Faults
Legend2[cacheSysPageFaults]:
Target[cacheSysVMsize]: cacheSysVMsize&cacheSysVMsize:public@localhost:3401 * 1024
MaxBytes[cacheSysVMsize]: 1000000000
Title[cacheSysVMsize]: Storage Mem Size @ localhost
Options[cacheSysVMsize]: gauge, growright, nopercent
PageTop[cacheSysVMsize]: <h1>Storage Mem Size @ localhost</h1>
YLegend[cacheSysVMsize]: mem size
ShortLegend[cacheSysVMsize]: Bytes
LegendI[cacheSysVMsize]: Mem Size
LegendO[cacheSysVMsize]:
Legend1[cacheSysVMsize]: Mem Size
Legend2[cacheSysVMsize]:
Target[cacheSysStorage]: cacheSysStorage&cacheSysStorage:public@localhost:3401
MaxBytes[cacheSysStorage]: 1000000000
Title[cacheSysStorage]: Storage Swap Size @ localhost
Options[cacheSysStorage]: gauge, growright, nopercent
PageTop[cacheSysStorage]: <h1>Storage Swap Size @ localhost</h1>
YLegend[cacheSysStorage]: swap size (KB)
ShortLegend[cacheSysStorage]: KBytes
LegendI[cacheSysStorage]: Swap Size
LegendO[cacheSysStorage]:
Legend1[cacheSysStorage]: Swap Size
Legend2[cacheSysStorage]:
Target[cacheSysNumReads]: cacheSysNumReads&cacheSysNumReads:public@localhost:3401
MaxBytes[cacheSysNumReads]: 10000000
Title[cacheSysNumReads]: HTTP I/O number of reads @ localhost
Options[cacheSysNumReads]: growright, nopercent
PageTop[cacheSysNumReads]: <h1>HTTP I/O number of reads @ localhost</h1>
YLegend[cacheSysNumReads]: reads/sec
ShortLegend[cacheSysNumReads]: reads/s
LegendI[cacheSysNumReads]: I/O
LegendO[cacheSysNumReads]:
Legend1[cacheSysNumReads]: I/O
Legend2[cacheSysNumReads]:
Target[cacheCpuTime]: cacheCpuTime&cacheCpuTime:public@localhost:3401
MaxBytes[cacheCpuTime]: 1000000000
Title[cacheCpuTime]: Cpu Time
Options[cacheCpuTime]: gauge, growright, nopercent
PageTop[cacheCpuTime]: <h1>Amount of cpu seconds consumed @ localhost</h1>
YLegend[cacheCpuTime]: cpu seconds
ShortLegend[cacheCpuTime]: cpu seconds
LegendI[cacheCpuTime]: Mem Time
LegendO[cacheCpuTime]:
Legend1[cacheCpuTime]: Mem Time
Legend2[cacheCpuTime]:
Target[cacheMaxResSize]: cacheMaxResSize&cacheMaxResSize:public@localhost:3401 * 1024
MaxBytes[cacheMaxResSize]: 1000000000
Title[cacheMaxResSize]: Max Resident Size
Options[cacheMaxResSize]: gauge, growright, nopercent
PageTop[cacheMaxResSize]: <h1>Maximum Resident Size @ localhost</h1>
YLegend[cacheMaxResSize]: Bytes
ShortLegend[cacheMaxResSize]: Bytes
LegendI[cacheMaxResSize]: Size
LegendO[cacheMaxResSize]:
Legend1[cacheMaxResSize]: Size
Legend2[cacheMaxResSize]:
Target[cacheCurrentUnlinkRequests]: cacheCurrentUnlinkRequests&cacheCurrentUnlinkRequests:public@localhost:3401
MaxBytes[cacheCurrentUnlinkRequests]: 1000000000
Title[cacheCurrentUnlinkRequests]: Unlinkd Requests
Options[cacheCurrentUnlinkRequests]: growright, nopercent
PageTop[cacheCurrentUnlinkRequests]: <h1>Requests given to unlinkd @ localhost</h1>
YLegend[cacheCurrentUnlinkRequests]: requests/sec
ShortLegend[cacheCurrentUnlinkRequests]: reqs/s
LegendI[cacheCurrentUnlinkRequests]: Unlinkd requests
LegendO[cacheCurrentUnlinkRequests]:
Legend1[cacheCurrentUnlinkRequests]: Unlinkd requests
Legend2[cacheCurrentUnlinkRequests]:
Target[cacheClients]: cacheClients&cacheClients:public@localhost:3401
MaxBytes[cacheClients]: 1000000000
Title[cacheClients]: Number of Clients
Options[cacheClients]: growright, nopercent
PageTop[cacheClients]: <h1>Number of clients accessing cache @ localhost</h1>
YLegend[cacheClients]: clients/sec
ShortLegend[cacheClients]: clients/s
LegendI[cacheClients]: Num Clients
LegendO[cacheClients]:
Legend1[cacheClients]: Num Clients
Legend2[cacheClients]:
Target[cacheHttpAllSvcTime]: cacheHttpAllSvcTime.5&cacheHttpAllSvcTime.60:public@localhost:3401
MaxBytes[cacheHttpAllSvcTime]: 1000000000
Title[cacheHttpAllSvcTime]: HTTP All Service Time
Options[cacheHttpAllSvcTime]: gauge, growright, nopercent
PageTop[cacheHttpAllSvcTime]: <h1>HTTP all service time @ localhost</h1>
YLegend[cacheHttpAllSvcTime]: svc time (ms)
ShortLegend[cacheHttpAllSvcTime]: ms
LegendI[cacheHttpAllSvcTime]: Median Svc Time (5min)
LegendO[cacheHttpAllSvcTime]: Median Svc Time (60min)
Legend1[cacheHttpAllSvcTime]: Median Svc Time
Legend2[cacheHttpAllSvcTime]: Median Svc Time
Target[cacheHttpMissSvcTime]: cacheHttpMissSvcTime.5&cacheHttpMissSvcTime.60:public@localhost:3401
MaxBytes[cacheHttpMissSvcTime]: 1000000000
Title[cacheHttpMissSvcTime]: HTTP Miss Service Time
Options[cacheHttpMissSvcTime]: gauge, growright, nopercent
PageTop[cacheHttpMissSvcTime]: <h1>HTTP miss service time @ localhost</h1>
YLegend[cacheHttpMissSvcTime]: svc time (ms)
ShortLegend[cacheHttpMissSvcTime]: ms
LegendI[cacheHttpMissSvcTime]: Median Svc Time (5min)
LegendO[cacheHttpMissSvcTime]: Median Svc Time (60min)
Legend1[cacheHttpMissSvcTime]: Median Svc Time
Legend2[cacheHttpMissSvcTime]: Median Svc Time
Target[cacheHttpNmSvcTime]: cacheHttpNmSvcTime.5&cacheHttpNmSvcTime.60:public@localhost:3401
MaxBytes[cacheHttpNmSvcTime]: 1000000000
Title[cacheHttpNmSvcTime]: HTTP Near Miss Service Time
Options[cacheHttpNmSvcTime]: gauge, growright, nopercent
PageTop[cacheHttpNmSvcTime]: <h1>HTTP near miss service time @ localhost</h1>
YLegend[cacheHttpNmSvcTime]: svc time (ms)
ShortLegend[cacheHttpNmSvcTime]: ms
LegendI[cacheHttpNmSvcTime]: Median Svc Time (5min)
LegendO[cacheHttpNmSvcTime]: Median Svc Time (60min)
Legend1[cacheHttpNmSvcTime]: Median Svc Time
Legend2[cacheHttpNmSvcTime]: Median Svc Time
Target[cacheHttpHitSvcTime]: cacheHttpHitSvcTime.5&cacheHttpHitSvcTime.60:public@localhost:3401
MaxBytes[cacheHttpHitSvcTime]: 1000000000
Title[cacheHttpHitSvcTime]: HTTP Hit Service Time
Options[cacheHttpHitSvcTime]: gauge, growright, nopercent
PageTop[cacheHttpHitSvcTime]: <h1>HTTP hit service time @ localhost</h1>
YLegend[cacheHttpHitSvcTime]: svc time (ms)
ShortLegend[cacheHttpHitSvcTime]: ms
LegendI[cacheHttpHitSvcTime]: Median Svc Time (5min)
LegendO[cacheHttpHitSvcTime]: Median Svc Time (60min)
Legend1[cacheHttpHitSvcTime]: Median Svc Time
Legend2[cacheHttpHitSvcTime]: Median Svc Time
Target[cacheIcpQuerySvcTime]: cacheIcpQuerySvcTime.5&cacheIcpQuerySvcTime.60:public@localhost:3401
MaxBytes[cacheIcpQuerySvcTime]: 1000000000
Title[cacheIcpQuerySvcTime]: ICP Query Service Time
Options[cacheIcpQuerySvcTime]: gauge, growright, nopercent
PageTop[cacheIcpQuerySvcTime]: <h1>ICP query service time @ localhost</h1>
YLegend[cacheIcpQuerySvcTime]: svc time (ms)
ShortLegend[cacheIcpQuerySvcTime]: ms
LegendI[cacheIcpQuerySvcTime]: Median Svc Time (5min)
LegendO[cacheIcpQuerySvcTime]: Median Svc Time (60min)
Legend1[cacheIcpQuerySvcTime]: Median Svc Time
Legend2[cacheIcpQuerySvcTime]: Median Svc Time
Target[cacheIcpReplySvcTime]: cacheIcpReplySvcTime.5&cacheIcpReplySvcTime.60:public@localhost:3401
MaxBytes[cacheIcpReplySvcTime]: 1000000000
Title[cacheIcpReplySvcTime]: ICP Reply Service Time
Options[cacheIcpReplySvcTime]: gauge, growright, nopercent
PageTop[cacheIcpReplySvcTime]: <h1>ICP reply service time @ localhost</h1>
YLegend[cacheIcpReplySvcTime]: svc time (ms)
ShortLegend[cacheIcpReplySvcTime]: ms
LegendI[cacheIcpReplySvcTime]: Median Svc Time (5min)
LegendO[cacheIcpReplySvcTime]: Median Svc Time (60min)
Legend1[cacheIcpReplySvcTime]: Median Svc Time
Legend2[cacheIcpReplySvcTime]: Median Svc Time
Target[cacheDnsSvcTime]: cacheDnsSvcTime.5&cacheDnsSvcTime.60:public@localhost:3401
MaxBytes[cacheDnsSvcTime]: 1000000000
Title[cacheDnsSvcTime]: DNS Service Time
Options[cacheDnsSvcTime]: gauge, growright, nopercent
PageTop[cacheDnsSvcTime]: <h1>DNS service time @ localhost</h1>
YLegend[cacheDnsSvcTime]: svc time (ms)
ShortLegend[cacheDnsSvcTime]: ms
LegendI[cacheDnsSvcTime]: Median Svc Time (5min)
LegendO[cacheDnsSvcTime]: Median Svc Time (60min)
Legend1[cacheDnsSvcTime]: Median Svc Time
Legend2[cacheDnsSvcTime]: Median Svc Time
Target[cacheRequestHitRatio]: cacheRequestHitRatio.5&cacheRequestHitRatio.60:public@localhost:3401
MaxBytes[cacheRequestHitRatio]: 100
AbsMax[cacheRequestHitRatio]: 100
Title[cacheRequestHitRatio]: Request Hit Ratio @ localhost
Options[cacheRequestHitRatio]: absolute, gauge, noinfo, growright, nopercent
Unscaled[cacheRequestHitRatio]: dwmy
PageTop[cacheRequestHitRatio]: <h1>Request Hit Ratio @ localhost</h1>
YLegend[cacheRequestHitRatio]: %
ShortLegend[cacheRequestHitRatio]: %
LegendI[cacheRequestHitRatio]: Median Hit Ratio (5min)
LegendO[cacheRequestHitRatio]: Median Hit Ratio (60min)
Legend1[cacheRequestHitRatio]: Median Hit Ratio
Legend2[cacheRequestHitRatio]: Median Hit Ratio
Target[cacheRequestByteRatio]: cacheRequestByteRatio.5&cacheRequestByteRatio.60:public@localhost:3401
MaxBytes[cacheRequestByteRatio]: 100
AbsMax[cacheRequestByteRatio]: 100
Title[cacheRequestByteRatio]: Byte Hit Ratio @ localhost
Options[cacheRequestByteRatio]: absolute, gauge, noinfo, growright, nopercent
Unscaled[cacheRequestByteRatio]: dwmy
PageTop[cacheRequestByteRatio]: <h1>Byte Hit Ratio @ localhost</h1>
YLegend[cacheRequestByteRatio]: %
ShortLegend[cacheRequestByteRatio]:%
LegendI[cacheRequestByteRatio]: Median Hit Ratio (5min)
LegendO[cacheRequestByteRatio]: Median Hit Ratio (60min)
Legend1[cacheRequestByteRatio]: Median Hit Ratio
Legend2[cacheRequestByteRatio]: Median Hit Ratio
Target[cacheBlockingGetHostByAddr]: cacheBlockingGetHostByAddr&cacheBlockingGetHostByAddr:public@localhost:3401
MaxBytes[cacheBlockingGetHostByAddr]: 1000000000
Title[cacheBlockingGetHostByAddr]: Blocking gethostbyaddr
Options[cacheBlockingGetHostByAddr]: growright, nopercent
PageTop[cacheBlockingGetHostByAddr]: <h1>Blocking gethostbyaddr count @ localhost</h1>
YLegend[cacheBlockingGetHostByAddr]: blocks/sec
ShortLegend[cacheBlockingGetHostByAddr]: blocks/s
LegendI[cacheBlockingGetHostByAddr]: Blocking
LegendO[cacheBlockingGetHostByAddr]:
Legend1[cacheBlockingGetHostByAddr]: Blocking
Legend2[cacheBlockingGetHostByAddr]:
5.执行mrtg监控
mrtg目录命令行下----> mrtg mrtg.cfg
6.indexmaker --output="C:\www\mrtg\index.html" --title=windowMRTG mrtg.cfg
生成索引页面,可以通过这一个页面访问其他监控页面
squid/缓存 | 评论:0
| Trackbacks:0
| 阅读:881
Submitted by admin on 2011, July 20, 2:25 PM
上回编译加载tcmalloc后,效果各有不同,所以还得细分具体运行情况,以便之后继续优化。
之前的架构是1个lvs下挂6台leaf+1台parent。现在已经给7台squid都加载tcmalloc了。leaf运行上佳,CPU占用率甚至降到了2%,loadavg也不过0.2。但parent的CPU占用率虽然降低,loadavg却依然在1以上——这对于单核服务器来说,可不是什么好事
分析日志,或者用squidclient分析cache情况,leaf如下:
$ cat access.log |awk '{if(/NONE/){a[NONE]++}}END{print a[NONE]/NR}'
0.981347
$ squidclient -p 80 mgr:info
Cache information for squid:
Request Hit Ratios: 5min: 97.8%, 60min: 98.3%
Byte Hit Ratios: 5min: 97.8%, 60min: 98.2%
Request Memory Hit Ratios: 5min: 85.8%, 60min: 86.8%
Request Disk Hit Ratios: 5min: 9.8%, 60min: 9.1%
Storage Swap size: 19891740 KB
Storage Mem size: 1048572 KB
Mean Object Size: 9.67 KB
可以看到缓存文件的平均大小不足10KB,绝大多数的请求都在内存中处理掉了。所以在加载了优化内存反应速度的tcmalloc后,效果那么明显。
parent如下:
$ cat access.log |awk '{if(/NONE/){a[NONE]++}}END{print a[NONE]/NR}'
0.179209
$ squidclient -p 80 mgr:info
Cache information for squid:
Request Hit Ratios: 5min: 31.1%, 60min: 32.3%
Byte Hit Ratios: 5min: 38.4%, 60min: 36.9%
Request Memory Hit Ratios: 5min: 7.8%, 60min: 12.2%
Request Disk Hit Ratios: 5min: 32.7%, 60min: 37.9%
Storage Swap size: 40300232 KB
Storage Mem size: 524284 KB
Mean Object Size: 11.68 KB
只有30%的缓存命中,而且基本还都是从磁盘读取的(awk结果排除了REFRESH_HIT,所以更低)。难怪上次优化没什么效用了……
为了保证服务,先给这组服务器加上了round-robin的双parent。新parent的硬件情况和老的一样。而squid配置上,则采用了aufs方式,不再使用diskd方式。运行到现在30个小时,分析如下:
$ cat /cache/logs/access.log |awk '{if(/NONE/){a[NONE]++}}END{print a[NONE]/NR}'
0.238754
$ squidclient -p 80 mgr:info
Cache information for squid:
Request Hit Ratios: 5min: 22.7%, 60min: 22.8%
Byte Hit Ratios: 5min: 22.9%, 60min: 20.1%
Request Memory Hit Ratios: 5min: 22.2%, 60min: 24.3%
Request Disk Hit Ratios: 5min: 64.4%, 60min: 65.0%
Storage Swap size: 4640308 KB
Storage Mem size: 1048588 KB
Mean Object Size: 9.08 KB
看起来差不多的样子。
因为确认mem没怎么用上,下一步看disk的I/O。
采用diskd的parent如下:
[root@tinysquid2 ~]# iostat -x /dev/xvdb2 5 5
Linux 2.6.18-128.el5xen (tinysquid2) 02/06/2010
avg-cpu: %user %nice %system %iowait %steal %idle
1.03 0.00 0.24 2.71 0.03 95.99
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
xvdb2 0.14 1.78 1.60 2.21 27.27 30.20 15.10 0.22 56.62 7.26 2.76
avg-cpu: %user %nice %system %iowait %steal %idle
0.00 0.00 0.00 10.00 0.00 90.00
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
xvdb2 0.00 5.00 8.60 46.60 81.60 412.80 8.96 0.32 5.80 1.75 9.68
^[ORavg-cpu: %user %nice %system %iowait %steal %idle
0.00 0.00 0.00 5.41 0.00 94.59
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
xvdb2 0.00 15.23 6.41 25.25 60.92 323.85 12.15 0.07 2.28 1.82 5.77
avg-cpu: %user %nice %system %iowait %steal %idle
0.00 0.00 0.00 14.00 0.00 86.00
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
xvdb2 0.00 3.20 8.60 1.60 84.80 38.40 12.08 0.15 14.35 14.12 14.40
avg-cpu: %user %nice %system %iowait %steal %idle
0.00 0.00 0.00 15.37 0.00 84.63
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
xvdb2 0.00 8.18 13.77 8.38 122.95 132.53 11.53 0.17 7.64 7.10 15.73
采用aufs的parent如下:
[root@tinysquid3 ~]# iostat -x /dev/xvdb2 5 5
Linux 2.6.18-128.el5xen (tinysquid3) 02/06/2010
avg-cpu: %user %nice %system %iowait %steal %idle
0.45 0.00 0.16 1.40 0.05 97.95
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
xvdb2 0.01 3.84 0.16 2.11 2.38 41.61 19.39 0.07 29.11 5.27 1.20
avg-cpu: %user %nice %system %iowait %steal %idle
0.20 0.00 0.40 1.60 0.20 97.60
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
xvdb2 0.00 8.58 3.19 6.19 25.55 118.16 15.32 0.02 2.47 1.70 1.60
avg-cpu: %user %nice %system %iowait %steal %idle
0.00 0.00 0.00 0.60 0.00 99.40
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
xvdb2 0.00 14.20 2.00 6.20 16.00 163.20 21.85 0.01 1.27 0.68 0.56
avg-cpu: %user %nice %system %iowait %steal %idle
0.00 0.00 0.00 0.60 0.00 99.40
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
xvdb2 0.00 15.23 1.40 5.61 12.83 166.73 25.60 0.01 1.37 1.03 0.72
avg-cpu: %user %nice %system %iowait %steal %idle
0.00 0.00 0.00 2.79 0.00 97.21
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
xvdb2 0.00 17.76 4.99 19.56 47.90 298.60 14.11 0.03 1.37 1.04 2.55
以上结果的解释如下:
- rrqm/s: 每秒进行 merge 的读操作数目。即 delta(rmerge)/s
- wrqm/s: 每秒进行 merge 的写操作数目。即 delta(wmerge)/s
- r/s: 每秒完成的读 I/O 设备次数。即 delta(rio)/s
- w/s: 每秒完成的写 I/O 设备次数。即 delta(wio)/s
- rsec/s: 每秒读扇区数。即 delta(rsect)/s
- wsec/s: 每秒写扇区数。即 delta(wsect)/s
- rkB/s: 每秒读K字节数。是 rsect/s 的一半,因为每扇区大小为512字节。(需要计算)
- wkB/s: 每秒写K字节数。是 wsect/s 的一半。(需要计算)
- avgrq-sz: 平均每次设备I/O操作的数据大小 (扇区)。delta(rsect+wsect)/delta(rio+wio)
- avgqu-sz: 平均I/O队列长度。即 delta(aveq)/s/1000 (因为aveq的单位为毫秒)。
- await: 平均每次设备I/O操作的等待时间 (毫秒)。即 delta(ruse+wuse)/delta(rio+wio)
- svctm: 平均每次设备I/O操作的服务时间 (毫秒)。即 delta(use)/delta(rio+wio)
- %util: 一秒中有百分之多少的时间用于 I/O 操作,或者说一秒中有多少时间 I/O 队列是非空的。即 delta(use)/s/1000 (因为use的单位为毫秒)
从上面的运行情况看,都是w操作为主,但diskd比aufs每秒w的次数要大,而每次w的服务时间也大——大的同时波动性也不太稳定——由此导致rw时的等待时间也延长——进一步的结果就是I/O非空时间变少——最后的结果就是disk的I/O压力变大!
因为现在已经双parent,loadavg降低,所以不好看出之前的高loadavg问题关键。不过至少从现在的运行来看,aufs比diskd要好。
squid/缓存 | 评论:0
| Trackbacks:0
| 阅读:803
Submitted by admin on 2011, July 20, 2:24 PM
Squid优化(一)
Hot!几个SQUID重要参数:
maximum_object_size 是 能cache最大的文件大小。对应wmv,rm文件,建议设置为32768 kB
maximum_object_size_in_memory 是在内存中cache的最大文件大小。
cache_mem 是SQUID可用到的最大内存。经实践,4G内存的服务器用2G;超过2G导致SQUID运行不稳
首先要分析SQUID所cache内容:
运行
squidclient -p 80 cache_object://localhost/info
能看到如下内容:
Storage Swap size: 7549104 KB
Storage Mem size: 418804 KB
Mean Object Size: 160.46 KB
Mean Object Size是平均内容大小,一般要把maximum_object_size_in_memory设置成离它最近的128的倍数。在这个例子中maximum_object_size_in_memory 的值应该是256kB。
cache_mem 一般设置成服务器内存的一半或更多,只要运行过程中LINUX没有使用SWAP就可以。
再就是按业务分SQUID。
比如某个论坛,用户能上载图片和视频;当然我们要把上载的图片、视频放在单独的域名上,比如img.example.com, video.example.com;这两个域名只提供静态文件服务。
根据统计,图片的平均大小在100KB,视频的平均大小在4M,差别是很大,应该建两个squid分别作图片和视频的CACHE。图片SQUID的 maximum_object_size_in_memory 设置为256KB,视频的SQUID的maximum_object_size_in_memory设置为8196KB。
Squid优化(2)
Hot!探讨动态内容的CACHE。
BBS,论坛是典型动态内容,要保证内容更新及时的同时,提高访问速度,降低数据库负担不是个简单任务。经实践发现如下办法取得很好效果:
1) 配置SQUID,对动态内容强制CACHE,用到的配置参数是refresh_pattern
refresh_pattern ^/forum/viewthread.php 1440 1000% 1440 ignore-reload
/forum/viewthread.php的内容将强制保持1天
2) 修改论坛程序在用户回复帖子后,向SQUID发送PURGE命令清除相应帖子的页面CACHE,保证失效性
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~实现过这一功能,但是有时候生效,有时候无效,还未进一步查明原因.(Edit by Sean)
3) 有些频繁更新的页面可以不CACHE,用no_cache参数
acl no_forum_cache urlpath_regex ^/forum/forumdisplay.php
no_cache DENY no_forum_cache
squid/缓存 | 评论:0
| Trackbacks:0
| 阅读:822
Submitted by admin on 2011, July 20, 9:32 AM
据国外媒体报道,HTC近日发布了其部分最受欢迎的Android智能手机和新发布的Flyer平板电脑的源代码。公司在自己的开发者页面上贴出了 HTC Desire Z、Incredible S和Flyer平板电脑的2.6.35内核源代码,开发者们可以籍此将Android操作系统输出到其 它HTC设备上,或者创建自定义内核。
此举主要是应消费者要求,之前有消费者在HTC的Facebook页面上抱怨没有提供相关设备,如Evo 4G的源代码共享。用户 Gregory Marton写道,“我很失望HTc违背了GNU公共许可,没有公布Evo 4G操作系统源代码的更改部分。作为一家公司,不能说等它完 备了再发布出来,这就违背了你们签订的协议。既然在我的手机上发布了二进制代码,就需要公开其所有源代码,我们希望能看到改动的部分。”
该协议要求任何修改代码的一方都需要将其公开。HTC在用户发帖之初并未作出回应,而对应产品Desire Z于11月在英国发布,Flyer则在5月发布。
Google支持的Android项目已经遵循GNU的公开协议GPL公布了手机OS的代码。
同时在5月,HTC还许诺对启动加载程序进行解锁,以便开发者在自己的手机上安装非官方的软件等。然而,截止到7月11日“要安装新的软件仍然需要进行大 量测试,面临很多挑战。”据悉,HTC Sensation 4G和EVO 3D上使用的启动加载程序,将于8月在美国成为首款获解锁的程序。
进入 HTC 开发者页面: http://developer.htc.com/
android | 评论:0
| Trackbacks:0
| 阅读:866