Support Questions
Find answers, ask questions, and share your expertise

how to capture all ambari services/components status by API

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

@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

Explorer

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

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

@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

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

@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/

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

@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!

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

Michael-Bronson

@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

@Michael Bronson,

To get status of all services

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

To get status of all components

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

Replace the placeholders

Thanks,

Aditya

@Aditya thank you , but this output not include the status of for example- Standby NameNode or ZKFailoverController etc .... , also kramakrishnan wrote some syntax that can give the results but I will happy to get the full syntax with curl ...

Michael-Bronson

@Michael Bronson,

ZKFailoverController is listed as ZKFC in the above API call response. If you want to get the status of ZKFailoverController , you can call this below API

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

The status of Standby NameNode and Active Namenode will be represented together as NameNode. If you want to know the active and standby namenodes, you can use these below API calls

For active Namenode:

curl -u admin:admin -H "X-Requested-By: ambari" -X GET "http://{ambari-host}:{ambari-port}/api/v1/clusters/{clustername}/host_components?HostRoles/component_name=NAMENDE&metrics/dfs/FSNamesystem/HAState=active"

For standby namenode:

curl -u admin:admin -H "X-Requested-By: ambari" -X GET "http://{ambari-host}:{ambari-port}/api/v1/clusters/{clustername}/host_components?HostRoles/component_name=NAMENODE&metrics/dfs/FSNamesystem/HAState=standby"

Thanks,

Aditya

@Aditya

first thank you so much for the example , the API are works and indicate the machine name but not indicate the status stop/start from output

Michael-Bronson

@Michael Bronson,

There will not be separate status for Active NameNode and StandByNamenode. You can find if name node is running or not. To get the status of NAMENODE use the below API

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

Thanks,

Aditya

example

 curl -u admin:admin -H "X-Requested-By: ambari" -X GET "http://localhost:8080/api/v1/clusters/hdp/host_components?HostRoles/component_name=NAMENODE&metrics/dfs/FSNamesystem/HAState=standby"
{
  "href" : "http://localhost:8080/api/v1/clusters/hdp/host_components?HostRoles/component_name=NAMENODE&metrics/dfs/FSNamesystem/HAState=standby",
  "items" : [
    {
      "href" : "http://localhost:8080/api/v1/clusters/hdp/hosts/master01.uridns.com/host_components/NAMENODE",
      "HostRoles" : {
        "cluster_name" : "hdp",
        "component_name" : "NAMENODE",
        "host_name" : "master01.uhg.com"
      },
      "host" : {
        "href" : "http://localhost:8080/api/v1/clusters/hdp/hosts/master01.uhg.com"
      },
      "metrics" : {
        "dfs" : {
          "FSNamesystem" : {
            "HAState" : "standby"
          }
        }
      }
    }
  ]
Michael-Bronson

ok , in that case what are the other alternative to check ( active/stand name node or App Timeline Server ) etc , because they not appears from the API , not logical to check them only from the Ambari GUI must be some way for that

Michael-Bronson

@Michael Bronson,

To get state of Active Namenode

curl -u {ambari-username}:{ambari-password} -H "X-Requested-By: ambari" -X GET http://{ambari-host}:{ambari-port}/api/v1/clusters/{clustername}/hosts/{active-namenode-host-name}/h...

To get state of StandBy Namenode

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

To get state of App Timeline Server

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

Note that you have to replace Active Namenode and standby Namenode hostnames in the URLs

Thanks,

Aditya

Super Mentor

@Michael Bronson

You can make use of the following Ambari API calls to findout Active/Standby NameNodes.

# curl -u admin:admin -H "X-Requested-By: ambari" -X GET "http://erie1.example.com:8080/api/v1/clusters/ErieCluster/host_components?HostRoles/component_name=NAMENODE&metrics/dfs/FSNamesystem/HAState=standby"


# curl -u admin:admin -H "X-Requested-By: ambari" -X GET "http://erie1.example.com:8080/api/v1/clusters/ErieCluster/host_components?HostRoles/component_name=NAMENODE&metrics/dfs/FSNamesystem/HAState=active"



Please replace the following in the above queries.

erie1.exmple.com => Your Ambari Server FQDN
ErieCluster => Your clustername

.

dear @Jay , yes we see the machine that is active or stand by but the problem is that we not get the status as fail or OK

Michael-Bronson
; ;