其实从标题来看,这样的文章已经相当多,不过由于这次使用了最新版的系统和软件,在配置方面比原来的版本有了一些改进,明显更加方便,所以值得记录一下和大家分享。
这次实现监控的目标是系统网络流量、TCP连接数、CPU负载、system和user的CPU负载、内存消耗、swap使用,另外还可以在此基础上实现磁盘监控、Mailscanner的垃圾邮件等监控。
首先通过cvsup更新系统源码和ports数到当前的FreeBSD 6.1Release版本,保持系统和软件包的最新版本,然后使用极为方便的ports进行软件安装。
1、安装net-snmp-5.2.2
#cd /usr/ports/net-mgmt/net-snmp
#make install clean
然后就等着系统自动为您下载net-snmp-5.2.2.tar.gz软件包以及关联软件包,ports会自动完成后续的安装。
2、配置snmp
等安装完成后会看到成功的提示以及后续配置的说明。接下来我们进行简单的几个配置即可完成snmp的安装配置。
#mkdir /usr/local/etc/snmp
#cp /usr/local/share/snmp/snmpd.conf /usr/local/etc/snmp/
#vim /usr/local/etc/snmp/snmpd.conf
下面是我的配置文件内容
com2sec local localhost private
com2sec mynet 192.168.0.0/24 public
com2sec public default public
group mygroup v1 mynet
group mygroup v2c mynet
group mygroup usm mynet
group local v1 local
group local v2c local
group local usm local
group public v1 public
group public v2c public
group public usm public
view all included .1 80
access mygroup “” any noauth exact mib2 none none
access public “” any noauth exact all none none
access local “” any noauth exact all all all
syslocation Right here, right now.
syscontact Me
proc mountd
proc ntalkd 4
proc sendmail 10 1
exec echotest /bin/echo hello world
disk / 10000
load 12 14 14
其实里面只有很少的部分是自己修改的,大部分是默认值,具体的您可以对比一下您的snmpd.conf文件,建议把您的配置文件使用 grep -v # snmpd.conf > snmpd.conf.new 去掉所有的注释行再进行配置,这样看起来更清晰一些。
完成上面的配置,snmp的安装和配置已经完成,此时我们可以使用 snmpwalk -v 1 -c public localhost system 来测试看看返回结果,正常应该返回类似下面的内容。
SNMPv2-MIB::sysDescr.0 = STRING: FreeBSD www.toplee.com 6.1-RELEASE FreeBSD 6.1-RELEASE #0: Wed May 24 13:32:37 CST 2006 root@www.toplee.com:/usr/src/sys/i386/compile/TOPLEE i386
SNMPv2-MIB::sysObjectID.0 = OID: SNMPv2-SMI::dod.0.0.0.0.0.0.0
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (8548737) 23:44:47.37
SNMPv2-MIB::sysContact.0 = STRING: Me
SNMPv2-MIB::sysName.0 = STRING: www.toplee.com
SNMPv2-MIB::sysLocation.0 = STRING: Right here, right now.
SNMPv2-MIB::sysServices.0 = INTEGER: 72
SNMPv2-MIB::sysORLastChange.0 = Timeticks: (11) 0:00:00.11
SNMPv2-MIB::sysORID.1 = OID: IF-MIB::ifMIB
SNMPv2-MIB::sysORID.2 = OID: SNMPv2-MIB::snmpMIB
SNMPv2-MIB::sysORID.3 = OID: TCP-MIB::tcpMIB
SNMPv2-MIB::sysORID.4 = OID: IP-MIB::ip
SNMPv2-MIB::sysORID.5 = OID: UDP-MIB::udpMIB
SNMPv2-MIB::sysORID.6 = OID: SNMP-VIEW-BASED-ACM-MIB::vacmBasicGroup
SNMPv2-MIB::sysORID.7 = OID: SNMP-FRAMEWORK-MIB::snmpFrameworkMIBCompliance
SNMPv2-MIB::sysORID.8 = OID: SNMP-MPD-MIB::snmpMPDCompliance
SNMPv2-MIB::sysORID.9 = OID: SNMP-USER-BASED-SM-MIB::usmMIBCompliance
SNMPv2-MIB::sysORDescr.1 = STRING: The MIB module to describe generic objects for network interface sub-layers
SNMPv2-MIB::sysORDescr.2 = STRING: The MIB module for SNMPv2 entities
SNMPv2-MIB::sysORDescr.3 = STRING: The MIB module for managing TCP implementations
SNMPv2-MIB::sysORDescr.4 = STRING: The MIB module for managing IP and ICMP implementations
SNMPv2-MIB::sysORDescr.5 = STRING: The MIB module for managing UDP implementations
SNMPv2-MIB::sysORDescr.6 = STRING: View-based Access Control Model for SNMP.
SNMPv2-MIB::sysORDescr.7 = STRING: The SNMP Management Architecture MIB.
SNMPv2-MIB::sysORDescr.8 = STRING: The MIB for Message Processing and Dispatching.
SNMPv2-MIB::sysORDescr.9 = STRING: The management information definitions for the SNMP User-based Security Model.
SNMPv2-MIB::sysORUpTime.1 = Timeticks: (9) 0:00:00.09
SNMPv2-MIB::sysORUpTime.2 = Timeticks: (11) 0:00:00.11
SNMPv2-MIB::sysORUpTime.3 = Timeticks: (11) 0:00:00.11
SNMPv2-MIB::sysORUpTime.4 = Timeticks: (11) 0:00:00.11
SNMPv2-MIB::sysORUpTime.5 = Timeticks: (11) 0:00:00.11
SNMPv2-MIB::sysORUpTime.6 = Timeticks: (11) 0:00:00.11
SNMPv2-MIB::sysORUpTime.7 = Timeticks: (11) 0:00:00.11
SNMPv2-MIB::sysORUpTime.8 = Timeticks: (11) 0:00:00.11
SNMPv2-MIB::sysORUpTime.9 = Timeticks: (11) 0:00:00.11
您可以去掉后面的system参数得到所有的snmp返回数据,通过分析这些数据就可以实现对系统的各种监控,这是mrtg通过snmp实现监控的途径。
为了让系统在启动的时候自动启动snmpd监听服务,我们要对/etc/rc.conf进行配置,在该文件种添加下面内容:
snmpd_enable=”YES”
snmpd_flags=”-a -p /var/run/snmpd.pid”
snmptrapd_enable=”YES”
snmptrapd_flags=”-a -p /var/run/snmptrapd.pid”
下面参数可选
NET_SNMP_SYS_CONTACT=”Michael@toplee.com”
NET_SNMP_SYS_LOCATION=”Beijing,China”
DEFAULT_SNMP_VERSION=3
NET_SNMP_MIB_MODULES=”host smux mibII/mta_sendmail ucd-snmp/diskio”
NET_SNMP_LOGFILE=/var/log/snmpd.log
NET_SNMP_PERSISTENTDIR=/var/net-snmp
3、安装mrtg-2.13.2
在完成了上面的snmp安装配置之后,开始进行mrtg的安装配置,也使用非常方便的ports进行安装
#cd /usr/ports/net-mgmt/mrtg/
#make install clean
4、配置mrtg
#vim /usr/local/etc/mrtg/mrtg.cfg
下面是我的配置文件
WorkDir: /var/www/mrtg
Language: gb2312
Options[_]: growright, bits
Target[traffic_1]: 1:public@localhost:
SetEnv[traffic_1]: MRTG_INT_IP=”localhost” MRTG_INT_DESCR=”流量分析”
Xsize[traffic_1]: 380
MaxBytes[traffic_1]: 2500000
Title[traffic_1]: 前端服务器流量监控
PageTop[traffic_1]:
前端服务器流量监控控
System: | FreeBSD web server of Toplee.com Col |
Maintainer: | Michael <toplee@gamil.com> |
ifType: | ethernetCsmacd (6) |
Max Speed: | 2.5 MBytes/s |
########################### TCP Cons ######################################
Target[tcpopen]: .1.3.6.1.2.1.6.9.0&.1.3.6.1.2.1.6.9.0:public@localhost
Options[tcpopen]: nopercent,growright,gauge,noinfo
Title[tcpopen]: Open TCP connections
PageTop[tcpopen]:
Open TCP connections
MaxBytes[tcpopen]: 1000000
YLegend[tcpopen]: # conns
ShortLegend[tcpopen]: connections
LegendI[tcpopen]: Connections:
LegendO[tcpopen]:
Legend1[tcpopen]: Open TCP connections
######################### CPU ############################################
LoadMIBs: /usr/local/share/snmp/mibs/UCD-SNMP-MIB.txt
Target[cpu]:ssCpuRawUser.0&ssCpuRawUser.0:public@localhost + ssCpuRawSystem.0&ssCpuRawSystem.0:public@localhost + ssCpuRawNice.0&ssCpuRawNice.0:public@localhost
RouterUptime[cpu]: public@localhost
MaxBytes[cpu]: 100
Title[cpu]: CPU Load
PageTop[cpu]:
Carga de CPU %
Unscaled[cpu]: ymwd
ShortLegend[cpu]: %
YLegend[cpu]: Uso de CPU
Legend1[cpu]: CPU Activa % (Carga)
Legend2[cpu]:
Legend3[cpu]:
Legend4[cpu]:
LegendI[cpu]: Active
LegendO[cpu]:
Options[cpu]: growright,nopercent
######################## CPU UsrSys ####################################
LoadMIBs: /usr/local/share/snmp/mibs/UCD-SNMP-MIB.txt
Target[usrsys]:ssCpuRawUser.0&ssCpuRawSystem.0:public@localhost
RouterUptime[usrsys]: public@localhost
MaxBytes[usrsys]: 100
Title[usrsys]: CPU LOAD
PageTop[usrsys]:
CPU (user and system) Load %
Unscaled[usrsys]: ymwd
ShortLegend[usrsys]: %
YLegend[usrsys]: CPU Utilization
Legend1[usrsys]: User CPU in % (Load)
Legend2[usrsys]: System CPU in % (Load)
Legend3[usrsys]:
Legend4[usrsys]:
LegendI[usrsys]: User
LegendO[usrsys]: System
Options[usrsys]: growright,nopercent
########################### Mem ###########################################
LoadMIBs: /usr/local/share/snmp/mibs/HOST-RESOURCES-MIB.txt
Target[mem]: .1.3.6.1.4.1.2021.4.6.0&.1.3.6.1.4.1.2021.4.6.0:public@localhost
PageTop[mem]:
Memory RAM
Options[mem]: nopercent,growright,gauge,noinfo
Title[mem]: Memory Libre
MaxBytes[mem]: 1055309824
kMG[mem]: k,M,G,T,P,X
YLegend[mem]: bytes
ShortLegend[mem]: bytes
LegendI[mem]: Free Memory:
LegendO[mem]:
Legend1[mem]: Free memory, not including swap, in bytes
####################### MEM1 ############################################
LoadMIBs: /usr/local/share/snmp/mibs/HOST-RESOURCES-MIB.txt
Target[mem1]:.1.3.6.1.4.1.2021.4.6.0&.1.3.6.1.4.1.2021.4.15.0:public@localhost * 1024
MaxBytes[mem1]: 1055309824
Title[mem1]: MEMORY USAGE
kilo[mem1]: 1024
WithPeak[mem1]: my
Options[mem1]: gauge,growright
YLegend[mem1]: Memory Usage
LegendI[mem1]: Used:
LegendO[mem1]: Cached:
Legend1[mem1]: Used Memory Size
Legend2[mem1]: Cached Memory Size
Legend3[mem1]: 5min Max Used Memory Size
Legend4[mem1]: 5min Max Cached Memory Size
ShortLegend[mem1]: B
PageTop[mem1]:
MEMORY USAGE
############################ Swap info #####################################
LoadMIBs: /usr/local/share/snmp/mibs/UCD-SNMP-MIB.txt
Target[swap]: memAvailSwap.0&memAvailSwap.0:public@localhost
PageTop[swap]:
Memory Swap
Options[swap]: nopercent,growright,gauge,noinfo
Title[swap]: Memory Libre
MaxBytes[swap]: 3000000
kMG[swap]: k,M,G,T,P,X
YLegend[swap]: bytes
ShortLegend[swap]: bytes
LegendI[swap]: Memory Libre:
LegendO[swap]:
Legend1[swap]: Swap memory avail, in bytes
######################## Load Avarage ####################################
LoadMIBs: /usr/local/share/snmp/mibs/HOST-RESOURCES-MIB.txt
Target[load]:.1.3.6.1.4.1.2021.10.1.3.2&.1.3.6.1.4.1.2021.10.1.3.3:public@localhost * 100
WithPeak[load]: my
MaxBytes[load]: 10000
Title[load]: SYSTEM LOAD AVG.
Options[load]: growright,gauge,integer,nopercent
YLegend[load]: Load Average
LegendI[load]: 5 min:
LegendO[load]: 15 min:
Legend1[load]: Load average for 5 Min
Legend2[load]: Load average for 15 Min
Legend3[load]: Max load average for 5 Min
Legend4[load]: Max Load average for 15 Min
YTicsFactor[load]: 0.01
#ShortLegend[load]: _
PageTop[load]:
LOAD AVERAGE
可以根据具体的需求进行修改上面的配置文件,有什么疑问可以参考mrtg的官方文档,比如http://net-snmp.sourceforge.net/tutorial/tutorial-5/mrtg/index.html 有当前版本的snmp下mrtg.cfg配置的范例可以参考。
下面是我的mrtg监控页面效果 http://toplee:toplee@mrtg.toplee.com
以上的讨论基本都是基于在本机上进行监控而言,如果你有多台机器进行监控,可以根据具体需要修改snmpd.conf文件中public的权限,让您的mrtg监控机器可以通过snmp取到监控数据。
欢迎大家一起讨论,有发现我前面的什么地方有问题也欢迎给我指出来,共同进步。
请问启动snmpd时出现以下错误是怎么回事?
ns# tail /var/log/snmpd.log
sysctl: physmem: Cannot allocate memory
[init_smux] bind failed: Address already in use
Error opening specified endpoint “restart”
Server Exiting with code 1
一般来说应该还是conf文件配置问题,官方也很少有这方面完整的文档说明。
Michael 老大我的系统平台是freebsd6.1通过ports安装后发现cpu不能监控,错误如下,麻烦您帮我看一看
2006-11-10 10:38:21: ERROR: Target[cpu][_IN_] ‘ $target->[2]{$mode} + $target- >[3]{$mode} + $target->[4]{$mode} ‘ (warn): Use of uninitialized value in addi tion (+) at (eval 2234) line 1.
2006-11-10 10:38:21: ERROR: Target[cpu][_OUT_] ‘ $target->[2]{$mode} + $target ->[3]{$mode} + $target->[4]{$mode} ‘ (warn): Use of uninitialized value in add ition (+) at (eval 2235) line 1.
2006-11-10 10:38:21: ERROR: Target[usrsys][_IN_] ‘ $target->[5]{$mode} ‘ did not eval into defined data
2006-11-10 10:38:21: ERROR: Target[usrsys][_OUT_] ‘ $target->[5]{$mode} ‘ did no t eval into defined data
2006-11-10 10:38:21: ERROR: Target[swap][_IN_] ‘ $target->[8]{$mode} ‘ did not e val into defined data
2006-11-10 10:38:21: ERROR: Target[swap][_OUT_] ‘ $target->[8]{$mode} ‘ did not eval into defined data
Michael兄,
小弟在监控cpu时也碰到isee的这个问题
执行 mrtg /etc/mrtg/cpu.cfg后报错如下:
[root@unnc-nagios snmp]# mrtg /etc/mrtg/cpu.cfg
SNMP Error:
Received SNMP response with error code
error status: noSuchName
index 1 (OID: 1.3.6.1.4.1.2021.4.6.0)
SNMPv1_Session (remote host: “10.2.1.1” [10.2.1.1].161)
community: “public”
request ID: 381777074
PDU bufsize: 8000 bytes
timeout: 2s
retries: 5
backoff: 1)
at /usr/bin/../lib/mrtg2/SNMP_util.pm line 490
SNMPGET Problem for .1.3.6.1.4.1.2021.4.6.0 .1.3.6.1.4.1.2021.4.6.0 sysUptime sysName on
public@10.2.1.1::::::v4only
at /usr/bin/mrtg line 1920
ERROR: Target[mem][_IN_] ‘ $target->[0]{$mode} ‘ did not eval into defined data
ERROR: Target[mem][_OUT_] ‘ $target->[0]{$mode} ‘ did not eval into defined data
[root@unnc-nagios snmp]#
如果知道,敬请告知,谢谢!
mrtg的配置文件太麻烦,出现问题比较棘手,从错误情况来看,还是$target->[0]{$mode}这个变量没有在预定义的数据当中找到匹配的值,但是具体怎么产生的我也没有仔细研究过,多试试几次吧,最近也没有心情去折腾这些东西了,很抱歉不能帮上楼上的朋友。
michael, 你的mrtg监控页面效果
里面有乱码啊
最大 平均 目前
5 min: 91 $1$2/秒 11 $1$2/秒 14 $1$2/秒
15 min: 52 $1$2/秒 9 $1$2/秒 10 $1$2/秒
这些$1$2是乱码吧?
[Comment ID #23785 Will Be Quoted Here]
乱码一方面在在mrtg.cfg里面要指定html的header字符集,另外,$1$2那个是因为没有读到数据,空了我看看
Hey There. I found your blog using msn. This is a really well written article.
I will be sure to bookmark it and come back to read more of your useful information. Thanks for the post.
I’ll definitely comeback.
Very nice post. I just stumbled upon your weblog and wished to say that I’ve really enjoyed surfing around your blog posts.
In any case I’ll be subscribing to your rss feed and I hope you
write again very soon!
hey there and thank you for your info – I have certainly
picked up anything new from right here. I did however
expertise a few technical issues using this
web site, since I experienced to reload the website lots of times previous to I could
get it to load correctly. I had been wondering if your web host is OK?
Not that I am complaining, but sluggish loading instances times will sometimes affect your placement in google and
could damage your high quality score if advertising and marketing with Adwords.
Well I am adding this RSS to my e-mail and can look out for much more
of your respective fascinating content. Make sure you update this again soon.
Heya i’m for the first time here. I found this board and I find It truly useful &
it helped me out much. I hope to give something back and aid others
like you helped me.
Thanks for one’s marvelous posting! I truly enjoyed
reading it, you will be a great author.I will ensure that I bookmark your blog and may come
back in the future. I want to encourage
one to continue your great posts, have a nice day!
First off I want to say wonderful blog! I had a quick question in which I’d like to ask if you do not mind.
I was interested to find out how you center yourself and clear your
thoughts prior to writing. I’ve had a difficult time clearing
my mind in getting my thoughts out there. I truly
do take pleasure in writing but it just seems like the first 10 to 15 minutes are usually wasted just
trying to figure out how to begin. Any ideas or tips? Thank you!
Hi there to every , as I am really eager of reading this web site’s
post to be updated regularly. It contains pleasant data.
natalielise pof
hello!,I love your writing very much! share we keep in touch
extra approximately your post on AOL? I require a specialist in this area to solve my problem.
Maybe that’s you! Having a look forward to look you.
Fantastic facts. With thanks!
canadian pharcharmy
online pharmacies – http://canadianpharmacyntv.com/
london drugs canada ol f48e3c3
I like looking through an article that will make people
think. Also, many thanks for permitting me to comment!
Wow! This blog looks just like my old one! It’s on a completely different subject but it has pretty much the same page layout and design. Outstanding choice of colors!
With thanks, Good stuff!
viagra how does it work
interfere with viagra
viagra sperm
viagra motorcycle
Hey there! Someone in my Myspace group shared this website with us so I came to give it a look.
I’m definitely loving the information. I’m bookmarking and will be tweeting
this to my followers! Great blog and outstanding style and design.
bookmarked!!, I like your website!
Hello there, I discovered your website via Google at the same time as searching for a comparable subject, your web
site got here up, it seems to be great. I’ve bookmarked it in my google bookmarks.
Hello there, just was alert to your blog via Google, and located that it is really informative.
I am gonna be careful for brussels. I will appreciate if you continue this in future.
Lots of folks might be benefited out of your writing.
Cheers!
I always emailed this weblog post page to all my
friends, since if like to read it next my contacts will too.
Greate pieces. Keep posting such kind of information on your site.
Im really impressed by your site.
Hi there, You have performed a great job. I will definitely digg it and in my opinion suggest to my friends.
I am confident they will be benefited from this website.
I have been surfing online more than 3 hours nowadays, yet I by no means found any interesting article like yours.
It’s beautiful price sufficient for me. In my view,
if all site owners and bloggers made good content as you
did, the internet shall be much more helpful than ever before.
Greetings! This is my 1st comment here so I just wanted to give a quick shout out and say I truly enjoy reading
your blog posts. Can you suggest any other blogs/websites/forums that go over the same subjects?
Thanks for your time!
Every weekend i used to go to see this website, as i wish for enjoyment, for
the reason that this this web page conations actually fastidious funny material too.
Great work! This is the kind of information that are meant to be
shared across the net. Disgrace on the search engines for not positioning this publish higher!
Come on over and visit my website . Thank you =)
We stumbled over here coming from a different web page and thought
I might as well check things out. I like what I see so now i am following you.
Look forward to going over your web page repeatedly.
achat viagra arnaque
My spouse and I stumbled over here by a
different website and thought I might as well check things out.
I like what I see so i am just following you. Look forward to looking into your web page yet again.
viagra cialis simili
buy viagra 25mg tablets
viagra for men benefits
Wonderful blog! Do you have any hints for aspiring writers?
I’m hoping to start my own blog soon but I’m a little
lost on everything. Would you advise starting with a free platform
like WordPress or go for a paid option? There are so many choices out there
that I’m completely confused .. Any tips? Bless you!
tarif viagra tarifs viagra
Normally I do not learn post on blogs, however I wish to say that this write-up very pressured
me to check out and do it! Your writing style has been surprised me.
Thank you, quite great post.
viagra for men http://genericonlineviaqra.com/ – teva generic viagra viagra generic female viagra buy viagra online
wow inexpensive viagra
kanada preiswerter viagra
I want to to thank you for this great read!! I absolutely loved
every little bit of it. I have got you saved as a favorite to look at new things you post…
Its like you learn my thoughts! You appear to grasp so much approximately this,
like you wrote the e-book in it or something.
I feel that you simply can do with a few percent to drive the message house a
bit, but other than that, that is excellent blog. A great read.
I’ll certainly be back.
purchase viagra http://1loviagraosn.com/ – cheapest viagra online buy cheap viagra viagra canada buy viagra online usa
Wonderful article! That is the type of info
that should be shared across the web. Disgrace on Google for no longer positioning this
post upper! Come on over and consult with my web site . Thanks =)
Hey there would you mind sharing which blog platform you’re using?
I’m going to start my own blog soon but I’m having a tough time making a
decision between BlogEngine/Wordpress/B2evolution and Drupal.
The reason I ask is because your design and style seems different then most
blogs and I’m looking for something unique.
P.S Sorry for being off-topic but I had to ask!