Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

WARNING: The client library is still in the works and not production ready. 

Ambari python client can be used make use of Ambari APIs.

...

Code Block
languagepython
titleCreate Ambari client
firstline1
linenumberstrue
from ambari_client.ambari_api import  AmbariClient
headers_dict={'X-Requested-By':'mycompany'} #Ambari needs X-Requested-By header
client = AmbariClient("localhost", 8080, "admin", "admin", version=1,http_header=headers_dict)
print client.version
print client.host_url
print"\n"

...

  1. Code Block
    languagepython
    titleShow all clusters in Ambari
    firstline1
    linenumberstrue
    all_clusters = client.get_all_clusters()
    print all_clusters.to_json_dict()
    print all_clusters
  2. Code Block
    languagepython
    titleShow all hosts in Ambari
    firstline1
    linenumberstrue
    all_hosts = client.get_all_hosts()
    print all_hosts
    print all_hosts.to_json_dict()
    print"\n"

We can also get the information of a specific cluster

  1. Code Block
    languagepython
    titleShow a specific cluster in Ambari
    firstline1
    linenumberstrue
    mycluster = client.get_cluster('cluster1')
    print mycluster
    print mycluster.to_json_dict()
    print"\n"
    Code Block
    languagepython
    titleShow all hosts in the cluster
    firstline1
    linenumberstrue
    clusters_hosts = mycluster.get_all_hosts()
    print clusters_hosts.to_json_dict()
    print clusters_hosts
    print"\n"
  2. Code Block
    languagepython
    titleShow a specific host in the cluster
    firstline1
    linenumberstrue
    host1 = mycluster.get_host('host1')
    print host1
    print host1.clusterRef.cluster_name
    print host1.to_json_dict()
    print"\n"
  3. Code Block
    languagepython
    titleShow all components of a host
    firstline1
    linenumberstrue
    host1_comp = host1.get_host_components()
    print host1_comp
    print host1_comp.to_json_dict()
    print"\n"
  4. Code Block
    languagepython
    titleShow a specific service of a cluster
    firstline1
    linenumberstrue
    nn = host1.get_host_component("NAMENODE")
    print nn
    print nn.to_json_dict()
    print nn.clusterRef.cluster_name
    print"\n"
  5. Code Block
    languagepython
    titleShow all services in the cluster
    firstline1
    linenumberstrue
    serviceList = mycluster.get_all_services()
    print serviceList
    print serviceList.to_json_dict()
    print"\n"
  6. Code Block
    languagepython
    titleShow a specific service of a cluster
    firstline1
    linenumberstrue
    ganglia = mycluster.get_service("GANGLIA")
    print  ganglia
    print ganglia.to_json_dict()
    print"\n"
  7. Code Block
    languagepython
    titleShow all components of a service
    firstline1
    linenumberstrue
    ganglia_comps = ganglia.get_service_components()
    print ganglia_comps
    print ganglia_comps.to_json_dict()
    print"\n"
  8. Code Block
    languagepython
    titleShow a specific component of a service
    firstline1
    linenumberstrue
    ganglia_comp1 = ganglia.get_service_component('GANGLIA_MONITOR')
    print ganglia_comp1
    print ganglia_comp1.to_json_dict()
    print ganglia_comp1.clusterRef.cluster_name
    print"\n"
  9. Code Block
    languagepython
    titleStop a service
    firstline1
    linenumberstrue
    ganglia.stop()
  10. Code Block
    languagepython
    titleSatrt a service
    firstline1
    linenumberstrue
    ganglia.start()

Get metrics

  1. Code Block
    languagepython
    titleget cpu-metrics of service component TASKTRACKER
    firstline1
    linenumberstrue
    mr = mycluster.get_service("MAPREDUCE")
    mr_comp1 = mr.get_service_component('TASKTRACKER')
    metric_json = mr_comp1.get_metrics()
    print metric_json["metrics"]["cpu"]
    print"\n"
  2. Code Block
    languagepython
    titleget cpu-metrics from a host which has component NAMENODE
    firstline1
    linenumberstrue
    host1 = mycluster.get_host('host1')
    nn = host1.get_host_component("NAMENODE")
    metric_json = nn.get_metrics()
    print metric_json["metrics"]["cpu"]
    print"\n"

Create & configure cluster

...