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
Super Guru

@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

avatar

@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

avatar
Super Guru

@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

avatar

@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

avatar
Super Guru

@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

avatar

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

avatar

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

avatar
Super Guru
@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

avatar
Master 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

.

avatar

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