<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Api to help pull yarn metrics and RM metrics in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Api-to-help-pull-yarn-metrics-and-RM-metrics/m-p/237182#M85266</link>
    <description>&lt;P&gt;Hi &lt;A rel="user" href="https://community.cloudera.com/users/99538/akash417sharma.html" nodeid="99538"&gt;@akash sharma&lt;/A&gt;,&lt;/P&gt;&lt;P&gt;Requested functionality is implemented in smartsence Activity explorer, which is like a out of the box solution, please have a look at the functionality as that will have some pre-build reporting trend analysis reports will help to asses the capacity planing.&lt;/P&gt;&lt;P&gt;However, if you still wish to implement in-house solution you can get the data using the REST api from yarn and get the metrics out of the cluster.&lt;/P&gt;&lt;P&gt;following URL will have REST specs so that you can get the required information.&lt;/P&gt;&lt;P&gt;&lt;A href="https://hadoop.apache.org/docs/current/hadoop-yarn/hadoop-yarn-site/ResourceManagerRest.html" target="_blank"&gt;https://hadoop.apache.org/docs/current/hadoop-yarn/hadoop-yarn-site/ResourceManagerRest.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;flowing code is scala snippet to extract the same in json format and eventually can be loaded to database or other location.&lt;/P&gt;&lt;PRE&gt;  def getURL (rmHost1: String , rmHost2: String , urlExtension : String &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; URL = {

    val url1 = new URL(rmHost1 + urlExtension)
    val url2 = new URL(rmHost2 + urlExtension)

    try {
      url1.openConnection().asInstanceOf[HttpURLConnection].getResponseCode
      url1
    }
    catch {
      case e: Exception =&amp;gt; {
        logger.info("Unable to Connect to primary RM Host Trying Secondary RM Host")
        try {
          url2.openConnection().asInstanceOf[HttpURLConnection].getResponseCode
          url2
        } catch {
          case f: Exception =&amp;gt; {
            logger.info("Unable to connect to eaither of the RM Hostes hence terminating ..")
            logger.error("primary host Stack trace !!", e)
            logger.error("secondary host Stack trace !!", f)
            Throw f
          }
        }
      }
    }
  }

  def loadRM (props : Properties ,urlExtension : String &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; String = {

    val url = getURL(props.getProperty("resoucemanagerHost1") , props.getProperty("resoucemanagerHost2"), urlExtension)
    if ( url == null ) { return null }
  try {
    val urlContext =  url.openConnection().asInstanceOf[HttpURLConnection]
    val resStr = IOUtils.toString(urlContext.getInputStream, StandardCharsets.UTF_8)
    urlContext.disconnect()
    resStr
  } catch {
    case e : Exception =&amp;gt;
      logger.error("Unable to load the URL : "+url.toString, e)
      Throw e
    }
  }




   val dat = appFunctions.loadRM(properties, "/ws/v1/cluster/appstatistics")
      if (dat == null) {
        logger.error("Could not get payload")
        return
      }
      val payload =
        try {
          new JSONObject(dat).getJSONObject("appStatInfo").getJSONArray("statItem")
        } catch {
          case e: Exception =&amp;gt; {
            logger.error ("Unable to extract the content from Json for Cluster Metrics" + dat)
            return
          }
        }

&lt;/PRE&gt;</description>
    <pubDate>Mon, 03 Dec 2018 07:49:18 GMT</pubDate>
    <dc:creator>bkosaraju</dc:creator>
    <dc:date>2018-12-03T07:49:18Z</dc:date>
    <item>
      <title>Api to help pull yarn metrics and RM metrics</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Api-to-help-pull-yarn-metrics-and-RM-metrics/m-p/237181#M85265</link>
      <description>&lt;P&gt;Hello All&lt;/P&gt;&lt;P&gt;I am trying to create a script that can pull all the resource manager / history server data via api for a period of 24 hours. I want the output in json format and then later i can parse and persist which can be used  for trend analysis. &lt;/P&gt;&lt;P&gt;Any idea, how can I proceed on that. any pointers will be very helful.&lt;/P&gt;&lt;P&gt;thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Nov 2018 22:16:57 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Api-to-help-pull-yarn-metrics-and-RM-metrics/m-p/237181#M85265</guid>
      <dc:creator>akash417sharma</dc:creator>
      <dc:date>2018-11-30T22:16:57Z</dc:date>
    </item>
    <item>
      <title>Re: Api to help pull yarn metrics and RM metrics</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Api-to-help-pull-yarn-metrics-and-RM-metrics/m-p/237182#M85266</link>
      <description>&lt;P&gt;Hi &lt;A rel="user" href="https://community.cloudera.com/users/99538/akash417sharma.html" nodeid="99538"&gt;@akash sharma&lt;/A&gt;,&lt;/P&gt;&lt;P&gt;Requested functionality is implemented in smartsence Activity explorer, which is like a out of the box solution, please have a look at the functionality as that will have some pre-build reporting trend analysis reports will help to asses the capacity planing.&lt;/P&gt;&lt;P&gt;However, if you still wish to implement in-house solution you can get the data using the REST api from yarn and get the metrics out of the cluster.&lt;/P&gt;&lt;P&gt;following URL will have REST specs so that you can get the required information.&lt;/P&gt;&lt;P&gt;&lt;A href="https://hadoop.apache.org/docs/current/hadoop-yarn/hadoop-yarn-site/ResourceManagerRest.html" target="_blank"&gt;https://hadoop.apache.org/docs/current/hadoop-yarn/hadoop-yarn-site/ResourceManagerRest.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;flowing code is scala snippet to extract the same in json format and eventually can be loaded to database or other location.&lt;/P&gt;&lt;PRE&gt;  def getURL (rmHost1: String , rmHost2: String , urlExtension : String &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; URL = {

    val url1 = new URL(rmHost1 + urlExtension)
    val url2 = new URL(rmHost2 + urlExtension)

    try {
      url1.openConnection().asInstanceOf[HttpURLConnection].getResponseCode
      url1
    }
    catch {
      case e: Exception =&amp;gt; {
        logger.info("Unable to Connect to primary RM Host Trying Secondary RM Host")
        try {
          url2.openConnection().asInstanceOf[HttpURLConnection].getResponseCode
          url2
        } catch {
          case f: Exception =&amp;gt; {
            logger.info("Unable to connect to eaither of the RM Hostes hence terminating ..")
            logger.error("primary host Stack trace !!", e)
            logger.error("secondary host Stack trace !!", f)
            Throw f
          }
        }
      }
    }
  }

  def loadRM (props : Properties ,urlExtension : String &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; String = {

    val url = getURL(props.getProperty("resoucemanagerHost1") , props.getProperty("resoucemanagerHost2"), urlExtension)
    if ( url == null ) { return null }
  try {
    val urlContext =  url.openConnection().asInstanceOf[HttpURLConnection]
    val resStr = IOUtils.toString(urlContext.getInputStream, StandardCharsets.UTF_8)
    urlContext.disconnect()
    resStr
  } catch {
    case e : Exception =&amp;gt;
      logger.error("Unable to load the URL : "+url.toString, e)
      Throw e
    }
  }




   val dat = appFunctions.loadRM(properties, "/ws/v1/cluster/appstatistics")
      if (dat == null) {
        logger.error("Could not get payload")
        return
      }
      val payload =
        try {
          new JSONObject(dat).getJSONObject("appStatInfo").getJSONArray("statItem")
        } catch {
          case e: Exception =&amp;gt; {
            logger.error ("Unable to extract the content from Json for Cluster Metrics" + dat)
            return
          }
        }

&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Dec 2018 07:49:18 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Api-to-help-pull-yarn-metrics-and-RM-metrics/m-p/237182#M85266</guid>
      <dc:creator>bkosaraju</dc:creator>
      <dc:date>2018-12-03T07:49:18Z</dc:date>
    </item>
  </channel>
</rss>

