<?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>satishgaudo.com &#187; Uncategorized</title>
	<atom:link href="http://satishgaudo.com/satblog/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://satishgaudo.com/satblog</link>
	<description>Understanding technology</description>
	<lastBuildDate>Sat, 19 Nov 2011 08:13:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Google Maps JavaScript API v3 Example</title>
		<link>http://satishgaudo.com/satblog/2011/11/02/google-maps-javascript-api-v3-example/</link>
		<comments>http://satishgaudo.com/satblog/2011/11/02/google-maps-javascript-api-v3-example/#comments</comments>
		<pubDate>Wed, 02 Nov 2011 11:09:26 +0000</pubDate>
		<dc:creator>satishgaudo</dc:creator>
				<category><![CDATA[Technology updates]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Google Maps]]></category>
		<category><![CDATA[Google Maps JavaScript API v3]]></category>
		<category><![CDATA[Google Maps JavaScript API v3 Example]]></category>

		<guid isPermaLink="false">http://satishgaudo.com/satblog/?p=331</guid>
		<description><![CDATA[
			
				
			
		

&#160;
&#60;!DOCTYPE html PUBLIC &#34;-//W3C//DTD XHTML 1.0 Transitional//EN&#34; &#34;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&#34;&#62;
&#60;html xmlns=&#34;http://www.w3.org/1999/xhtml&#34;&#62;
&#60;head runat=&#34;server&#34;&#62;
    &#60;meta name=&#34;viewport&#34; content=&#34;initial-scale=1.0, user-scalable=no&#34; /&#62;
    &#60;meta http-equiv=&#34;content-type&#34; content=&#34;text/html; charset=UTF-8&#34; /&#62;
    &#60;style type=&#34;text/css&#34;&#62;
        html
        &#123;
         [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fsatishgaudo.com%2Fsatblog%2F2011%2F11%2F02%2Fgoogle-maps-javascript-api-v3-example%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fsatishgaudo.com%2Fsatblog%2F2011%2F11%2F02%2Fgoogle-maps-javascript-api-v3-example%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #339933;">&lt;!</span>DOCTYPE html <span style="color: #000000; font-weight: bold;">PUBLIC</span> <span style="color: #0000ff;">&quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;</span> <span style="color: #0000ff;">&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>html xmlns<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.w3.org/1999/xhtml&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>head runat<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;server&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>meta name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;viewport&quot;</span> content<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;initial-scale=1.0, user-scalable=no&quot;</span> <span style="color: #339933;">/&gt;</span>
    <span style="color: #339933;">&lt;</span>meta http<span style="color: #339933;">-</span>equiv<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;content-type&quot;</span> content<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=UTF-8&quot;</span> <span style="color: #339933;">/&gt;</span>
    <span style="color: #339933;">&lt;</span>style type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/css&quot;</span><span style="color: #339933;">&gt;</span>
        html
        <span style="color: #009900;">&#123;</span>
            height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">%;</span>
        <span style="color: #009900;">&#125;</span>
        body
        <span style="color: #009900;">&#123;</span>
            height<span style="color: #339933;">:</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">%;</span>
            margin<span style="color: #339933;">:</span> <span style="color: #cc66cc;">0</span> auto<span style="color: #339933;">;</span>
            padding<span style="color: #339933;">:</span> 0px 250px<span style="color: #339933;">;</span>
            text<span style="color: #339933;">-</span>align<span style="color: #339933;">:</span>center<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #339933;">&lt;/</span>style<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;</span>Google Maps JavaScript API v3 Example<span style="color: #339933;">&lt;/</span>title<span style="color: #339933;">&gt;</span>
&nbsp;
    <span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://maps.google.com/maps/api/js?sensor=false&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
&nbsp;
    <span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
        <span style="color: #000000; font-weight: bold;">var</span> geocoder<span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">var</span> map<span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">var</span> markersArray <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">var</span> marker<span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">var</span> infowindow <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> google<span style="color: #339933;">.</span>maps<span style="color: #339933;">.</span>InfoWindow<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">var</span> address <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;153, Second Floor, Raghuleela Mall, Opposite Vashi Railway Station, Vashi Plaza, Vashi, Navi Mumbai,India&quot;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">function</span> initializeMap<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            geocoder <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> google<span style="color: #339933;">.</span>maps<span style="color: #339933;">.</span>Geocoder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">var</span> myOptions <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
            zoom<span style="color: #339933;">:</span> <span style="color: #cc66cc;">8</span><span style="color: #339933;">,</span>
                mapTypeId<span style="color: #339933;">:</span> google<span style="color: #339933;">.</span>maps<span style="color: #339933;">.</span>MapTypeId<span style="color: #339933;">.</span>ROADMAP
            <span style="color: #009900;">&#125;</span>
            map <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> google<span style="color: #339933;">.</span>maps<span style="color: #339933;">.</span>Map<span style="color: #009900;">&#40;</span>document<span style="color: #339933;">.</span>getElementById<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;map_canvas&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> myOptions<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            codeAddressMap<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            google<span style="color: #339933;">.</span>maps<span style="color: #339933;">.</span>event<span style="color: #339933;">.</span>addListener<span style="color: #009900;">&#40;</span>map<span style="color: #339933;">,</span> <span style="color: #0000ff;">'click'</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
                placeMarker<span style="color: #009900;">&#40;</span>event<span style="color: #339933;">.</span>latLng<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">function</span> codeAddressMap<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            geocoder<span style="color: #339933;">.</span>geocode<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">'address'</span><span style="color: #339933;">:</span> address <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>results<span style="color: #339933;">,</span> status<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>status <span style="color: #339933;">==</span> google<span style="color: #339933;">.</span>maps<span style="color: #339933;">.</span>GeocoderStatus<span style="color: #339933;">.</span>OK<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    clearOverlaysMap<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    map<span style="color: #339933;">.</span>setCenter<span style="color: #009900;">&#40;</span>results<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span>geometry<span style="color: #339933;">.</span>location<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    marker <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> google<span style="color: #339933;">.</span>maps<span style="color: #339933;">.</span>Marker<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
                        map<span style="color: #339933;">:</span> map<span style="color: #339933;">,</span>
                        title<span style="color: #339933;">:</span> results<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'formatted_address'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
                        position<span style="color: #339933;">:</span> results<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span>geometry<span style="color: #339933;">.</span>location<span style="color: #339933;">,</span>
                        animation<span style="color: #339933;">:</span> google<span style="color: #339933;">.</span>maps<span style="color: #339933;">.</span>Animation<span style="color: #339933;">.</span>DROP
                    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>results<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span>undefined<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
						infowindow<span style="color: #339933;">.</span>setContent<span style="color: #009900;">&#40;</span>results<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span>formatted_address<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						infowindow<span style="color: #339933;">.</span>open<span style="color: #009900;">&#40;</span>map<span style="color: #339933;">,</span> marker<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						markersArray<span style="color: #339933;">.</span>push<span style="color: #009900;">&#40;</span>marker<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span>	
&nbsp;
                <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                    alert<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Geocode was not successful for the following reason: &quot;</span> <span style="color: #339933;">+</span> status<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">function</span> placeMarker<span style="color: #009900;">&#40;</span>location<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            geocoder<span style="color: #339933;">.</span>geocode<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">'latLng'</span><span style="color: #339933;">:</span> location <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>results<span style="color: #339933;">,</span> status<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>status <span style="color: #339933;">==</span> google<span style="color: #339933;">.</span>maps<span style="color: #339933;">.</span>GeocoderStatus<span style="color: #339933;">.</span>OK<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>results<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        clearOverlaysMap<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>					
                        marker <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> google<span style="color: #339933;">.</span>maps<span style="color: #339933;">.</span>Marker<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
                            position<span style="color: #339933;">:</span> location<span style="color: #339933;">,</span>
                            title<span style="color: #339933;">:</span> results<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span>formatted_address<span style="color: #339933;">,</span>
                            map<span style="color: #339933;">:</span> map<span style="color: #339933;">,</span>
                            animation<span style="color: #339933;">:</span> google<span style="color: #339933;">.</span>maps<span style="color: #339933;">.</span>Animation<span style="color: #339933;">.</span>DROP
                        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        infowindow<span style="color: #339933;">.</span>setContent<span style="color: #009900;">&#40;</span>results<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span>formatted_address<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        infowindow<span style="color: #339933;">.</span>open<span style="color: #009900;">&#40;</span>map<span style="color: #339933;">,</span> marker<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                        markersArray<span style="color: #339933;">.</span>push<span style="color: #009900;">&#40;</span>marker<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                        google<span style="color: #339933;">.</span>maps<span style="color: #339933;">.</span>event<span style="color: #339933;">.</span>addListener<span style="color: #009900;">&#40;</span>marker<span style="color: #339933;">,</span> <span style="color: #0000ff;">'click'</span><span style="color: #339933;">,</span> toggleBounceMap<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                        map<span style="color: #339933;">.</span>setCenter<span style="color: #009900;">&#40;</span>location<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                    alert<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Geocoder failed due to: &quot;</span> <span style="color: #339933;">+</span> status<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">function</span> clearOverlaysMap<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>markersArray<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i in markersArray<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    markersArray<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span>setMap<span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">function</span> toggleBounceMap<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>marker<span style="color: #339933;">.</span>getAnimation<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                marker<span style="color: #339933;">.</span>setAnimation<span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                marker<span style="color: #339933;">.</span>setAnimation<span style="color: #009900;">&#40;</span>google<span style="color: #339933;">.</span>maps<span style="color: #339933;">.</span>Animation<span style="color: #339933;">.</span>BOUNCE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span>
<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>body onload<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;initializeMap()&quot;</span> <span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>table width<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;800px&quot;</span> cellpadding<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;0&quot;</span> cellspacing<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;0&quot;</span> border<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;0&quot;</span><span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
            <span style="color: #339933;">&lt;</span>td colspan<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;2&quot;</span> align<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;center&quot;</span><span style="color: #339933;">&gt;</span>
                <span style="color: #339933;">&lt;</span>h2<span style="color: #339933;">&gt;</span>Map My Address<span style="color: #339933;">&lt;/</span>h2<span style="color: #339933;">&gt;</span>
&nbsp;
            <span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
            <span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span>
                <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;map_canvas&quot;</span> style<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;height:300px; width:300px;&quot;</span> <span style="color: #339933;">&gt;</span>
&nbsp;
                <span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
            <span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>table<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://satishgaudo.com/satblog/2011/11/02/google-maps-javascript-api-v3-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perl Batch convertion script for ffmpeg , to make flash video (flv) from several other videosources</title>
		<link>http://satishgaudo.com/satblog/2011/05/04/perl-batch-convertion-script-for-ffmpeg-to-make-flash-video-flv-from-several-other-videosources/</link>
		<comments>http://satishgaudo.com/satblog/2011/05/04/perl-batch-convertion-script-for-ffmpeg-to-make-flash-video-flv-from-several-other-videosources/#comments</comments>
		<pubDate>Wed, 04 May 2011 11:05:31 +0000</pubDate>
		<dc:creator>satishgaudo</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[ffmpeg]]></category>
		<category><![CDATA[Perl Batch convertion script for ffmpeg]]></category>
		<category><![CDATA[to make flash video (flv) from several other videosources]]></category>

		<guid isPermaLink="false">http://satishgaudo.com/satblog/?p=290</guid>
		<description><![CDATA[
			
				
			
		

#!/usr/bin/perl
use strict;
&#160;
# Very crude batch convertion script for ffmpeg
# to make flash video (flv) from several other videosources
#
# First get the ffmpeg CVS version
# cvs -z9 -d:pserver:anonymous@mplayerhq.hu:/cvsroot/ffmpeg co ffmpeg
#
# compile it with:
# ./configure --enable-mp3lame --enable-gpl
# make
# make install
#
# next:
# make them flv files ;)

# input movie files dirname
my $input_dir = &#34;/var/www/uploads/dummymedia/&#34;;
&#160;
# output files dirname
# has [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fsatishgaudo.com%2Fsatblog%2F2011%2F05%2F04%2Fperl-batch-convertion-script-for-ffmpeg-to-make-flash-video-flv-from-several-other-videosources%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fsatishgaudo.com%2Fsatblog%2F2011%2F05%2F04%2Fperl-batch-convertion-script-for-ffmpeg-to-make-flash-video-flv-from-several-other-videosources%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl
</span>use strict<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Very crude batch convertion script for ffmpeg
</span><span style="color: #666666; font-style: italic;"># to make flash video (flv) from several other videosources
</span><span style="color: #666666; font-style: italic;">#
</span><span style="color: #666666; font-style: italic;"># First get the ffmpeg CVS version
</span><span style="color: #666666; font-style: italic;"># cvs -z9 -d:pserver:anonymous@mplayerhq.hu:/cvsroot/ffmpeg co ffmpeg
</span><span style="color: #666666; font-style: italic;">#
</span><span style="color: #666666; font-style: italic;"># compile it with:
</span><span style="color: #666666; font-style: italic;"># ./configure --enable-mp3lame --enable-gpl
</span><span style="color: #666666; font-style: italic;"># make
</span><span style="color: #666666; font-style: italic;"># make install
</span><span style="color: #666666; font-style: italic;">#
</span><span style="color: #666666; font-style: italic;"># next:
</span><span style="color: #666666; font-style: italic;"># make them flv files ;)
</span>
<span style="color: #666666; font-style: italic;"># input movie files dirname
</span>my <span style="color: #000088;">$input_dir</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/var/www/uploads/dummymedia/&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># output files dirname
</span><span style="color: #666666; font-style: italic;"># has to exist
</span>my <span style="color: #000088;">$output_dir</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/var/www/converted/&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># bit rate of audio (valid vaues are 16,32,64)
</span>my <span style="color: #000088;">$bitrate</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">81920</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># sampling rate (valid values are 11025, 22050, 44100)
</span>my <span style="color: #000088;">$samprate</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">44100</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># open input dir and get moviefile names
</span><span style="color: #990000;">opendir</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">DIR</span><span style="color: #339933;">,</span> <span style="color: #000088;">$input_dir</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #990000;">die</span> <span style="color: #0000ff;">&quot;Can't open dir <span style="color: #006699; font-weight: bold;">$input_dir</span>: $!&quot;</span><span style="color: #339933;">;</span>
my <span style="color: #339933;">@</span>movies <span style="color: #339933;">=</span> grep <span style="color: #009900;">&#123;</span> <span style="color: #339933;">/</span>\<span style="color: #339933;">.</span>asf<span style="color: #339933;">|</span>\<span style="color: #339933;">.</span>mov<span style="color: #339933;">|</span>\<span style="color: #339933;">.</span>mpg<span style="color: #339933;">|</span>\<span style="color: #339933;">.</span>mpeg<span style="color: #339933;">|</span>\<span style="color: #339933;">.</span>avi<span style="color: #339933;">|</span>\<span style="color: #339933;">.</span>wmv<span style="color: #339933;">/</span> <span style="color: #009900;">&#125;</span> <span style="color: #990000;">readdir</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">DIR</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">closedir</span> <span style="color: #990000;">DIR</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># get the filenames
</span>my <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$movie</span><span style="color: #339933;">,</span> <span style="color: #000088;">$filename</span><span style="color: #339933;">,</span> <span style="color: #000088;">$size</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
use <span style="color: #990000;">File</span><span style="color: #339933;">::</span><span style="color: #990000;">Basename</span><span style="color: #339933;">;</span>    
&nbsp;
<span style="color: #b1b100;">foreach</span> <span style="color: #000088;">$movie</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span>movies<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
 <span style="color: #666666; font-style: italic;"># copy the full name
</span> <span style="color: #000088;">$filename</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$movie</span><span style="color: #339933;">;</span>
&nbsp;
 my<span style="color: #009900;">&#40;</span>undef<span style="color: #339933;">,</span> undef<span style="color: #339933;">,</span> <span style="color: #000088;">$ftype</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> fileparse<span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #339933;">,</span>qr<span style="color: #009900;">&#123;</span>\<span style="color: #339933;">..*</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;[<span style="color: #006699; font-weight: bold;">$ftype</span>]&amp;lt;br&amp;gt;&quot;</span><span style="color: #339933;">;</span>
 my <span style="color: #000088;">$pos</span> <span style="color: #339933;">=</span> index<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ftype</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'mpg'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pos</span><span style="color: #339933;">==</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
 <span style="color: #666666; font-style: italic;"># drop extensions
</span> <span style="color: #000088;">$filename</span> <span style="color: #339933;">=</span>~ s<span style="color: #339933;">/</span>\<span style="color: #339933;">.</span>asf<span style="color: #339933;">|</span>\<span style="color: #339933;">.</span>mpg<span style="color: #339933;">|</span>\<span style="color: #339933;">.</span>mpeg<span style="color: #339933;">|</span>\<span style="color: #339933;">.</span>avi<span style="color: #339933;">|</span>\<span style="color: #339933;">.</span>wmv<span style="color: #666666; font-style: italic;">//gi;</span>
&nbsp;
 <span style="color: #666666; font-style: italic;"># transcode the moviefile
</span> <span style="color: #666666; font-style: italic;"># -y overwrite previous file
</span> <span style="color: #666666; font-style: italic;"># -hq highquality
</span> <span style="color: #666666; font-style: italic;"># -f fileformat
</span> <span style="color: #666666; font-style: italic;"># -s size of output
</span> <span style="color: #666666; font-style: italic;"># -aspect aspectratio (duh)
</span> <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>transcoding <span style="color: #006699; font-weight: bold;">$movie</span> -  <span style="color: #006699; font-weight: bold;">$filename</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>ffmpeg -i <span style="color: #006699; font-weight: bold;">$input_dir</span><span style="color: #006699; font-weight: bold;">$movie</span> -acodec libmp3lame -ar <span style="color: #006699; font-weight: bold;">$samprate</span> -ab <span style="color: #006699; font-weight: bold;">$bitrate</span> -b 524288 -f flv -s 352x288 -y <span style="color: #006699; font-weight: bold;">$output_dir</span><span style="color: #006699; font-weight: bold;">$filename</span>.flv&quot;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #990000;">system</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ffmpeg -i <span style="color: #006699; font-weight: bold;">$input_dir</span><span style="color: #006699; font-weight: bold;">$movie</span> -acodec libmp3lame -ar <span style="color: #006699; font-weight: bold;">$samprate</span> -ab <span style="color: #006699; font-weight: bold;">$bitrate</span> -b 524288 -f flv -s 352x288 -y <span style="color: #006699; font-weight: bold;">$output_dir</span><span style="color: #006699; font-weight: bold;">$filename</span>.flv&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #666666; font-style: italic;">## optional, just delete these if you don't want it
</span> <span style="color: #666666; font-style: italic;"># check file and make thumbnail
</span>
 <span style="color: #666666; font-style: italic;"># get the size of new flv file
</span> <span style="color: #000088;">$size</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">stat</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$output_dir</span><span style="color: #006699; font-weight: bold;">$filename</span>.flv&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">7</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
 <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;Size of <span style="color: #006699; font-weight: bold;">$output_dir</span><span style="color: #006699; font-weight: bold;">$filename</span>.flv = <span style="color: #006699; font-weight: bold;">$size</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #666666; font-style: italic;"># now delete bad converted files
</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$size</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;=</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
 <span style="color: #b1b100;">print</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>OOPS, <span style="color: #006699; font-weight: bold;">$filename</span>.flv is broken<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #990000;">unlink</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$output_dir</span><span style="color: #006699; font-weight: bold;">$filename</span>.flv&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
&nbsp;
 <span style="color: #666666; font-style: italic;"># create preview JPG
</span> <span style="color: #666666; font-style: italic;"># -itsoffset sets the time where capture should take place
</span> <span style="color: #666666; font-style: italic;"># so in this example after 6 seconds in the movie
</span> <span style="color: #990000;">system</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ffmpeg -i <span style="color: #006699; font-weight: bold;">$output_dir</span><span style="color: #006699; font-weight: bold;">$filename</span>.flv -an -itsoffset 00:00:06 -ss 00:00:10 -t 00:00:01 -r 1 -y <span style="color: #006699; font-weight: bold;">$output_dir</span><span style="color: #006699; font-weight: bold;">$filename</span><span style="color: #009933; font-weight: bold;">%d</span>.jpg&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
&nbsp;
 <span style="color: #666666; font-style: italic;"># end of optional check file
</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://satishgaudo.com/satblog/2011/05/04/perl-batch-convertion-script-for-ffmpeg-to-make-flash-video-flv-from-several-other-videosources/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Ganglia : monitoring framework</title>
		<link>http://satishgaudo.com/satblog/2010/07/30/ganglia-monitoring-framework/</link>
		<comments>http://satishgaudo.com/satblog/2010/07/30/ganglia-monitoring-framework/#comments</comments>
		<pubDate>Fri, 30 Jul 2010 11:37:45 +0000</pubDate>
		<dc:creator>satishgaudo</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ganglia]]></category>
		<category><![CDATA[gmetd]]></category>
		<category><![CDATA[gmond]]></category>
		<category><![CDATA[ibm]]></category>
		<category><![CDATA[server health]]></category>
		<category><![CDATA[server monitoring]]></category>

		<guid isPermaLink="false">http://satishgaudo.com/satblog/?p=239</guid>
		<description><![CDATA[
			
				
			
		
Ganglia is a monitoring framework for clusters of servers. It records many statistics and can record custom defined ones too. It works in a distributed manner, with each machine you wish to collect statistics for running the Ganglia monitor deamon, gmond. Each monitoring deamon’s statistics are collected by a metadata daemon, gmetad, running on either [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fsatishgaudo.com%2Fsatblog%2F2010%2F07%2F30%2Fganglia-monitoring-framework%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fsatishgaudo.com%2Fsatblog%2F2010%2F07%2F30%2Fganglia-monitoring-framework%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Ganglia is a monitoring framework for clusters of servers. It records many statistics and can record custom defined ones too. It works in a distributed manner, with each machine you wish to collect statistics for running the Ganglia monitor deamon, gmond. Each monitoring deamon’s statistics are collected by a metadata daemon, gmetad, running on either one of the monitored hosts or a separate machine. Ganglia provides a PHP frontend which displays the data from gmetad in the form of pretty graphs.</p>
<p>For extra details: <a href="http://www.ibm.com/developerworks/wikis/display/WikiPtype/ganglia">http://www.ibm.com/developerworks/wikis/display/WikiPtype/ganglia</a></p>
<p>On installation ganglia will show default metrics like cluster load, cpu status etc.</p>
<div class="wp-caption alignnone" style="width: 460px"><img title="Ganglia web front" src="http://satishgaudo.com/satblog/ext_img/ganglia.jpg" alt="Ganglia web front" width="450" height="547" /><p class="wp-caption-text">Ganglia web front</p></div>
<p>Admin can define metrics that he want using &#8220;gmetric&#8221; command like</p>
<p><strong><span style="color: #ff0000;">/usr/bin/gmetric  -u hits -tfloat -n apache_status_200  -v 100</span></strong></p>
<p>where n is the metric name and v is the value</p>
<p>Following are the PHP scripts called on crontab,</p>
<p>1. <strong>Apache Access log metric to count hits status:</strong></p>
<p><span style="color: #000000;">$gmetric_command = &#8220;/usr/bin/gmetric&#8221;;<br />
//cat access.log | grep &#8220;31/Jul/2010:09&#8243; | cut -f9 -d &#8221; &#8221; | sort | uniq -c<br />
$sApacheLogFile=APACHE_LOG_DIR.&#8221;access.log&#8221;;<br />
$sCurrentDate=date(&#8221;d/M/Y:H&#8221;);<br />
$sStatCommand=&#8221;cat &#8220;.$sApacheLogFile.&#8221; | grep &#8216;&#8221;.$sCurrentDate.&#8221;&#8216; | cut -f9 -d &#8216; &#8216; | sort | uniq -c&#8221;;<br />
$aOutput=Array();<br />
$sOp=exec($sStatCommand,$aOutput);<br />
if(is_array($aOutput)){<br />
foreach($aOutput as $iK =&gt;$sValue) {<br />
$aData=Array();<br />
$aData=explode(&#8221; &#8220;,trim($sValue));<br />
if($aData[0]&gt;0){<br />
system($gmetric_command . &#8221; -u hits -tfloat -n apache_status_&#8221;.$aData[1].&#8221; -v &#8221; . $aData[0]);<br />
}<br />
}<br />
}</span></p>
<p><strong>2.  Mysql status metrics:</strong></p>
<p><span style="color: #000000;">//gmetric command<br />
$stats_command = &#8220;/usr/bin/mysqladmin -u root &#8211;password=mAnG0pp1 extended-status&#8221;;<br />
$gmetric_command = &#8220;/usr/bin/gmetric&#8221;;<br />
$aCounterMetrics = Array(<br />
&#8220;Bytes_received&#8221; =&gt; &#8220;bytes&#8221;,<br />
&#8220;Bytes_sent&#8221; =&gt; &#8220;bytes&#8221;,<br />
&#8220;Com_delete&#8221; =&gt; &#8220;operations&#8221;,<br />
&#8220;Com_insert&#8221; =&gt; &#8220;operations&#8221;,<br />
&#8220;Com_replace&#8221; =&gt; &#8220;operations&#8221;,<br />
&#8220;Com_select&#8221; =&gt; &#8220;operations&#8221;,<br />
&#8220;Com_update&#8221; =&gt; &#8220;operations&#8221;,<br />
&#8220;Key_reads&#8221; =&gt; &#8220;operations&#8221;,<br />
&#8220;Qcache_hits&#8221; =&gt; &#8220;hits&#8221;,<br />
&#8220;Questions&#8221; =&gt; &#8220;queries&#8221;,<br />
&#8220;Connections&#8221; =&gt; &#8220;connections&#8221;,<br />
&#8220;Threads_created&#8221; =&gt; &#8220;threads&#8221;,<br />
&#8220;Slow_queries&#8221; =&gt; &#8220;queries&#8221;<br />
);<br />
$aAbsoluteMetrics = array(<br />
&#8220;Threads_connected&#8221; =&gt; &#8220;threads&#8221;,<br />
&#8220;Threads_running&#8221; =&gt; &#8220;threads&#8221;<br />
);<br />
$sMysqlLogFile=LOG_DIR.&#8221;mysql_stats.txt&#8221;;</span></p>
<p><span style="color: #000000;">if(!file_exists($sMysqlLogFile)){<br />
//if no file , create a one<br />
system(&#8221;$stats_command &gt; $sMysqlLogFile&#8221;);<br />
}else {<br />
//get the old stats data<br />
$aStatsOld=file($sMysqlLogFile);<br />
$aMyStatsOld=Array();<br />
$i=0;<br />
if(is_array($aStatsOld)&amp;&amp; count($aStatsOld)&gt;0){<br />
for($i=3;$i&lt;(count($aStatsOld)-1);$i++){<br />
$aStatTemp=explode(&#8221;|&#8221;,$aStatsOld[$i]);<br />
$aMyStatsOld[trim($aStatTemp[1])]=trim($aStatTemp[2]);<br />
}<br />
}<br />
unset($aStatTemp);<br />
//get the time file modified last time<br />
$sFileModTime=filemtime($sMysqlLogFile);<br />
unlink($sMysqlLogFile);<br />
//get the current stats<br />
system(&#8221;$stats_command &gt; $sMysqlLogFile&#8221;);<br />
$sCurrentTime=time();<br />
$aStatsNew=file($sMysqlLogFile);<br />
$aMyStatsNew=Array();<br />
if(is_array($aStatsNew)&amp;&amp; count($aStatsNew)&gt;0){<br />
for($i=3;$i&lt;(count($aStatsNew)-1);$i++){<br />
$aStatTemp=explode(&#8221;|&#8221;,$aStatsNew[$i]);<br />
$aMyStatsNew[trim($aStatTemp[1])]=trim($aStatTemp[2]);<br />
}<br />
}<br />
$iTimeDiff=$sCurrentTime-$sFileModTime;<br />
if($iTimeDiff&lt;1){<br />
die(&#8221;Time difference can&#8217;t be less than 1&#8243;);<br />
}<br />
# Calculate deltas for counter metrics and send them to ganglia<br />
foreach($aCounterMetrics as $sMetric =&gt;$sUnit){<br />
//print $aMyStatsNew[$sMetric].&#8221; &#8211; &#8220;.$aMyStatsOld[$sMetric].&#8221;===&lt;br&gt;&#8221;;<br />
$iRate = ($aMyStatsNew[$sMetric] &#8211; $aMyStatsOld[$sMetric]) / $iTimeDiff;</span></p>
<p><span style="color: #000000;">if ($iRate&gt;=0) {<br />
system($gmetric_command . &#8221; -u &#8216;$sUnit/sec&#8217; -tfloat -n mysqld_&#8221; . $sMetric . &#8221; -v &#8221; . $iRate);<br />
}<br />
}<br />
//Just send absolute metrics. No need to calculate delta<br />
foreach($aAbsoluteMetrics as $sMetric =&gt;$sUnit){<br />
system($gmetric_command . &#8221; -u $sUnit -tuint16 -n mysqld_&#8221; .$sMetric. &#8221; -v &#8221; .$aMyStats[$sMetric]);<br />
}<br />
}</span></p>
<p><strong>3.  Memcache status:</strong></p>
<p><span style="color: #000000;">require_once(CLASS_PATH.&#8217;memcache.class.php&#8217;);<br />
$oCache = new Cache();<br />
$gmetric_command = &#8220;/usr/bin/gmetric&#8221;;<br />
$sMemcacheLogFile=LOG_DIR.&#8221;memcache_stats.txt&#8221;;<br />
$aOldStats=Array();<br />
//get the memcache stats<br />
$aNewStats=$oCache-&gt;getExtendedStats();<br />
if(!file_exists($sMemcacheLogFile)){<br />
$f=fopen($sMemcacheLogFile,&#8221;w&#8221;);<br />
fwrite($f,serialize($aNewStats));<br />
fclose($f);<br />
}else {<br />
$aOldStats=unserialize(file_get_contents($sMemcacheLogFile));<br />
$sFileModTime=filemtime($sMemcacheLogFile);<br />
$iTimeDiff=time()-$sFileModTime;</span></p>
<p><span style="color: #000000;">$f=fopen($sMemcacheLogFile,&#8221;w&#8221;);<br />
fwrite($f,serialize($aNewStats));<br />
fclose($f);<br />
}</span></p>
<p><span style="color: #000000;">#################################################################################<br />
# Memcache Hit Ratio<br />
#################################################################################<br />
foreach($aNewStats as $sHost =&gt;$aData){<br />
$sDisplayHost=$sHost;<br />
$sDisplayHost=str_replace(&#8221;.&#8221;,&#8221;_&#8221;,$sDisplayHost);<br />
$sDisplayHost=str_replace(&#8221;:&#8221;,&#8221;_&#8221;,$sDisplayHost);<br />
$iHits   = $aData['get_hits'];<br />
$iMisses = $aData['get_misses'];<br />
$iTotalReq = $iHits + $iMisses;<br />
$iHitRatio=0;<br />
if ($iTotalReq == 0 ) {<br />
$iHitRatio = 0.0;<br />
} else {<br />
$iHitRatio = $iHits / $iTotalReq;<br />
}</span></p>
<p><span style="color: #000000;">system($gmetric_command . &#8221; -u ratio -tfloat -n memcache_hit_ratio&#8221;.$sDisplayHost.&#8221; -v &#8221; . $iHitRatio);<br />
#################################################################################<br />
# Calculate Memcache Fill Ratio<br />
#################################################################################<br />
$iTotalBytes = 0;<br />
$iUsedBytes  = 0;<br />
$iCurrConnections = 0;<br />
$iCurrItems = 0;<br />
$iFillRatio = 0;<br />
$iEvictions = 0;<br />
$iBytesRead = 0;<br />
$iBytesWritten = 0;<br />
$iTotalBytes = $aData['limit_maxbytes'];<br />
$iUsedBytes  = $aData['bytes'];<br />
$iFillRatio = $iUsedBytes/$iTotalBytes;<br />
$iCurrConnections = $aData['curr_connections'];<br />
$iCurrItems = $aData['curr_items'];</span></p>
<p><span style="color: #000000;">$iEvictions = $aData['evictions'];<br />
$iBytesRead = $aData['bytes_read'];<br />
$iBytesWritten = $aData['bytes_written'];</span></p>
<p><span style="color: #000000;">system($gmetric_command . &#8221; -u ratio -tfloat -n memcache_fill_ratio&#8221;.$sDisplayHost.&#8221; -v &#8221; . $iFillRatio );<br />
system($gmetric_command . &#8221; -u connections -tfloat -n memcache_curr_connections&#8221;.$sDisplayHost.&#8221; -v &#8221; . $iCurrConnections );<br />
system($gmetric_command . &#8221; -u items -tfloat -n memcache_curr_items&#8221;.$sDisplayHost.&#8221; -v &#8221; . $iCurrItems );<br />
//calculate counter metrics such as bytes in/out and evictions</span></p>
<p><span style="color: #000000;">if (isset($aOldStats[$sHost]) &amp;&amp; $iBytesRead &gt;= $aOldStats[$sHost]['bytes_read']) {<br />
system($gmetric_command . &#8221; -u number -tuint32 -n memcache_evictions&#8221;.$sDisplayHost.&#8221; -v &#8221; . ($iEvictions &#8211; $aOldStats[$sHost]['evictions']) );<br />
system($gmetric_command . &#8221; -u bytes/s -tfloat -n memcache_bytes_read&#8221;.$sDisplayHost.&#8221; -v &#8221; . ( ($iBytesRead &#8211; $aOldStats[$sHost]['bytes_read']) / $iTimeDiff)  );<br />
system($gmetric_command . &#8221; -u bytes/s -tfloat -n memcache_bytes_written&#8221;.$sDisplayHost.&#8221; -v &#8221; . ( ($iBytesWritten &#8211; $aOldStats[$sHost]['bytes_written']) / $iTimeDiff ) );<br />
}</span></p>
<p><span style="color: #000000;">}</span></p>
<p><strong>&#8212;memcache.class.php</strong></p>
<p><span style="color: #000000;">&lt;?php<br />
/**<br />
*<br />
* Setup:<br />
*<br />
edit the singleton() metod<br />
and define the list of memcached servers in a 2-d array<br />
in the format<br />
array(<br />
array(&#8217;192.168.0.1&#8242;=&gt;&#8217;11211&#8242;),<br />
array(&#8217;192.168.0.2&#8242;=&gt;&#8217;11211&#8242;),<br />
);<br />
*<br />
*<br />
* Usage:<br />
*<br />
&lt;?php<br />
//include the class name<br />
include (&#8217;memcache.class.php&#8217;);</span></p>
<p><span style="color: #000000;">//store the variable<br />
Cache::set(&#8217;key&#8217;,'abc&#8217;);</span></p>
<p><span style="color: #000000;">//increment/decrement the integer value<br />
Cache::increment(&#8217;key&#8217;);<br />
Cache::decrement(&#8217;key&#8217;);</span></p>
<p><span style="color: #000000;">//fetch the value by it&#8217;s key<br />
echo Cache::get(&#8217;key&#8217;);</span></p>
<p><span style="color: #000000;">//delete the data<br />
echo Cache::delete(&#8217;key&#8217;);</span></p>
<p><span style="color: #000000;">//Clear the cache memory on all servers<br />
Cache::flush();</span></p>
<p><span style="color: #000000;">Cache::replace() and Cache::add are implemented also.</span></p>
<p><span style="color: #000000;">More information can be obtained here:<br />
http://www.danga.com/memcached/<br />
http://www.php.net/memcache</span></p>
<p><span style="color: #000000;">*/<br />
/** @ingroup classes<br />
*  This is the Classes group<br />
*  @{<br />
*/<br />
/**<br />
* @brief class Cache The class makes it easier to work with memcached servers and provides hints in the IDE like Zend Studio<br />
* @version 1<br />
*<br />
*/</span></p>
<p><span style="color: #000000;">class Cache {<br />
/**<br />
* Resources of the opend memcached connections<br />
* @var array [memcache objects]<br />
*/<br />
var $mc_servers = array();<br />
/**<br />
* Quantity of servers used<br />
* @var int<br />
*/</span></p>
<p><span style="color: #000000;">var $servers = array(</span></p>
<p><span style="color: #000000;">array(&#8217;127.0.0.1&#8242;=&gt;&#8217;11211&#8242;)<br />
);</span></p>
<p><span style="color: #000000;">var $mc_servers_count=1;</span></p>
<p><span style="color: #000000;">/**<br />
* Accepts the 2-d array with details of memcached servers<br />
*<br />
* @param array $servers<br />
*/<br />
function Cache(){</span></p>
<p><span style="color: #000000;">/*<br />
for ($i = 0, $n = count($this-&gt;servers); $i &lt; $n; ++$i){<br />
( $con = memcache_connect(key($this-&gt;servers[$i]), current($this-&gt;servers[$i])) )&amp;&amp;<br />
$this-&gt;mc_servers[] = $con;<br />
}<br />
$this-&gt;mc_servers_count = count($this-&gt;mc_servers);<br />
if (!$this-&gt;mc_servers_count){<br />
$this-&gt;mc_servers[0]=null;<br />
}<br />
*/<br />
}</span></p>
<p><span style="color: #000000;">/**<br />
* Get statistics of the server<br />
*<br />
* @param string $key<br />
* @param mix $value<br />
* @return bool<br />
*/<br />
function getExtendedStats() {<br />
$num=0;<br />
foreach ($this-&gt;servers[$num] as $host =&gt; $port) {<br />
$memcache_obj = memcache_pconnect($host, $port);<br />
}<br />
if (!$memcache_obj) return false;<br />
return $memcache_obj-&gt;getExtendedStats();<br />
}</span></p>
<p><span style="color: #000000;">//class end<br />
}</span></p>
<p>?&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://satishgaudo.com/satblog/2010/07/30/ganglia-monitoring-framework/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Tuning LAMP systems, Part 2: Optimizing Apache and PHP</title>
		<link>http://satishgaudo.com/satblog/2010/05/07/tuning-lamp-systems-part-2-optimizing-apache-and-php/</link>
		<comments>http://satishgaudo.com/satblog/2010/05/07/tuning-lamp-systems-part-2-optimizing-apache-and-php/#comments</comments>
		<pubDate>Fri, 07 May 2010 05:47:23 +0000</pubDate>
		<dc:creator>satishgaudo</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Part 2: Optimizing Apache and PHP]]></category>
		<category><![CDATA[Tuning LAMP systems]]></category>

		<guid isPermaLink="false">http://satishgaudo.com/satblog/?p=196</guid>
		<description><![CDATA[
			
				
			
		
Here is an link from digg.com, Tuning LAMP systems, Part 2: Optimizing Apache and PHP
Tuning LAMP systems, Part 2: Optimizing Apache and PHP
]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fsatishgaudo.com%2Fsatblog%2F2010%2F05%2F07%2Ftuning-lamp-systems-part-2-optimizing-apache-and-php%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fsatishgaudo.com%2Fsatblog%2F2010%2F05%2F07%2Ftuning-lamp-systems-part-2-optimizing-apache-and-php%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Here is an link from digg.com, Tuning LAMP systems, Part 2: Optimizing Apache and PHP</p>
<p><a class="wp-caption" title="Tuning LAMP systems, Part 2: Optimizing Apache and PHP" href="http://digg.com/d38pEi" target="_blank"><span style="text-decoration: underline;"><span style="color: #ff0000;">Tuning LAMP systems, Part 2: Optimizing Apache and PHP</span></span></a></p>
]]></content:encoded>
			<wfw:commentRss>http://satishgaudo.com/satblog/2010/05/07/tuning-lamp-systems-part-2-optimizing-apache-and-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux commands</title>
		<link>http://satishgaudo.com/satblog/2010/01/30/linux-commands/</link>
		<comments>http://satishgaudo.com/satblog/2010/01/30/linux-commands/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 07:22:18 +0000</pubDate>
		<dc:creator>satishgaudo</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://satishgaudo.com/satblog/?p=143</guid>
		<description><![CDATA[
			
				
			
		
sed -i &#8217;s/abc/xyz/g&#8217; *.php
This command is used for mass replacemet using regular expression.
In the above command &#8220;abc&#8221; is replace with &#8220;xyz&#8221; from all the files extension &#8220;php&#8221;.
find /var/www/html/sch_admin/ -mtime -1
This command is used to list all the files within the specified folder,say &#8220;var/www/html/sch_admin/&#8221;, which have been created or modified within the period specified,say &#8220;-1&#8243; which [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fsatishgaudo.com%2Fsatblog%2F2010%2F01%2F30%2Flinux-commands%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fsatishgaudo.com%2Fsatblog%2F2010%2F01%2F30%2Flinux-commands%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p><strong>sed -i &#8217;s/abc/xyz/g&#8217; *.php</strong><br />
This command is used for mass replacemet using regular expression.<br />
In the above command &#8220;abc&#8221; is replace with &#8220;xyz&#8221; from all the files extension &#8220;php&#8221;.</p>
<p><strong>find /var/www/html/sch_admin/ -mtime -1</strong></p>
<p>This command is used to list all the files within the specified folder,say &#8220;var/www/html/sch_admin/&#8221;, which have been created or modified within the period specified,say &#8220;-1&#8243; which is last one day.</p>
<p><strong>tar xvzf pig-0.5.0.tar.gz</strong><br />
untar the tar.gz file</p>
<p>Add /pig-n.n.n/bin to your path. Use export (bash,sh,ksh) or setenv (tcsh,csh). For example:<br />
<strong> export PATH=/root/pig-0.5.0/bin:$PATH</strong></p>
<p>Set JAVA_HOME as follows using syntax export JAVA_HOME=
<path-to-java>.<br />
If your path is set to /usr/java/jdk1.5.0_07/bin/java, set it as follows:<br />
<strong>export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0/jre</strong></p>
<p>Tip: Use the following command to find out exact path to which java executable under UNIX / Linux:<br />
<strong>$ which java</strong></p>
<p>* export command is used to set environment variable relevant on during the current session</p>
<p>For permanent setup &#8211; edit .bash_profile &#8211; as it get all the vars set on login</p>
<p><strong>vi ~/.bash_profile</strong><br />
<strong>export JAVA_HOME=/usr</strong><br />
<strong>export PATH=/root/pig-0.5.0/bin:$PATH</strong></p>
<p><strong>Display date And time for each command</strong><br />
$ HISTTIMEFORMAT=&#8221;%d/%m/%y %T &#8221;</p>
<p>OR </p>
<p>$ echo &#8216;export HISTTIMEFORMAT=&#8221;%d/%m/%y %T &#8220;&#8216; >> ~/.bash_profile</p>
<p>To see history type:<br />
$ history</p>
<p>Output Sample:<br />
1002  12/03/10 11:50:24 echo &#8216;export HISTTIMEFORMAT=&#8221;%d/%m/%y %T &#8220;&#8216; >> ~/.bash_profile</p>
]]></content:encoded>
			<wfw:commentRss>http://satishgaudo.com/satblog/2010/01/30/linux-commands/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

