<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule">

<channel>
	<title>wolfg&#039;s Weblog &#187; 运维</title>
	<atom:link href="http://guoyong.me/tag/%e8%bf%90%e7%bb%b4/feed/" rel="self" type="application/rss+xml" />
	<link>http://guoyong.me</link>
	<description>wolfg&#039;s journey with open source, linux, programming, sysadm ...</description>
	<lastBuildDate>Wed, 04 Apr 2012 12:42:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/2.5/cn/</creativeCommons:license>		<item>
		<title>使用Eclipse Memory Analyzer(MAT)解决Java Web应用故障</title>
		<link>http://guoyong.me/dev/solve-jvm-oom-problem-with-mat/</link>
		<comments>http://guoyong.me/dev/solve-jvm-oom-problem-with-mat/#comments</comments>
		<pubDate>Sun, 11 Mar 2012 14:54:11 +0000</pubDate>
		<dc:creator>guoyong</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[运维]]></category>
		<category><![CDATA[heap dump]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[jvm]]></category>
		<category><![CDATA[mat]]></category>

		<guid isPermaLink="false">http://guoyong.me/?p=928</guid>
		<description><![CDATA[这周一我负责维护的一个系统突然出现故障，用户反映系统很慢，浏览器加载半天最后进了错误页面。登录到系统查看，发现系统负载很高，用sar命令进一步明确了是java进程在某一时刻后突然占据了大量CPU资源。查看应用日志，发现了OutOfMemory异常，然后使用jstat的gcutil确认JVM heap工作不正常，已经有上千次的full gc了。 用VisualGC或者jmap工具生成Headp dump文件，然后用MAT打开，生成内存泄露的分析报告，查找占用内存最大的对象并通过Thread call stack就可以定位导致问题出现的类和方法。 由于系统属旧系统，代码一直没有改动，显然是数据出了问题。最终发现是用户输入的格式不规范的数据，使得对数据做查找替换的一段代码不断地扩大1个字符串对象，导致内存消耗不断增长，gc频繁。 # sar # sar -P ALL 1 5 # jstat -gcutil &#60;pid_of_jvm&#62; 1000 # jmap -dump:format=b,file=HeapDump.hprof &#60;pid_of_jvm&#62; 参考: http://wiki.eclipse.org/index.php/MemoryAnalyzer]]></description>
			<content:encoded><![CDATA[<p>这周一我负责维护的一个系统突然出现故障，用户反映系统很慢，浏览器加载半天最后进了错误页面。登录到系统查看，发现系统负载很高，用sar命令进一步明确了是java进程在某一时刻后突然占据了大量CPU资源。查看应用日志，发现了OutOfMemory异常，然后使用jstat的gcutil确认JVM heap工作不正常，已经有上千次的full gc了。</p>
<p>用VisualGC或者jmap工具生成Headp dump文件，然后用MAT打开，生成内存泄露的分析报告，查找占用内存最大的对象并通过Thread call stack就可以定位导致问题出现的类和方法。</p>
<p>由于系统属旧系统，代码一直没有改动，显然是数据出了问题。最终发现是用户输入的格式不规范的数据，使得对数据做查找替换的一段代码不断地扩大1个字符串对象，导致内存消耗不断增长，gc频繁。</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"># sar<br />
# sar -P ALL 1 5<br />
# jstat -gcutil &lt;pid_of_jvm&gt; 1000<br />
# jmap -dump:format=b,file=HeapDump.hprof &lt;pid_of_jvm&gt;</div></div>
<p>参考: <a href="http://wiki.eclipse.org/index.php/MemoryAnalyzer" target="_blank">http://wiki.eclipse.org/index.php/MemoryAnalyzer</a></p>
]]></content:encoded>
			<wfw:commentRss>http://guoyong.me/dev/solve-jvm-oom-problem-with-mat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MongoDB日志回滚</title>
		<link>http://guoyong.me/linux/sysadm/mongodb%e6%97%a5%e5%bf%97%e5%9b%9e%e6%bb%9a/</link>
		<comments>http://guoyong.me/linux/sysadm/mongodb%e6%97%a5%e5%bf%97%e5%9b%9e%e6%bb%9a/#comments</comments>
		<pubDate>Thu, 02 Jun 2011 00:51:02 +0000</pubDate>
		<dc:creator>wolfg</dc:creator>
				<category><![CDATA[SysAdmin]]></category>
		<category><![CDATA[运维]]></category>
		<category><![CDATA[mongodb]]></category>

		<guid isPermaLink="false">http://guoyong.org/?p=641</guid>
		<description><![CDATA[# kill -SIGUSR1 `cat /var/run/mongodb.pid` 用在shell脚本里时，命令要改成这样： kill -USR1 `cat /var/run/mongodb.pid` 参考：http://www.mongodb.org/display/DOCS/Logging#Logging-Rotatingthelogfiles]]></description>
			<content:encoded><![CDATA[<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"># kill -SIGUSR1 `cat /var/run/mongodb.pid`</div></div>
<p>用在shell脚本里时，命令要改成这样： kill -USR1 `cat /var/run/mongodb.pid` </p>
<p>参考：http://www.mongodb.org/display/DOCS/Logging#Logging-Rotatingthelogfiles   </p>
]]></content:encoded>
			<wfw:commentRss>http://guoyong.me/linux/sysadm/mongodb%e6%97%a5%e5%bf%97%e5%9b%9e%e6%bb%9a/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RHEL5下编译MongoDB</title>
		<link>http://guoyong.me/linux/sysadm/rhel5%e4%b8%8b%e7%bc%96%e8%af%91mongodb/</link>
		<comments>http://guoyong.me/linux/sysadm/rhel5%e4%b8%8b%e7%bc%96%e8%af%91mongodb/#comments</comments>
		<pubDate>Wed, 01 Jun 2011 06:21:29 +0000</pubDate>
		<dc:creator>wolfg</dc:creator>
				<category><![CDATA[SysAdmin]]></category>
		<category><![CDATA[DevOps]]></category>
		<category><![CDATA[运维]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[mongodb]]></category>

		<guid isPermaLink="false">http://guoyong.org/?p=630</guid>
		<description><![CDATA[很多人都说自己编译的稳定好用，我也来试试： 1. 参考官方文档，手工编译Spider Monkey # curl -O ftp://ftp.mozilla.org/pub/mozilla.org/js/js-1.7.0.tar.gz # tar zxvf js-1.7.0.tar.gz # cd js/src # export CFLAGS=&#34;-DJS_C_STRINGS_ARE_UTF8&#34; # make -f Makefile.ref # JS_DIST=/usr make -f Makefile.ref export 2. 安装scons，用官网的rpm包就行。 3. 重新编译pcre。自带的编译时没带&#8211;enable-unicode-properties参数，mongdb启动时会提示：warning: some regex utf8 things will not work. pcre &#8230; <a href="http://guoyong.me/linux/sysadm/rhel5%e4%b8%8b%e7%bc%96%e8%af%91mongodb/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>很多人都说自己编译的稳定好用，我也来试试：</p>
<p>1. 参考官方文档，手工编译Spider Monkey</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"># curl -O ftp://ftp.mozilla.org/pub/mozilla.org/js/js-1.7.0.tar.gz<br />
# tar zxvf js-1.7.0.tar.gz<br />
# cd js/src<br />
# export CFLAGS=&quot;-DJS_C_STRINGS_ARE_UTF8&quot;<br />
# make -f Makefile.ref<br />
# JS_DIST=/usr make -f Makefile.ref export</div></div>
<p>2. 安装scons，用<a href="http://www.scons.org/download.php">官网</a>的rpm包就行。</p>
<p>3. 重新编译pcre。自带的编译时没带&#8211;enable-unicode-properties参数，mongdb启动时会提示：warning: some regex utf8 things will not work.  pcre build doesn&#8217;t have &#8211;enable-unicode-properties. RPMS包是在<a href="http://rpm.pbone.net/">这里</a>找到的。</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"># rpm -ivh pcre-6.6-2.el5_1.7.src.rpm<br />
# vi /usr/src/redhat/SPECS/pcre.spec<br />
%configure --enable-utf8<br />
修改成<br />
%configure --enable-utf8 --enable-unicode-properties<br />
# rpmbuild -ba /usr/src/redhat/SPECS/pcre.spec<br />
# rpm -Uvh /usr/src/redhat/RPMS/x86_64/pcre*.rpm</div></div>
<p>4. 安装1.41版本的boost库。<a href="http://pkgs.org/centos-5-rhel-5/epel-x86_64/boost141-1.41.0-2.el5.x86_64.rpm.html">这里</a>可以找到编译好的boost库的RPM包。因为后面要编译成静态库，还需要安装boost141-static-1.41.0-2.el5.i386.rpm</p>
<p>5. 开始编译MongoDB</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"># cd mongodb-src-r1.8.1<br />
# scons --libpath=/usr/lib64/boost141/ \<br />
&nbsp; &nbsp;--cpppath=/usr/include/boost141/ \<br />
&nbsp; &nbsp;--release --64 --static all</div></div>
<p>如果你没有&#8211;release和&#8211;static选项，可能会看见下面这样的消息<br />
 *** notice: no readline library, mongo shell will not have nice interactive line editing ***<br />
解决方法是加上&#8211;extralib=ncurses。</p>
<p>6. 安装</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"># cd mongodb-src-r1.8.1<br />
# scons --libpath=/usr/lib64/boost141/ \<br />
&nbsp; &nbsp;--cpppath=/usr/include/boost141/ \<br />
&nbsp; &nbsp;--release --64 --static --prefix=/opt/mongo-1.8.1 install</div></div>
<p>参考：<br />
1. <a href="http://www.mongodb.org/display/DOCS/Building+for+Linux">http://www.mongodb.org/display/DOCS/Building+for+Linux</a><br />
2. <a href="http://hi.baidu.com/farmerluo/blog/item/37364623f35ba55e9922ed2f.html">http://hi.baidu.com/farmerluo/blog/item/37364623f35ba55e9922ed2f.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://guoyong.me/linux/sysadm/rhel5%e4%b8%8b%e7%bc%96%e8%af%91mongodb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>nrpe使用一例</title>
		<link>http://guoyong.me/linux/sysadm/nrpe%e4%bd%bf%e7%94%a8%e4%b8%80%e4%be%8b/</link>
		<comments>http://guoyong.me/linux/sysadm/nrpe%e4%bd%bf%e7%94%a8%e4%b8%80%e4%be%8b/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 07:22:25 +0000</pubDate>
		<dc:creator>wolfg</dc:creator>
				<category><![CDATA[SysAdmin]]></category>
		<category><![CDATA[监控]]></category>
		<category><![CDATA[运维]]></category>
		<category><![CDATA[nagios]]></category>
		<category><![CDATA[nrpe]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://guoyong.org/?p=548</guid>
		<description><![CDATA[NRPE的作用是在远程主机上运行Nagios插件，以便监控远程主机。 Ubuntu Server下安装NRPE很方便： $ sudo apt-get install nagios-nrpe-server nagios-plugins 默认的几个检查命令(check_users, check_load等)都已经在/etc/naigos/nrpe.cfg和/etc/nagios/nrpe_local.cfg配置好了。在Nagios里配置监控服务使用类似如下的监控命令就可以了： check_command&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;check_nrpe!check_load 如果需要自定义监控命令，只需在/etc/nagios/nrpe_local.cfg里设置，重启NRPE服务，再在Nagios里配置监控服务即可。比如，要添加一个监控TCP各种状态的命令，步骤如下： @remotehost$ cd /usr/lib/nagios/plugins$ sudo wget http://www.tuschy.com/nagios/plugins/check_tcp_count$ sudo chmod +x check_tcp_count$ cd /etc/nagios$ sudo vi nrpe_local.cfgcommand[check_tcp_count]=/usr/lib/nagios/plugins/check_tcp_count$ sudo service nagios-nrpe-server &#8230; <a href="http://guoyong.me/linux/sysadm/nrpe%e4%bd%bf%e7%94%a8%e4%b8%80%e4%be%8b/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>NRPE的作用是在远程主机上运行Nagios插件，以便监控远程主机。</p>
<p>Ubuntu Server下安装NRPE很方便：</p>
<div class="hl-surround"><div class="hl-main">$ sudo apt-get install nagios-nrpe-server nagios-plugins</div></div>
<p>默认的几个检查命令(check_users, check_load等)都已经在/etc/naigos/nrpe.cfg和/etc/nagios/nrpe_local.cfg配置好了。在Nagios里配置监控服务使用类似如下的监控命令就可以了：</p>
<div class="hl-surround"><div class="hl-main">check_command&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;check_nrpe!check_load</div></div>
<p>如果需要自定义监控命令，只需在/etc/nagios/nrpe_local.cfg里设置，重启NRPE服务，再在Nagios里配置监控服务即可。比如，要添加一个监控TCP各种状态的命令，步骤如下：</p>
<div class="hl-surround"><div class="hl-main">@remotehost<br />$ cd /usr/lib/nagios/plugins<br />$ sudo wget http://www.tuschy.com/nagios/plugins/check_tcp_count<br />$ sudo chmod +x check_tcp_count<br />$ cd /etc/nagios<br />$ sudo vi nrpe_local.cfg<br />command[check_tcp_count]=/usr/lib/nagios/plugins/check_tcp_count<br />$ sudo service nagios-nrpe-server restart<br /><br />@nagioshost<br />$ sudo vi remotehost.cfg<br />define service{<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;use&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; generic-service<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;host_name&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; remotehostname<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;service_description&nbsp; &nbsp; &nbsp; &nbsp; Tcp count<br />&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;check_command&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; check_nrpe!check_tcp_count<br />}</div></div>
]]></content:encoded>
			<wfw:commentRss>http://guoyong.me/linux/sysadm/nrpe%e4%bd%bf%e7%94%a8%e4%b8%80%e4%be%8b/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>使用Cacti监控JVM</title>
		<link>http://guoyong.me/linux/sysadm/%e4%bd%bf%e7%94%a8cacti%e7%9b%91%e6%8e%a7jvm/</link>
		<comments>http://guoyong.me/linux/sysadm/%e4%bd%bf%e7%94%a8cacti%e7%9b%91%e6%8e%a7jvm/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 08:55:59 +0000</pubDate>
		<dc:creator>wolfg</dc:creator>
				<category><![CDATA[SysAdmin]]></category>
		<category><![CDATA[cacti]]></category>
		<category><![CDATA[监控]]></category>
		<category><![CDATA[运维]]></category>
		<category><![CDATA[jvm]]></category>
		<category><![CDATA[snmp]]></category>

		<guid isPermaLink="false">http://guoyong.org/?p=512</guid>
		<description><![CDATA[Cacti官方论坛里有几个监控JVM的模板： http://forums.cacti.net/about19761.html http://forums.cacti.net/post-112268.html 导入到Cacti后，需要启用JVM的SNMP Agent，方法如下： 1. 启动JVM的参数里加入-Dcom.sun.management.snmp.port=9998 这个是指定SNMP Agent的监听端口。 2. 设置访问权限 $ sudo cp $JRE_HOME/lib/management/snmp.acl.template $JRE_HOME/lib/management/snmp.acl$ sudo vi $JRE_HOME/lib/management/snmp.aclacl = {&#160; {&#160;&#160; &#160;communities = public, private&#160;&#160; &#160;access = read-only&#160;&#160; &#160;managers = localhost&#160; }}trap = {&#160; {&#160;&#160; &#160;trap-community = public&#160;&#160; &#160;hosts &#8230; <a href="http://guoyong.me/linux/sysadm/%e4%bd%bf%e7%94%a8cacti%e7%9b%91%e6%8e%a7jvm/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Cacti官方论坛里有几个监控JVM的模板：</p>
<ul>
<li><a href="http://forums.cacti.net/about19761.html">http://forums.cacti.net/about19761.html</a></li>
<li>
<a href="http://forums.cacti.net/post-112268.html">http://forums.cacti.net/post-112268.html</a></li>
</ul>
<p>导入到Cacti后，需要启用JVM的SNMP Agent，方法如下：<br />
1. 启动JVM的参数里加入-Dcom.sun.management.snmp.port=9998 这个是指定SNMP Agent的监听端口。<br />
2. 设置访问权限</p>
<div class="hl-surround"><div class="hl-main">$ sudo cp $JRE_HOME/lib/management/snmp.acl.template $JRE_HOME/lib/management/snmp.acl<br />$ sudo vi $JRE_HOME/lib/management/snmp.acl<br /><br />acl = {<br />&nbsp; {<br />&nbsp;&nbsp; &nbsp;communities = public, private<br />&nbsp;&nbsp; &nbsp;access = read-only<br />&nbsp;&nbsp; &nbsp;managers = localhost<br />&nbsp; }<br />}<br /><br />trap = {<br />&nbsp; {<br />&nbsp;&nbsp; &nbsp;trap-community = public<br />&nbsp;&nbsp; &nbsp;hosts = localhost<br />&nbsp; }<br />}</div></div>
<p>3. 设置配置文件的权限，必须只能为启用JVM的用户只读，否则不能工作。(management.properties不用修改，使用默认配置即可)</p>
<div class="hl-surround"><div class="hl-main">$ sudo chmod 600 management.properties snmp.acl<br />$ sudo chown jetty management.properties snmp.acl</div></div>
<p>4. 重启JVM，用netstat命令检查9998端口是否已被监听或用snmpwalk命令检查。</p>
<div class="hl-surround"><div class="hl-main">$ sudo netstat -tlunp |grep 9998<br />$ snmpwalk -v 2c -c public localhost:9998 .1.3.6.1.4.1.42</div></div>
<p>5. 为了让远程的Cacti主机可以访问，可使用snmpd的proxy功能将请求转发到localhost的JVM SNMP Agent上。修改snmpd的配置文件，添加<br />
proxy -v 2c -c public localhost:9998 .1.3.6.1.4.1.42<br />
然后重启snmpd服务。在Cacti主机上以snmpwalk命令检查，应该能得到与上一步中snmpwalk命令一样的输出。snmpwalk -v 2c -c public remotehost .1.3.6.1.4.1.42<br />
6. 至此，可以在Cacti里为JVM主机添加监控图表了，注意Device的SNMP Options配置里SNMP Version要选择Version 2。</p>
<p>参考：</p>
<ul>
<li><a href="http://java.sun.com/javase/6/docs/technotes/guides/management/snmp.html">http://java.sun.com/javase/6/docs/technotes/guides/management/snmp.html</a></li>
<li>
<a href="http://www.fifi.org/cgi-bin/man2html/usr/share/man/man5/snmpd.conf.5snmp.gz">http://www.fifi.org/cgi-bin/man2html/usr/share/man/man5/snmpd.conf.5snmp.gz</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://guoyong.me/linux/sysadm/%e4%bd%bf%e7%94%a8cacti%e7%9b%91%e6%8e%a7jvm/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>npc安装问题解决一例</title>
		<link>http://guoyong.me/linux/sysadm/npc%e5%ae%89%e8%a3%85%e9%97%ae%e9%a2%98%e8%a7%a3%e5%86%b3%e4%b8%80%e4%be%8b/</link>
		<comments>http://guoyong.me/linux/sysadm/npc%e5%ae%89%e8%a3%85%e9%97%ae%e9%a2%98%e8%a7%a3%e5%86%b3%e4%b8%80%e4%be%8b/#comments</comments>
		<pubDate>Sun, 17 Jan 2010 12:27:34 +0000</pubDate>
		<dc:creator>wolfg</dc:creator>
				<category><![CDATA[SysAdmin]]></category>
		<category><![CDATA[cacti]]></category>
		<category><![CDATA[监控]]></category>
		<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[运维]]></category>
		<category><![CDATA[nagios]]></category>
		<category><![CDATA[npc]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://guoyong.org/?p=504</guid>
		<description><![CDATA[Cacti和Nagios都是好用的运维监控软件，NPC(Nagios Plugin for Cacti)是一个Cacti插件，安装后可以在Cacti界面里使用Nagios的功能。官方安装文档在这里。 我的安装环境是这样的： Ubuntu 6.06 LTS PHP 5.1.2 Cacti 0.8.7e Cacti Plugin Architecture 2.6 Nagios 3.2.0 NDOUtils 1.4b7 PHP必须安装PDO 和 JSON扩展。由于NPC使用了Ext JS，如果没有JSON扩展，NPC的界面不会出来，只能看到一个空白页面。Ubuntu 6.06下安装PDO可以参考这里。 按照官方文档安装配置好后，遇到了没有显示任何数据的问题，host, hostgroup, service, servicegroup等等都看不到。 检查了NPC的数据库表，有数据，说明NDOUtils已经工作。没有出现在界面上，说明是NPC从数据库读出来到界面显示过程中出现的问题。 用Firebug找出NPC界面为了获取显示数据的Ajax请求(比如/cacti/plugins/npc/npc.php?module=servicegroups&#038;action=getHostStatusPortlet)，直接在浏览器里访问，可以看到出了异常：Fatal error: Uncaught exception &#8216;Doctrine_Exception&#8217; with message &#8216;Couldn&#8217;t find class &#8230; <a href="http://guoyong.me/linux/sysadm/npc%e5%ae%89%e8%a3%85%e9%97%ae%e9%a2%98%e8%a7%a3%e5%86%b3%e4%b8%80%e4%be%8b/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.cacti.net/">Cacti</a>和<a href="http://www.nagios.org/">Nagios</a>都是好用的运维监控软件，<a href="http://trac2.assembla.com/npc/">NPC</a>(Nagios Plugin for Cacti)是一个Cacti插件，安装后可以在Cacti界面里使用Nagios的功能。官方安装文档在<a href="http://trac2.assembla.com/npc/wiki/QuickStartGuide">这里</a>。</p>
<p>我的安装环境是这样的：</p>
<ul>
<li>Ubuntu 6.06 LTS</li>
<li>PHP 5.1.2</li>
<li>Cacti 0.8.7e</li>
<li><a href="http://cactiusers.org/downloads/">Cacti Plugin Architecture 2.6</a></li>
<li>Nagios 3.2.0</li>
<li>NDOUtils 1.4b7</li>
</ul>
<p>PHP必须安装PDO 和 JSON扩展。由于NPC使用了Ext JS，如果没有JSON扩展，NPC的界面不会出来，只能看到一个空白页面。Ubuntu 6.06下安装PDO可以参考<a href="http://bhiv.com/getting-pdo-to-work-with-ubuntus-606-lts-dapper-drake/">这里</a>。</p>
<p>按照官方文档安装配置好后，遇到了没有显示任何数据的问题，host, hostgroup, service, servicegroup等等都看不到。</p>
<p>检查了NPC的数据库表，有数据，说明NDOUtils已经工作。没有出现在界面上，说明是NPC从数据库读出来到界面显示过程中出现的问题。</p>
<p>用Firebug找出NPC界面为了获取显示数据的Ajax请求(比如/cacti/plugins/npc/npc.php?module=servicegroups&#038;action=getHostStatusPortlet)，直接在浏览器里访问，可以看到出了异常：Fatal error: Uncaught exception &#8216;Doctrine_Exception&#8217; with message &#8216;Couldn&#8217;t find class NpcServicegroups&#8217; 。显然是Doctrine没有加载到NPC定义的领域类。</p>
<p>经过一番对Doctrine的调试，发现原因在Doctrine类的loadModels方法(Line 516 in Doctrine.php)</p>
<div class="hl-surround"><div class="hl-main"><span style="color: #00008b;">$e</span><span style="color: Gray;"> = </span><span style="color: Blue;">explode</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">.</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: #00008b;">$file</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">getFileName</span><span style="color: Olive;">())</span><span style="color: Gray;">;</span></div></div>
<p>这里getFileName返回了带绝对路径的文件名，导致autoload函数失败。改成下面这样就解决了。</p>
<div class="hl-surround"><div class="hl-main"><span style="color: #00008b;">$e</span><span style="color: Gray;"> = </span><span style="color: Blue;">explode</span><span style="color: Olive;">(</span><span style="color: #8b0000;">'</span><span style="color: Red;">.</span><span style="color: #8b0000;">'</span><span style="color: Gray;">, </span><span style="color: Blue;">basename</span><span style="color: Olive;">(</span><span style="color: #00008b;">$file</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">getFileName</span><span style="color: Olive;">()))</span><span style="color: Gray;">;</span></div></div>
<p>不过还是不明白为什么getFileName返回的是带绝对路径的文件名，是跟我的系统环境有关系吗？有熟悉PHP的朋友能解释一下就好了。</p>
]]></content:encoded>
			<wfw:commentRss>http://guoyong.me/linux/sysadm/npc%e5%ae%89%e8%a3%85%e9%97%ae%e9%a2%98%e8%a7%a3%e5%86%b3%e4%b8%80%e4%be%8b/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.590 seconds -->

