新手=or≠菜鸟 2020-05-14 19:44 采纳率: 0%
浏览 232

Python代码转换成java需要,做java开发的,需要更改代码

Copyright © 1999-2020, CSDN.NET, All Rights Reserved

搜索博文/帖子/用户
登录
通过Spark Rest 服务监控Spark任务执行情况 转载
2017-09-07

buyaoxx

码龄3年

关注
1、Rest服务

  Spark源为了方便用户对任务做监控,从1.4版本启用Rest服务,用户可以通过访问地址,得到application的运行状态。

  Spark的REST API返回的信息是JSON格式的,开发者们可以很方便地通过这个API来创建可视化的Spark监控工具。目前

  这个API支持正在运行的应用程序,也支持历史服务器。在请求URL都有/api/v1。比如,对于历史服务器来说,我们可以通过
  http://***:18080/api/v1 来获取一些信息,端口可以改;对于正在运行的Spark应用程序,我们可以通过 https://***/api/v1
  来获取一些信息。

  主要用途: 通过rest服务,可以轻松对任务时长、stage等做监控,同时可以配合时间序列数据库,对集群各个任务做监控。
2、实例代码(Python)

  

1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 '''
4 Created by zhangy on Aug 25, 2017
5 '''
6 import datetime
7 import json, urllib2
8 import os
9 import time

10
11
12 if name == '__main__':
13 command = "yarn application -list |grep Noce |awk -F'\t' '{print $1}'"
14 val = os.popen(command).read()
15 appids = val.split("\n")
16 for pid in appids:
17 if pid.__eq__(""):continue
18 url = "http://th04-znwg-sgi620-001:18088/api/v1/applications/" + pid
19 req = urllib2.Request(url)
20 res_data = urllib2.urlopen(req)
21 res = res_data.read()
22 jo = json.loads(res)
23 dict1 = jo['attempts'][0]
24 st = dict1['startTime']
25 GMT_FORMAT = '%Y-%m-%dT%H:%M:%S.%fGMT'
26 sti = datetime.datetime.strptime(st, GMT_FORMAT)
27 startTime = time.mktime(sti.timetuple()) + 8 * 60 * 60
28 nowTime = long(time.time())
29 sub = nowTime - startTime
30 if sub > 4 * 60 * 60:
31 killCommand = "yarn application -kill " + pid
32 res = os.popen(killCommand ).read()
33        cc = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(float(nowTime)))
34        f = open("/home/noce1/run_noce/his/monitor/" + pid + ".txt", "a")
35        f.write(cc + " : " + "pid : " + "\n" + sub + " seconds")
36      f.write(res + "\n")
37      f.close()

  • 写回答

1条回答 默认 最新

  • 关注
    评论

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试