<?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>Matejunkie &#187; HDFS</title>
	<atom:link href="http://www.matejunkie.com/tag/hdfs/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.matejunkie.com</link>
	<description>&#34;Look behind you, a Three-Headed Monkey!&#34;</description>
	<lastBuildDate>Thu, 07 Jan 2010 14:26:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>How to kick off Hadoop&#8217;s rack awareness</title>
		<link>http://www.matejunkie.com/how-to-kick-off-hadoops-rack-awareness/</link>
		<comments>http://www.matejunkie.com/how-to-kick-off-hadoops-rack-awareness/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 22:31:39 +0000</pubDate>
		<dc:creator>Mike Adolphs</dc:creator>
				<category><![CDATA[Binary Talks]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[distributed computing]]></category>
		<category><![CDATA[distributed data storage]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[hadoop]]></category>
		<category><![CDATA[HDFS]]></category>
		<category><![CDATA[namenode]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[rack awareness]]></category>

		<guid isPermaLink="false">http://www.matejunkie.com/?p=1198</guid>
		<description><![CDATA[Hadoop, an Open Source framework for reliable, scalable, distributed computing and data storage, has a nice feature called rack awareness. This means nothing more than that you&#8217;re able to widely spread your Hadoop cluster over multiple machines within different racks and even different data centers that are worlds apart from each other. Sadly this isn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://hadoop.apache.org/" title="Hadoop">Hadoop</a>, an Open Source framework for reliable, scalable, distributed computing and data storage, has a nice feature called rack awareness. This means nothing more than that you&#8217;re able to widely spread your Hadoop cluster over multiple machines within different racks and even different data centers that are worlds apart from each other. Sadly this isn&#8217;t well documented as almost anything regarding Hadoop since it&#8217;s under heavy development and because of the few people that are actually working with Hadoop compared to other huge Open Source projects.</p>
<p style="text-align: left;"><a href="http://www.matejunkie.com/wp-content/uploads/2009/07/hadoop_rack_awareness_example_01.png"><img class="aligncenter size-full wp-image-1199" title="Hadoop - Rack Awareness" src="http://www.matejunkie.com/wp-content/uploads/2009/07/hadoop_rack_awareness_example_01.png" alt="Hadoop - Rack Awareness" width="500" height="337" /></a></p>
<p>Anyway, kicking off Hadoop&#8217;s rack awareness is no big deal in general. Here&#8217;s how to achieve this goal:</p>
<p>Put a small script in whatever language you prefer to a location of your choice which is accessible by the local Hadoop user on the namenode. The only requirement is that the script is able to print a record to stdout. In this example I&#8217;m using a small Python script written <a href="http://www.nabble.com/Re%3A-Hadoop-topology.script.file.name-Form-p22588620.html" title="Nabble - Hadoop Core Users">by Vadim Zaliva</a> stored in the Hadoop user&#8217;s home directory under /home/hadoop:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span>
&nbsp;
<span style="color: #483d8b;">''</span><span style="color: #483d8b;">'
This script used by hadoop to determine network/rack topology.  It
should be specified in hadoop-site.xml via topology.script.file.name
Property.
&nbsp;
 topology.script.file.name
 /home/hadoop/topology.py
&nbsp;
'</span><span style="color: #483d8b;">''</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">string</span> <span style="color: #ff7700;font-weight:bold;">import</span> join
&nbsp;
DEFAULT_RACK = <span style="color: #483d8b;">'/default/rack0'</span><span style="color: #66cc66;">;</span>
&nbsp;
RACK_MAP = <span style="color: black;">&#123;</span> <span style="color: #483d8b;">'10.72.10.1'</span> : <span style="color: #483d8b;">'/datacenter0/rack0'</span>,
&nbsp;
             <span style="color: #483d8b;">'10.112.110.26'</span> : <span style="color: #483d8b;">'/datacenter1/rack0'</span>,
             <span style="color: #483d8b;">'10.112.110.27'</span> : <span style="color: #483d8b;">'/datacenter1/rack0'</span>,
             <span style="color: #483d8b;">'10.112.110.28'</span> : <span style="color: #483d8b;">'/datacenter1/rack0'</span>,
&nbsp;
             <span style="color: #483d8b;">'10.2.5.1'</span> : <span style="color: #483d8b;">'/datacenter2/rack0'</span>,
             <span style="color: #483d8b;">'10.2.10.1'</span> : <span style="color: #483d8b;">'/datacenter2/rack1'</span>
    <span style="color: black;">&#125;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#41;</span>==<span style="color: #ff4500;">1</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> DEFAULT_RACK
<span style="color: #ff7700;font-weight:bold;">else</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> join<span style="color: black;">&#40;</span><span style="color: black;">&#91;</span>RACK_MAP.<span style="color: black;">get</span><span style="color: black;">&#40;</span>i, DEFAULT_RACK<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span>:<span style="color: black;">&#93;</span><span style="color: black;">&#93;</span>,<span style="color: #483d8b;">&quot; &quot;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Then you need to add a property directive to the hadoop-site.xml you&#8217;re using for your cluster&#8217;s configuration (delete all leading underscores in the tags, this is just for display purposes):</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>topology.script.file.name<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/home/hadoop/topology.py<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Simply restart the namenode&#8217;s process and from now on the Namenode runs the script and looks for a record regarding the datanode everytime a new datanode tries to participate in the cluster.<br />
Keep in mind that taking care of connections between multiple locations via VPN or else and proper DNS resolution is your business and not Hadoop&#8217;s. Make sure that resolving the datanode&#8217;s DNS record is possible and that it&#8217;s accessible within your Hadoop environment.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matejunkie.com/how-to-kick-off-hadoops-rack-awareness/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Hadoop DFS Check Plugin for Nagios</title>
		<link>http://www.matejunkie.com/hadoop-dfs-check-plugin-for-nagios/</link>
		<comments>http://www.matejunkie.com/hadoop-dfs-check-plugin-for-nagios/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 22:46:45 +0000</pubDate>
		<dc:creator>Mike Adolphs</dc:creator>
				<category><![CDATA[Binary Talks]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[gplv2]]></category>
		<category><![CDATA[hadoop]]></category>
		<category><![CDATA[HDFS]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[nagios]]></category>
		<category><![CDATA[network monitoring]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[shell scripting]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[yahoo]]></category>

		<guid isPermaLink="false">http://www.matejunkie.com/?p=1110</guid>
		<description><![CDATA[Since I&#8217;m currently occupied with kicking off a several terabytes large Hadoop cluster I thought it&#8217;d be a good idea to provide a few Nagios plugins related to Hadoop. Just in case you don&#8217;t know: Hadoop is a free Java software framework that supports data intensive distributed applications. It got its own filesystem called HDFS [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-193" title="logo_nagios" src="http://www.matejunkie.com/wp-content/uploads/2008/05/logo_nagios.gif" alt="logo_nagios" width="150" height="40" />Since I&#8217;m currently occupied with kicking off a several terabytes large Hadoop cluster I thought it&#8217;d be a good idea to provide a few Nagios plugins related to Hadoop.</p>
<p>Just in case you don&#8217;t know: Hadoop is a <a title="Wikipedia - Hadoop" href="http://en.wikipedia.org/wiki/Hadoop" target="_blank">free Java software framework</a> that supports data intensive distributed applications. It got its own filesystem called HDFS which scales up to petabytes of storage running on top of the operating system&#8217;s filesystem. Hadoop is inspired by Google&#8217;s MapReduce and GFS, the Google File System.</p>
<p>Yahoo for example uses several Hadoop Clusters with <strong>100.000 CPUs total in 20.000 boxes</strong> (2.000 boxes per cluster) according to the <a title="Hadoop website" href="http://wiki.apache.org/hadoop/PoweredBy" target="_blank">official Hadoop website</a>. If you haven&#8217;t checked it out yet, do so! This is &#8211; sorry for that &#8211; crazy shit and it&#8217;s working!<br />
For the beginning I&#8217;d recommend reading the <a title="Wikipedia - Hadoop" href="http://en.wikipedia.org/wiki/Hadoop" target="_blank">Wikipedia article</a>, the <a title="Hadoop - Official documentation 0.18.3" href="http://hadoop.apache.org/core/docs/r0.18.3/" target="_blank">offical documentation</a> and, of course, watching the Hadoop related lectures over <a title="Cloudera" href="http://www.cloudera.com/" target="_blank">at Cloudera</a>.</p>
<p>Anyway, the first plugin is almost finished and checks the amount of running DataNodes and the capacity of the DFS. It&#8217;s working, but I want to add a few more features so that the plugin become more flexible. Nevertheless, feel free to give it a try if you&#8217;re in the mood.</p>
<h3>The Script</h3>
<p>Hadoop is completely operated by the hadoop user and since it got its own filesystem it got its own permissions as well. To keep things clean and safe we won&#8217;t give hadoop related permissions to the Nagios user. We&#8217;ll rather enable the Nagios user to run a small shell script as root which contains a command ran by the hadoop user to get information about the cluster.</p>
<p>Add the following small script to a directory of your choice, e.g. /usr/local/sbin:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #c20cb9; font-weight: bold;">su</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">bash</span> - hadoop <span style="color: #660033;">-c</span> <span style="color: #ff0000;">'hadoop dfsadmin -report'</span></pre></div></div>

<p>Afterwards alter its permissions so that it&#8217;s only read-, write and accessible by root:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">700</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>get-dfsreport.sh</pre></div></div>

<p>Then enable the Nagios user to sudo run the script via /etc/sudoers (or better visudo):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">nagios          <span style="color: #007800;">ALL</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span>ALL<span style="color: #7a0874; font-weight: bold;">&#41;</span>       NOPASSWD: <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>get-dfsreport.sh</pre></div></div>

<p>This is it for the prerequisites. You may then run the script provided for copy&#8217;n'pasting below (or svn co, your choice).<br />
If you&#8217;ve chosen another directory than /usr/local/sbin you have to provide the path via -s/&#8211;path-sh when running the script.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ <span style="color: #c20cb9; font-weight: bold;">svn</span> <span style="color: #c20cb9; font-weight: bold;">co</span> <span style="color: #c20cb9; font-weight: bold;">svn</span>:<span style="color: #000000; font-weight: bold;">//</span>svn.matejunkie.com<span style="color: #000000; font-weight: bold;">/</span>nagios-plugins<span style="color: #000000; font-weight: bold;">/</span>stable<span style="color: #000000; font-weight: bold;">/</span>check_hadoop-dfs<span style="color: #000000; font-weight: bold;">/</span> check_hadoop-dfs<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#   This program is free software; you can redistribute it and/or modify</span>
<span style="color: #666666; font-style: italic;">#   it under the terms of the GNU General Public License as published by</span>
<span style="color: #666666; font-style: italic;">#   the Free Software Foundation; either version 2 of the License, or</span>
<span style="color: #666666; font-style: italic;">#   (at your option) any later version.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#   This program is distributed in the hope that it will be useful,</span>
<span style="color: #666666; font-style: italic;">#   but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span style="color: #666666; font-style: italic;">#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<span style="color: #666666; font-style: italic;">#   GNU General Public License for more details.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#   You should have received a copy of the GNU General Public License</span>
<span style="color: #666666; font-style: italic;">#   along with this program; if not, write to the Free Software</span>
<span style="color: #666666; font-style: italic;">#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA</span>
&nbsp;
<span style="color: #007800;">PROGNAME</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">basename</span> $<span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">VERSION</span>=<span style="color: #ff0000;">&quot;Version 1.0,&quot;</span>
<span style="color: #007800;">AUTHOR</span>=<span style="color: #ff0000;">&quot;2009, Mike Adolphs (http://www.matejunkie.com/)&quot;</span>
&nbsp;
<span style="color: #007800;">ST_OK</span>=<span style="color: #000000;">0</span>
<span style="color: #007800;">ST_WR</span>=<span style="color: #000000;">1</span>
<span style="color: #007800;">ST_CR</span>=<span style="color: #000000;">2</span>
<span style="color: #007800;">ST_UK</span>=<span style="color: #000000;">3</span>
&nbsp;
<span style="color: #007800;">path_sh</span>=<span style="color: #ff0000;">&quot;/usr/local/sbin&quot;</span>
&nbsp;
print_version<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$VERSION</span> <span style="color: #007800;">$AUTHOR</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
print_help<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    print_version <span style="color: #007800;">$PROGNAME</span> <span style="color: #007800;">$VERSION</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$PROGNAME</span> is a Nagios plugin to check the status of HDFS, Hadoop's&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;underlying, redundant, distributed file system.&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$PROGNAME</span> -s /usr/local/sbin [-w 10] [-c 5]&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Options:&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -s|--path-sh)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Path to the shell script that is mentioned in the&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     documentation. Default is: /usr/local/sbin&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -w|--warning)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Defines the warning level for available datanodes. Default&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     is: off&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -c|--critical)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Defines the critical level for available datanodes. Default&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     is: off&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;$1&quot;</span>; <span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
        -help<span style="color: #000000; font-weight: bold;">|</span>-h<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            print_help
            <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --version<span style="color: #000000; font-weight: bold;">|</span>-v<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            print_version <span style="color: #007800;">$PROGNAME</span> <span style="color: #007800;">$VERSION</span>
            <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --path-sh<span style="color: #000000; font-weight: bold;">|</span>-s<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">path_sh</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --warning<span style="color: #000000; font-weight: bold;">|</span>-w<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">warning</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --critical<span style="color: #000000; font-weight: bold;">|</span>-c<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">critical</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Unknown argument: $1&quot;</span>
            print_help
            <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        <span style="color: #000000; font-weight: bold;">esac</span>
    <span style="color: #7a0874; font-weight: bold;">shift</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
get_wcdiff<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warning</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$critical</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">wclvls</span>=<span style="color: #000000;">1</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #800000;">${warning}</span> <span style="color: #660033;">-lt</span> <span style="color: #800000;">${critical}</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
        <span style="color: #000000; font-weight: bold;">then</span>
            <span style="color: #007800;">wcdiff</span>=<span style="color: #000000;">1</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
    <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warning</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$critical</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">wcdiff</span>=<span style="color: #000000;">2</span>
    <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warning</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$critical</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">wcdiff</span>=<span style="color: #000000;">3</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
val_wcdiff<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$wcdiff</span>&quot;</span> = <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Please adjust your warning/critical thresholds. The warning <span style="color: #000099; font-weight: bold;">\
</span>must be higher than the critical level!&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
    <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$wcdiff</span>&quot;</span> = <span style="color: #000000;">2</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Please also set a critical value when you want to use <span style="color: #000099; font-weight: bold;">\
</span>warning/critical thresholds!&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
    <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$wcdiff</span>&quot;</span> = <span style="color: #000000;">3</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Please also set a warning value when you want to use <span style="color: #000099; font-weight: bold;">\
</span>warning/critical thresholds!&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
get_vals<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #007800;">tmp_vals</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #800000;">${path_sh}</span><span style="color: #000000; font-weight: bold;">/</span>get-dfsreport.sh<span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">dn_avail</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$tmp_vals</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">&quot;Datanodes available:&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $3}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">dfs_used</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$tmp_vals</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">&quot;Used raw bytes:&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $4}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">dfs_used</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #800000;">${dfs_used}</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000;">1024</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000;">1024</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">dfs_used_p</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$tmp_vals</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">&quot;% used:&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $3}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">dfs_total</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$tmp_vals</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">&quot;Total raw bytes:&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $4}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">dfs_total</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #800000;">${dfs_total}</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000;">1024</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000;">1024</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
do_output<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #007800;">output</span>=<span style="color: #ff0000;">&quot;Datanodes up and running: <span style="color: #007800;">${dn_avail}</span>, DFS total: <span style="color: #000099; font-weight: bold;">\
</span><span style="color: #007800;">${dfs_total}</span> MB, DFS used: <span style="color: #007800;">${dfs_used}</span> MB (<span style="color: #007800;">${dfs_used_p}</span>)&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
do_perfdata<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #007800;">perfdata</span>=<span style="color: #ff0000;">&quot;'datanodes_available'=<span style="color: #007800;">${dn_avail}</span> 'dfs_total'=<span style="color: #007800;">${dfs_total}</span> <span style="color: #000099; font-weight: bold;">\
</span>'dfs_used'=<span style="color: #007800;">${dfs_used}</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Here we go!</span>
get_wcdiff
val_wcdiff
&nbsp;
get_vals
&nbsp;
do_output
do_perfdata
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warning</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$critical</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$dn_avail</span>&quot;</span> <span style="color: #660033;">-le</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warning</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$dn_avail</span>&quot;</span> <span style="color: #660033;">-gt</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$critical</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;WARNING - <span style="color: #007800;">${output}</span> | <span style="color: #007800;">${perfdata}</span>&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_WR</span>
    <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$dn_avail</span>&quot;</span> <span style="color: #660033;">-le</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$critical</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;CRITICAL - <span style="color: #007800;">${output}</span> | <span style="color: #007800;">${perfdata}</span>&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_CR</span>
    <span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;OK - <span style="color: #007800;">${output}</span> | <span style="color: #007800;">${perfdata}</span> &quot;</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_OK</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">else</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;OK - <span style="color: #007800;">${output}</span> | <span style="color: #007800;">${perfdata}</span>&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_OK</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<h3>Output example:</h3>
<p>If everything went fine you should see output like the following:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ .<span style="color: #000000; font-weight: bold;">/</span>check_hadoop-dfs.sh <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>nagios<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>bin
OK - Datanodes up and running: <span style="color: #000000;">50</span>, DFS total: <span style="color: #000000;">20147365</span> MB, DFS used: <span style="color: #000000;">0</span> MB <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">%</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #ff0000;">'datanodes_available'</span>=<span style="color: #000000;">50</span> <span style="color: #ff0000;">'dfs_total'</span>=<span style="color: #000000;">20147365</span> <span style="color: #ff0000;">'dfs_used'</span>=<span style="color: #000000;">0</span>
user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ .<span style="color: #000000; font-weight: bold;">/</span>check_hadoop-dfs.sh <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>nagios<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>bin <span style="color: #660033;">-w</span> <span style="color: #000000;">40</span> <span style="color: #660033;">-c</span> <span style="color: #000000;">30</span>
OK - Datanodes up and running: <span style="color: #000000;">50</span>, DFS total: <span style="color: #000000;">20147365</span> MB, DFS used: <span style="color: #000000;">0</span> MB <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">%</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #ff0000;">'datanodes_available'</span>=<span style="color: #000000;">50</span> <span style="color: #ff0000;">'dfs_total'</span>=<span style="color: #000000;">20147365</span> <span style="color: #ff0000;">'dfs_used'</span>=<span style="color: #000000;">0</span>
user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ .<span style="color: #000000; font-weight: bold;">/</span>check_hadoop-dfs.sh <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>nagios<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>bin <span style="color: #660033;">-w</span> <span style="color: #000000;">60</span> <span style="color: #660033;">-c</span> <span style="color: #000000;">40</span>
WARNING - Datanodes up and running: <span style="color: #000000;">50</span>, DFS total: <span style="color: #000000;">20147365</span> MB, DFS used: <span style="color: #000000;">0</span> MB <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">%</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #ff0000;">'datanodes_available'</span>=<span style="color: #000000;">50</span> <span style="color: #ff0000;">'dfs_total'</span>=<span style="color: #000000;">20147365</span> <span style="color: #ff0000;">'dfs_used'</span>=<span style="color: #000000;">0</span>
user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ .<span style="color: #000000; font-weight: bold;">/</span>check_hadoop-dfs.sh <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>nagios<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>bin <span style="color: #660033;">-w</span> <span style="color: #000000;">70</span>-c <span style="color: #000000;">60</span>
CRITICAL - Datanodes up and running: <span style="color: #000000;">50</span>, DFS total: <span style="color: #000000;">20147365</span> MB, DFS used: <span style="color: #000000;">0</span> MB <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">%</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #ff0000;">'datanodes_available'</span>=<span style="color: #000000;">50</span> <span style="color: #ff0000;">'dfs_total'</span>=<span style="color: #000000;">20147365</span> <span style="color: #ff0000;">'dfs_used'</span>=<span style="color: #000000;">0</span>
user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ .<span style="color: #000000; font-weight: bold;">/</span>check_hadoop-dfs.sh <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>nagios<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>bin <span style="color: #660033;">-w</span> <span style="color: #000000;">20</span> <span style="color: #660033;">-c</span> <span style="color: #000000;">40</span>
Please adjust your warning<span style="color: #000000; font-weight: bold;">/</span>critical thresholds. The warning must be higher than the critical level<span style="color: #000000; font-weight: bold;">!</span>
user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ .<span style="color: #000000; font-weight: bold;">/</span>check_hadoop-dfs.sh <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>nagios<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>bin <span style="color: #660033;">-w</span> <span style="color: #000000;">30</span>
Please also <span style="color: #000000; font-weight: bold;">set</span> a critical value when you want to use warning<span style="color: #000000; font-weight: bold;">/</span>critical thresholds<span style="color: #000000; font-weight: bold;">!</span>
user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ .<span style="color: #000000; font-weight: bold;">/</span>check_hadoop-dfs.sh <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>nagios<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>bin <span style="color: #660033;">-c</span> <span style="color: #000000;">30</span>
Please also <span style="color: #000000; font-weight: bold;">set</span> a warning value when you want to use warning<span style="color: #000000; font-weight: bold;">/</span>critical thresholds<span style="color: #000000; font-weight: bold;">!</span></pre></div></div>

<h3>The License</h3>
<p>As always this little script is ment to be sh-compliant and released under the terms of the GPL Version 2 only. Feel free to subscribe via rss to get updates on this one. More options will be added in the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matejunkie.com/hadoop-dfs-check-plugin-for-nagios/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
