Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Query Ambari to get each host/service racks

avatar

Do we have any api to get rack info of each /service in an ambari cluster

1 ACCEPTED SOLUTION

avatar
Master Mentor

@Manisha Pande

You can use the following Ambari API call:

# curl -u admin:admin -H "X-Requested-By:ambari" -X GET http://ambariserver.example.com:8080/api/v1/clusters/TestCluster/hosts?fields=Hosts/rack_info,Hosts/...

.

Please replace the "TestCluster" with your own cluster name and the ambari hostname in the above URL.

View solution in original post

6 REPLIES 6

avatar
Master Mentor

@Manisha Pande

You can use the following Ambari API call:

# curl -u admin:admin -H "X-Requested-By:ambari" -X GET http://ambariserver.example.com:8080/api/v1/clusters/TestCluster/hosts?fields=Hosts/rack_info,Hosts/...

.

Please replace the "TestCluster" with your own cluster name and the ambari hostname in the above URL.

avatar

@Jay Kumar SenSharma

Thanks Jay!!

My requirement to check each service get host name and rack info.Can we achieve this in one api.

Appreciate your help.

avatar
Master Mentor

@Manisha Pande

Can you please clarify what exactly do you mean by "check each service get host name and rack info"?

In Each service where do you see the rack info?

avatar

@Jay Kumar SenSharma

For example , I have two hosts in a cluster hostA, HostB

HostA is on rack-1 and HostB is on rack-2

Services components running in hostA are HDFS_CLINET, ZOOKEEPER,NAMENODE..etc

Services components running in hostB are HBASE, AMABRI_METRICS,DATANODE...etc

I want get result from api like Host: HostA, Service_component : NAMENODE, rack_info: rack-1

HostA, Service_component : ZOOKEEPER, rack_info: rack-1

HostB, Service_component : DATANODE, rack_info: rack-2

--------------------------------------

avatar
Master Mentor

@Manisha Pande

In that case you cane add the "host_components/HostRoles/service_name" part in the same API call to also list the components on each host along with the Rack Info. Burt you will have to parse the output based on your requirement.

Example:

# curl -u admin:admin -H "X-Requested-By:ambari" -X GET  http://hdfcluster1.example.com:8080/api/v1/clusters/TestCluster/hosts?fields=Hosts/rack_info,Hosts/h...

.

avatar
Master Mentor

@Manisha Pande

If this answers your query/issue then please mark this HCC thread as answered by clicking on "Accept" link on the correct answer, That way it will help other HCC users to quickly find the answers.