Advertisement
Guest User

Untitled

a guest
Apr 10th, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. ## ********************************************************************************
  4. ## get-yarn-long-running-jobs.py
  5. ##
  6. ## Usage: ./get-yarn-long-running-jobs.py
  7. ##
  8. ## Edit the settings below to connect to your Cluster
  9. ##
  10. ## ********************************************************************************
  11.  
  12. import sys
  13. import time
  14. import datetime
  15. from cm_api.api_client import ApiResource
  16.  
  17. ## Settings to connect to the cluster
  18.  
  19. cm_host = "toronto"
  20.  
  21. cm_port = "7180"
  22.  
  23. cm_login = "admin"
  24.  
  25. cm_password = "admin"
  26.  
  27. cluster_name = "onefoursix"
  28.  
  29.  
  30.  
  31. ## define a tsquery
  32. query = "SELECT application_duration from YARN_APPLICATIONS where application_duration > 12000"
  33.  
  34.  
  35. ## Connect to CM
  36. api = ApiResource(server_host=cm_host, server_port=cm_port, username=cm_login, password=cm_password, version=11)
  37.  
  38. ## Get Cluster
  39. cluster = None
  40. clusters = api.get_all_clusters()
  41. for c in clusters:
  42. if c.displayName == cluster_name:
  43. cluster = c
  44. break
  45. if cluster is None:
  46. print "\nError: Cluster '" + cluster_name + "' not found"
  47. quit(1)
  48.  
  49.  
  50. ## Get YARN Service
  51. yarn = None
  52. service_list = cluster.get_all_services()
  53. for service in service_list:
  54. if service.type == "YARN":
  55. yarn = service
  56. break
  57. if yarn is None:
  58. print "Error: Could not locate YARN Service"
  59. quit(1)
  60.  
  61. ## Get YARN Health Checks
  62. for chk in yarn.healthChecks:
  63. if chk['summary'] in ['CONCERNING','BAD'] :
  64. print (chk)
  65. if chk['name'] == 'alarm:Slow-YARN-Job':
  66.  
  67. ## define a 30 minute window
  68. from_time = datetime.datetime.fromtimestamp(time.time() - 1800)
  69. to_time = datetime.datetime.fromtimestamp(time.time())
  70.  
  71. ## get the metrics associated with the tsquery
  72. result = api.query_timeseries(query, from_time, to_time)
  73. ts_list = result[0]
  74.  
  75. ## print the metrics
  76. for ts in ts_list.timeSeries:
  77. print "--- %s: %s ---" % (ts.metadata.entityName, ts.metadata.metricName)
  78. for point in ts.data:
  79. print "%s:\t%s" % (point.timestamp.isoformat(), point.value)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement