Support Questions

Find answers, ask questions, and share your expertise

how to capture all ambari services/components status by API

avatar

Dear colleges


I want to capture all ambari services/components status by API

I need to do so because we developed some scripts that make a lot of change in ambari configuration & restart of some services,

Therefore we need to know what is the services/components status before the changes and what is the services status after the changes

So we need rest API that will capture all ambari services/components status ( as HDFS, YARN Mapreduce , Tez ,Pig , Ziikeper , AMbari metrix , kafka , spark etc )

Expected results Status can be as – fail/ok

Michael-Bronson
1 ACCEPTED SOLUTION

avatar
Super Guru

@Michael Bronson,

You can get the state - STARTED/STOPPED by using the below API Calls

For services

curl -u {ambari-username}:{ambari-password} -H "X-Requested-By: ambari" -X GET http://{ambari-host}:{ambari-port}/api/v1/clusters/{clustername}/services/{service-name}?fields=Serv...

For components

curl -u {ambari-username}:{ambari-password} -H "X-Requested-By: ambari" -X GET http://{ambari-host}:{ambari-port}/api/v1/clusters/{clustername}/components/{component-name}?fields=...

To get complete status info about service

curl -u {ambari-username}:{ambari-password} -H "X-Requested-By: ambari" -X GET http://{ambari-host}:{ambari-port}/api/v1/clusters/{clustername}/services/{service-name}

To get complete status info about component

curl -u {ambari-username}:{ambari-password} -H "X-Requested-By: ambari" -X GET http://{ambari-host}:{ambari-port}/api/v1/clusters/{clustername}/components/{component-name}

Replace the place holders like {ambari-username} , {ambari-password}, {ambari-host} , {ambari-port},{clustername} etc with your respective values

Thanks,

Aditya

View solution in original post

19 REPLIES 19

avatar
Contributor

You can refer to https://community.hortonworks.com/articles/81353/popular-ambari-rest-api-commands.html for commands relating to listing of various services etc. It also has link to other ambari API documentation

avatar

not help , see the article its about stop/start others and not as I asked , what I am asking is how to get status from ambari about services / components , and get results as ok / fail

Michael-Bronson

avatar
Super Guru

@Michael Bronson,

You can get the state - STARTED/STOPPED by using the below API Calls

For services

curl -u {ambari-username}:{ambari-password} -H "X-Requested-By: ambari" -X GET http://{ambari-host}:{ambari-port}/api/v1/clusters/{clustername}/services/{service-name}?fields=Serv...

For components

curl -u {ambari-username}:{ambari-password} -H "X-Requested-By: ambari" -X GET http://{ambari-host}:{ambari-port}/api/v1/clusters/{clustername}/components/{component-name}?fields=...

To get complete status info about service

curl -u {ambari-username}:{ambari-password} -H "X-Requested-By: ambari" -X GET http://{ambari-host}:{ambari-port}/api/v1/clusters/{clustername}/services/{service-name}

To get complete status info about component

curl -u {ambari-username}:{ambari-password} -H "X-Requested-By: ambari" -X GET http://{ambari-host}:{ambari-port}/api/v1/clusters/{clustername}/components/{component-name}

Replace the place holders like {ambari-username} , {ambari-password}, {ambari-host} , {ambari-port},{clustername} etc with your respective values

Thanks,

Aditya

avatar

ok fine , how to get all list of services / components by API in order to use them for the API that U gave me

Michael-Bronson

avatar
Super Guru
@Michael Bronson

To get list of services

curl -u {ambari-username}:{ambari-password}-H "X-Requested-By: ambari"-X GET http://{ambari-host}:{ambari-port}/api/v1/clusters/{clustername}/services/{service-name}

To get list of components

curl -u {ambari-username}:{ambari-password}-H "X-Requested-By: ambari"-X GET http://{ambari-host}:{ambari-port}/api/v1/clusters/{clustername}/components/

avatar

I see little problem for example when I check the HDFS with complete status , I not see the status of "stand by namenode" or "ZKfailovercontroler" etc , and for example for YARN we not see the App Timeline Server etc

Michael-Bronson

avatar
Contributor
@Michael Bronson

You can get the service components status from the "ServiceComponentInfo/state" parameter.

1. To get all components state in single API:

API : <AMBARI_HOST>/api/v1/clusters/cl1/components?fields=ServiceComponentInfo/state

E.g In the response you can find something like this when MR History server is stopped:

"ServiceComponentInfo": {"cluster_name": "cl1","component_name": "HISTORYSERVER","service_name": "MAPREDUCE2","state": "INSTALLED"}

2. To get more info for individual component, You can use this API resource

<AMBARI_HOST>/api/v1/clusters/cl1/services/MAPREDUCE2/components/HISTORYSERVER

Hopefully this helps!

avatar

thank you kramakrishnan , regarding step1 can you please show me the full command API syntax

Michael-Bronson

avatar
Contributor

@Michael Bronson

curl -u {ambari_username}:{ambari_password} -H "X-Requested-By:ambari" -i GET http://localhost:8080/api/v1/clusters/cl1/components?fields=ServiceComponentInfo/state