<?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/"
	>

<channel>
	<title>Be the signal &#187; collectd</title>
	<atom:link href="http://bethesignal.org/blog/tag/collectd/feed/" rel="self" type="application/rss+xml" />
	<link>http://bethesignal.org</link>
	<description>where we&#039;re going, we don&#039;t need roads...</description>
	<lastBuildDate>Thu, 26 Jan 2012 05:52:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<atom:link rel='hub' href='http://bethesignal.org/?pushpress=hub'/>
		<item>
		<title>Watching nginx upstreams with collectd</title>
		<link>http://bethesignal.org/blog/2009/07/22/watching-nginx-upstreams-with-collectd/</link>
		<comments>http://bethesignal.org/blog/2009/07/22/watching-nginx-upstreams-with-collectd/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 11:22:12 +0000</pubDate>
		<dc:creator>Jeff Waugh</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[collectd]]></category>
		<category><![CDATA[FastCGI]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://bethesignal.org/?p=1577</guid>
		<description><![CDATA[Already happy with nginx in front of Apache for a number of sites, I decided it was time to start testing nginx/fastcgi on my personal server (the serial crash test dummy of my web operations). The only problem: I have &#8230; <a href="http://bethesignal.org/blog/2009/07/22/watching-nginx-upstreams-with-collectd/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Already happy with <a href="http://bethesignal.org/blog/2009/04/06/replacing-apache-with-nginx-for-static-file-serving/">nginx in front of Apache</a> for a number of sites, I decided it was time to start testing nginx/fastcgi on my personal server (the serial crash test dummy of my web operations). The only problem: I have yet to find a sensible method of grabbing useful runtime information from the PHP fastcgi process itself, and if you can&#8217;t sensibly <em>watch</em> it, you can&#8217;t sensibly <em>deploy</em> it.</p>
<p>So for now, instead of watching the PHP fastcgi process directly, I&#8217;m tracking its performance and usage from nginx&#8217;s perspective. You can log all kinds of data about upstream performance with nginx:</p>
<pre>log_format upstream '$remote_addr - - [$time_local] "$request" $status '
    'upstream $upstream_response_time request $request_time '
    '[for $host via $upstream_addr]';</pre>
<p>Then we log to a central upstream.log file from every <tt>location</tt> block which includes a <tt>fastcgi_pass</tt> parameter. For example:</p>
<pre>location ~ \.php$ {
    include  fastcgi_params;
    access_log  /var/log/nginx/upstream.log  upstream;
    fastcgi_pass  fcgi_php;
    fastcgi_param  SCRIPT_FILENAME  $wordpress_root$fastcgi_script_name;
}</pre>
<p>Now we know how many requests the PHP fastcgi process is handling, and how quickly it&#8217;s doing so. <a href="http://collectd.org/">collectd</a>&#8216;s <tt>tail</tt> plugin can watch this log file&#8230;</p>
<pre>&lt;Plugin tail&gt;
  &lt;File "/var/log/nginx/upstream.log"&gt;
  Instance "nginx"
    &lt;Match&gt;
      Regex ".*"
      DSType "CounterInc"
      Type counter
      Instance "requests"
    &lt;/Match&gt;
    &lt;Match&gt;
      Regex " upstream ([0-9.]*) "
      DSType GaugeAverage
      Type delay
      Instance "upstream"
    &lt;/Match&gt;
  &lt;/File&gt;
&lt;/Plugin&gt;</pre>
<p>&#8230; and turn it into something readable. First, the number of requests per second (which I only started watching at 14:30 this afternoon), then the delay for each request:</p>
<p><img style=' display: block; margin-right: auto; margin-left: auto;'  class="aligncenter size-full wp-image-1578" title="nginx Upstream Requests" src="/wp-content/uploads/2009/07/nginx-upstream-requests.png" alt="nginx Upstream Requests" width="481" height="179" /></p>
<p><img style=' display: block; margin-right: auto; margin-left: auto;'  class="aligncenter size-full wp-image-1579" title="nginx Upstream Response" src="/wp-content/uploads/2009/07/nginx-upstream-speed.png" alt="nginx Upstream Response" width="481" height="179" /></p>
<p>(Relatively boring statistics here, as it&#8217;s only monitoring the dynamic processing of my personal sites.)</p>
<p>Combining nginx&#8217;s flexible logging and collectd&#8217;s tail plugin makes it pretty easy to watch the usage and performance of whatever you&#8217;re running behind nginx, even if you can&#8217;t instrument the application itself.</p>
<p>&#8230; and thus far, I&#8217;m pretty happy with the performance, reliability and resource usage of nginx in front of PHP in fastcgi mode. <img width='16' height='16' src='http://bethesignal.org/wp-content/plugins/tango-smilies/tango/face-smile.png' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://bethesignal.org/blog/2009/07/22/watching-nginx-upstreams-with-collectd/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>

