<?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>Sandeep Ghael &#187; Ubuntu</title>
	<atom:link href="http://sandeepghael.com/category/ubuntu/feed/" rel="self" type="application/rss+xml" />
	<link>http://sandeepghael.com</link>
	<description>acts_as_blog</description>
	<lastBuildDate>Wed, 20 Apr 2011 14:48:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
		<item>
		<title>Ruby Server monitoring scripts w/ email alerts</title>
		<link>http://sandeepghael.com/2009/10/ruby-server-monitoring-scripts-w-email-alerts/</link>
		<comments>http://sandeepghael.com/2009/10/ruby-server-monitoring-scripts-w-email-alerts/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 19:20:16 +0000</pubDate>
		<dc:creator>sghael</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://sandeepghael.com/?p=324</guid>
		<description><![CDATA[While working on several rails projects, I&#8217;ve found it useful to write a couple of scripts to monitor real-time server health. Basically, I&#8217;d like to automatically be notified by email if anything peculiar is occurring on the server. Two pretty obvious things to alert on are low disk space and high average load. While there [...]]]></description>
			<content:encoded><![CDATA[<p>While working on several rails projects, I&#8217;ve found it useful to write a couple of scripts to monitor real-time server health.  Basically, I&#8217;d like to automatically be notified by email if anything peculiar is occurring on the server.  Two pretty obvious things to alert on are <strong>low disk space</strong> and <strong>high average load</strong>.  While there are great tools out there like Munin/Nagios that will give you detailed instrumentation for your server, I just needed something lightweight that I could periodically cron.  These scripts are designed for use on Ubuntu 9.04.  YMMV.</p>
<h2>disk_usage.rb</h2>
<p>This script will email foo@example.com when the disk space left on either sda1 and sda2 falls below 5GB.  The threshold is just a variable you can change.  You can also add to or remove from the list of sda devices you want to monitor using the disks array.</p>
<p>[cci lang="ruby"]<br />
#!/usr/bin/env ruby</p>
<p>require &#8216;rubygems&#8217;<br />
require &#8216;send_gmail&#8217;</p>
<p>TO_EMAIL = &#8216;foo@example.com&#8217;</p>
<p>filesys = `df -h`</p>
<p>disks = [1,2]</p>
<p>disks.each do |i|<br />
  r = filesys[/sda#{i}\s+[\d\.]+[MG]\s+[\d\.]+[MG]\s+([\d\.]+[MG])/,1]<br />
  message = &#8220;Low disk space on /sda#{i}: only #{r.to_i}GB remaining&#8221;<br />
  hsh={:to=>TO_EMAIL, :subject=>&#8217;Low disk space warning!&#8217;, :body=>message}<br />
  SendGMail.send_gmail(hsh) if r.to_i < 5 or r[/M$/]<br />
  puts message if r.to_i < 5 or r[/M$/]<br />
end<br />
[/cci]</p>
<h2>load_check.rb</h2>
<p>This script will use the uptime command to get the avarage load.  I&#8217;m just using the 1min and 5min averages.  If the 1min average load is over 9 or the 5min average load is over 4, bar@example.com will get an email.</p>
<p>[cci lang="ruby"]<br />
#!/usr/bin/env ruby</p>
<p>require &#8216;rubygems&#8217;<br />
require &#8216;send_gmail&#8217;</p>
<p>TO_EMAIL = &#8216;bar@example.com&#8217;</p>
<p>uptime = `uptime`</p>
<p>load_1min = uptime.split(&#8221; &#8220;)[8].chop()<br />
load_5min = uptime.split(&#8221; &#8220;)[9].chop()</p>
<p>message = &#8220;Load on server is 1min/5min avg: #{load_1min} / #{load_5min} &#8221;</p>
<p>hsh={:to=>TO_EMAIL, :subject=>&#8217;Load warning!&#8217;, :body=>message}<br />
SendGMail.send_gmail(hsh) if (load_1min.to_i > 9) or (load_5min.to_i > 4)<br />
[/cci]</p>
<p>You may have noticed an included module &#8220;send_gmail&#8221; and a call to &#8220;SendGMail&#8221; in the previous scripts.  Since I use Gmail for all my outbound emails, the underlying alert system needs a way to make calls to the Gmail servers.  Problem solved using this nifty little Ruby Gmailer script I found on at <a href="http://codingfrenzy.alexpmay.com/2007/12/sending-gmail-from-standalone-ruby.html">http://codingfrenzy.alexpmay.com/2007/12/sending-gmail-from-standalone-ruby.html</a>.  I did make a few modifications to the script, so I&#8217;m including it here.  You&#8217;ll want to set your gmail account/domain info if you do use this mailer.</p>
<h2>send_gmail.rb</h2>
<p>[cci lang="ruby"]<br />
#!/usr/bin/env ruby</p>
<p>require &#8216;rubygems&#8217;</p>
<p>gem &#8216;actionmailer&#8217;<br />
require &#8216;action_mailer&#8217;<br />
require &#8216;openssl&#8217;<br />
require &#8216;net/smtp&#8217;</p>
<p>module SendGMail</p>
<p>@user_name=&#8217;someone@example.com&#8217;<br />
@domain=&#8217;example.com&#8217;<br />
@password=&#8217;password&#8217;</p>
<p>def SendGMail.send_gmail(hsh)</p>
<p>raw_attachments=hsh.fetch(:raw_attachements, [])<br />
if hsh.has_key?(:raw_attachment)<br />
 raw_attachments.push(hsh[:raw_attachment])<br />
end</p>
<p>mail=TMail::Mail.new<br />
mail.to=hsh[:to]<br />
mail.date=Time.now<br />
mail.from=@user_name<br />
mail.subject=hsh[:subject]</p>
<p>main=mail<br />
main=TMail::Mail.new<br />
main.body = hsh[:body]<br />
main.set_content_type(&#8216;text/plain&#8217;, nil, &#8216;charset&#8217;=>&#8217;utf-8&#8242;)<br />
mail.parts.push(main)</p>
<p>for raw_attachment in raw_attachments<br />
 part = TMail::Mail.new<br />
 transfer_encoding=raw_attachment[:transfer_encoding]<br />
 body=raw_attachment[:body]<br />
 case (transfer_encoding || &#8220;&#8221;).downcase<br />
   when &#8220;base64&#8243; then<br />
     part.body = TMail::Base64.folding_encode(body)<br />
   when &#8220;quoted-printable&#8221;<br />
     part.body = [body].pack(&#8220;M*&#8221;)<br />
   else<br />
     part.body = body<br />
 end</p>
<p> part.transfer_encoding = transfer_encoding<br />
 part.set_content_type(raw_attachment[:mime_type], nil, &#8216;name&#8217; => raw_attachment[:filename])<br />
 part.set_content_disposition(&#8220;attachment&#8221;, &#8220;filename&#8221;=>raw_attachment[:filename])<br />
 mail.parts.push(part)<br />
end</p>
<p>mail.set_content_type(&#8216;multipart&#8217;, &#8216;mixed&#8217;)<br />
ActionMailer::Base.deliver(mail)</p>
<p>end</p>
<p>ActionMailer::Base.smtp_settings = {<br />
:address => &#8216;smtp.gmail.com&#8217;,<br />
:domain => @domain,<br />
:authentication => :plain,<br />
:port => 587,<br />
:user_name => @user_name,<br />
:password => @password<br />
}</p>
<p>Net::SMTP.class_eval do<br />
private<br />
def do_start(helodomain, user, secret, authtype)<br />
 raise IOError, &#8216;SMTP session already started&#8217; if @started<br />
 check_auth_args user, secret if user or secret</p>
<p> sock = timeout(@open_timeout) { TCPSocket.open(@address, @port) }<br />
 @socket = Net::InternetMessageIO.new(sock)<br />
 @socket.read_timeout = 60 #@read_timeout<br />
 @socket.debug_output = STDERR #@debug_output</p>
<p> check_response(critical { recv_response() })<br />
 do_helo(helodomain)</p>
<p> raise &#8216;openssl library not installed&#8217; unless defined?(OpenSSL)<br />
 starttls<br />
 ssl = OpenSSL::SSL::SSLSocket.new(sock)<br />
 ssl.sync_close = true<br />
 ssl.connect<br />
 @socket = Net::InternetMessageIO.new(ssl)<br />
 @socket.read_timeout = 60 #@read_timeout<br />
 @socket.debug_output = STDERR #@debug_output<br />
 do_helo(helodomain)</p>
<p> authenticate user, secret, authtype if user<br />
 @started = true<br />
ensure<br />
 unless @started<br />
   # authentication failed, cancel connection.<br />
     @socket.close if not @started and @socket and not @socket.closed?<br />
   @socket = nil<br />
 end<br />
end</p>
<p>def do_helo(helodomain)<br />
  begin<br />
   if @esmtp<br />
     ehlo helodomain<br />
   else<br />
     helo helodomain<br />
   end<br />
 rescue Net::ProtocolError<br />
   if @esmtp<br />
     @esmtp = false<br />
     @error_occured = false<br />
     retry<br />
   end<br />
   raise<br />
 end<br />
end</p>
<p>def starttls<br />
 getok(&#8216;STARTTLS&#8217;)<br />
end</p>
<p>def quit<br />
 begin<br />
   getok(&#8216;QUIT&#8217;)<br />
 rescue EOFError, OpenSSL::SSL::SSLError<br />
 end<br />
end<br />
end<br />
end</p>
<p>[/cci]</p>
]]></content:encoded>
			<wfw:commentRss>http://sandeepghael.com/2009/10/ruby-server-monitoring-scripts-w-email-alerts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting RED 5 up and running on Ubuntu 9.04</title>
		<link>http://sandeepghael.com/2009/07/getting-red-5-up-and-running-on-ubuntu-9-04/</link>
		<comments>http://sandeepghael.com/2009/07/getting-red-5-up-and-running-on-ubuntu-9-04/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 19:31:59 +0000</pubDate>
		<dc:creator>sghael</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Install]]></category>
		<category><![CDATA[Red5]]></category>
		<category><![CDATA[Ubuntu 9.04]]></category>

		<guid isPermaLink="false">http://sandeepghael.com/?p=3</guid>
		<description><![CDATA[As part of my Rails Rumble team prep, I wanted to document the quickest way to get a Red5 Flash media server up and running on a virtual private server. The Rails Rumble project will actually be using a Linode cloud server, but since I already have a Slicehost account, I did this experimentation on [...]]]></description>
			<content:encoded><![CDATA[<p>As part of my Rails Rumble team prep, I wanted to document the quickest way to get a Red5 Flash media server up and running on a virtual private server.  The Rails Rumble project will actually be using a <a href="http://www.linode.com/">Linode</a> cloud server, but since I already have a <a href="http://slicehost.com">Slicehost</a> account, I did this experimentation on Slicehost.</p>
<ol>
<li>
   	First fire up a new server on Slicehost (even though it&#8217;s not LTS, we&#8217;ll use Ubuntu 9.04). <br />
   	After the server is provisioned, ssh in as root.  For simplicity, I&#8217;ve done this entire<br />
   	exercise as root.  Obviously on a production server, you&#8217;ll want to create the necessary<br />
   	non-root account.<br />
   	<br/>
   </li>
<li>
   	Next let&#8217;s get our server up to date and necessary repos added. <br />
   	If you are already root, you won&#8217;t need the &#8216;sudo&#8217;:<br/><br />
   	<script src="https://gist.github.com/723925.js?file=RED5Ubuntu"></script><br />
	<br/>
   </li>
<li>
   	Add this line to the end of your &#8216;sources.list&#8217; file:<br/><br />
        <script src="https://gist.github.com/723925.js?file=gistfile2.tcsh"></script><br />
	<br/>
   </li>
<li>
	Now run this series of commands from the shell.  This will bring Ubuntu<br />
	up to date with the latest patches, etc.  Also it will install some useful<br />
	shell tools like locate to help you quickly find files on the filesystem. <br/><br />
	<script src="https://gist.github.com/723925.js?file=gistfile3.txt"></script><br />
	<br/>
   </li>
<li>
   	Now install the necessary Java packages and the Ant build tool:<br/><br />
        <script src="https://gist.github.com/723925.js?file=gistfile4.txt"></script><br />
	<br/>
   </li>
<li>
   	After you have run through the install steps, you can test the success of the<br />
   	install by checking where java was installed and which version is recognized:<br/><br />
   	<script src="https://gist.github.com/723925.js?file=gistfile5.txt"></script><br />
	<br/>
   </li>
<li>
   	You can do this as a non-root account, but I built Red5 with Ant from the root account.<br />
   	After the build completes, copy the build output into /usr/share.<br/><br />
  	<script src="https://gist.github.com/723925.js?file=gistfile6.txt"></script><br />
	<br/>
   </li>
<li>
   	Now we can check if Red5 can be brought to life:<br/><br />
   	<script src="https://gist.github.com/723925.js?file=gistfile7.txt"></script><br />
   	<br/><br />
   	We can check with netstat that Red5 is running on the default port of 5080:<br/><br />
   	<script src="https://gist.github.com/723925.js?file=gistfile8.txt"></script><br />
   	<br/><br />
   	And to confirm, connect to port 5080 via telnet:<br/><br />
   	<script src="https://gist.github.com/723925.js?file=gistfile9.txt"></script><br />
   	<br/>
   </li>
<li>
   	Go ahead and cancel out of telnet.  Confirm that the Red5 start page is accessible via a browser by navigating to:<br/><br />
   	http://[yourdomain]:5080/ <br/><br />
   	You should see this Red5 page: <br/><br />
   	<img src="http://sandeepghael.com/wp-content/uploads/2009/07/Red5-The-open-source-media-server_1248399827808.jpg" alt="red 5 start page" style="width:300px;"/><br />
   	<br/>
   </li>
<li>
   	At this point, you can watch the really nice <a href="http://www.youtube.com/watch?v=969cmyGu1yw">YouTube video that the Red5 team has put together</a> which is embedded on this Red5 start page.  It will guide you thru the process of installing a couple of demo applications and then testing them&#8230; Remember when you are testing the demo apps to change the ip address of the server you are connecting to.  If you are using a remote server, it won&#8217;t be &#8216;localhost&#8217; but the ip address of the remote machine.<br/><br/>
   </li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://sandeepghael.com/2009/07/getting-red-5-up-and-running-on-ubuntu-9-04/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
	</channel>
</rss>

