Created 01-02-2018 02:19 PM
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
Created 01-02-2018 04:51 PM
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
Created 01-03-2018 05:20 AM
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
Created 01-03-2018 09:02 AM
@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 ...
Created 01-03-2018 10:46 AM
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
Created 01-03-2018 12:32 PM
@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
Created 01-03-2018 12:38 PM
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
Created 01-03-2018 12:42 PM
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" } } } } ]
Created 01-03-2018 01:07 PM
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
Created 01-03-2018 02:32 PM
@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
Created 01-03-2018 01:30 PM
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
.
Created 01-03-2018 01:55 PM
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