基于Yarn API的Spark程序监控

简介: 一.简述 通过对Yarn ResourceManager中运行程序的状态(RUNNING、KILLED、FAILED、FINISHED)以及ApplicationMaster中Application的Job执行时长超过批次时间的监控,来达到对Spark on Yarn程序的失败重启、超时重启等功能 二.

一.简述

基于对Yarn ResourceManager中运行程序的状态(RUNNING、KILLED、FAILED、FINISHED)以及ApplicationMaster中Application的Job执行时长超过批次时间的监控,来达到对Spark on Yarn程序的失败重启、超时重启等功能

二.Yarn主要的几类API

1.查询整个集群指标

GET http:// http address:port>/ws/v1/cluster/metrics

2.查询集群调度器详情

GET http:// http address:port>/ws/v1/cluster/scheduler

3.监控任务

curl 'http:// http address:port>/ws/v1/cluster/apps//state'
GET http:// http address:port>/ws/v1/cluster/apps//state

4.查看指定任务

GET http:// http address:port>/ws/v1/cluster/apps/

5.查看指定任务的详细信息

curl http:// http address:port>/proxy//ws/v2/mapreduce/info"

6.杀死任务

yarn application -kill application_id
curl -v -X PUT -d '{"state": "KILLED"}''http:// http address:port>/ws/v1/cluster/apps/'
PUT http:// http address:port>/ws/v1/cluster/apps//state

三.YarnMonitor

Ⅰ. Setup

1. install yarn-api-client

you mast install yarn-api-client when you use this yarn monitor

  • python setup.py build
  • python setup.py install

2. uninstall yarn-api-client

when you need uninstall this yarn-api-client model,use this

  • pip list
  • pip uninstall yarn-api-client

3. upate yarn-api-client

when you need update python model,you need unintall and update

  • update yarn-api-client
  • cp yarn-api-client/base.py base.py.bak

4. offline intall python model

when you need intall other python model,you can do this

  • pip freeze > yarn.txt
  • mkdir yarnpackage
  • pip install --no-index --find-links=yarnpackage/ -r yarn.txt

Ⅱ. Command

you should modify the script permissions

  • chmod 774 start_prmsbd.sh

Ⅲ. Crontab

configure crontab task

  • crontab -l
  • crontab -e

1.start yarn monitor

*/1 * * * * ../yarnmonitor/yarn-monitor/command/start_yarn_monitor.sh >> ../yarnmonitor/yarn-monitor/logs/yarn-corntab.log 2>&1 
* * * * * sleep 60; ../yarnmonitor/yarn-monitor/command/start_yarn_monitor.sh

2.clear yarn monitor log

0 4 * * * ../yarn-monitor/command/clear_log_opm.sh >> ../yarn-monitor/logs/yarn-corntab.log 2>&1

0 4 * * * ../yarnmonitor/yarn-monitor/command/clear_log_opm.sh >> ../yarnmonitor/yarn-monitor/logs/yarn-corntab.log 2>&1

Ⅳ. Just for test

1. start yarn command

../python ./yarn-monitor/YarnMonitor.py

2. Application_Master API

curl --compressed -H "Accept: application/json" -X GET "http://***:8088/ws/v1/cluster/apps"
curl --compressed -H "Accept: application/json" -X GET "http://***:8088/ws/v1/cluster/apps"
curl --compressed -H "Accept: application/json" -X GET "http://***:8088/proxy/application_1549963435527_0001/ws/v1/mapreduce/info"

curl --compressed -H "Accept: application/json" -X GET "http://***:8088/proxy/application_1535085750394_0017/ws/v1/mapreduce/info"
curl --compressed -H "Accept: application/json" -X GET "http://***:8088/proxy/application_1535085750394_0017/ws/v2/mapreduce/info"

curl --compressed -H "Accept: application/json" -X GET "http://***:8088/proxy/application_1535085750394_0017/ws/v1/mapreduce/jobs/4536"

curl --compressed -H "Accept: application/json" -X GET "http://***:8088/proxy/application_1548125170651_0090/api/v1/applications"

四.问题

其中,在ApplicationMaster中查询Job的返回数据无法转json的异常时,需修改yarn-api-client中修改对应API返回数据,可参考:

if 'ws/v1/mapreduce/info' in path:
            if response.status == OK:
                html_content = response.read()
                element_html = etree.HTML(html_content)
                tr_list = element_html.xpath('//tbody/tr')
                content_list = []
                for tr in tr_list:
                    item = {}
                    item['id'] = tr.xpath('./td[1]/text()')[0].replace('\n', '').strip()
                    item['duration'] = tr.xpath('./td[4]/text()')[0]
                    # 打印每条信息
                    # logging.info(item)
                    content_list.append(item)
                    # print content_list
                    return content_list
                response.close()
                return self.response_class(content_list)
            else:
                msg = 'Response finished with status: %s' % response.status
                raise APIError(msg)
目录
相关文章
|
SQL 分布式计算 资源调度
Dataphin功能Tips系列(48)-如何根据Hive SQL/Spark SQL的任务优先级指定YARN资源队列
如何根据Hive SQL/Spark SQL的任务优先级指定YARN资源队列
504 4
|
分布式计算 资源调度 Hadoop
Spark Standalone与YARN的区别?
本文详细解析了 Apache Spark 的两种常见部署模式:Standalone 和 YARN。Standalone 模式自带轻量级集群管理服务,适合小规模集群;YARN 模式与 Hadoop 生态系统集成,适合大规模生产环境。文章通过示例代码展示了如何在两种模式下运行 Spark 应用程序,并总结了两者的优缺点,帮助读者根据需求选择合适的部署模式。
800 3
|
分布式计算 资源调度 Hadoop
Spark Standalone与YARN的区别?
【10月更文挑战第5天】随着大数据处理需求的增长,Apache Spark 成为了广泛采用的大数据处理框架。本文详细解析了 Spark Standalone 与 YARN 两种常见部署模式的区别,并通过示例代码展示了如何在不同模式下运行 Spark 应用程序。Standalone 模式自带轻量级集群管理,适合小规模集群或独立部署;YARN 则作为外部资源管理器,能够与 Hadoop 生态系统中的其他应用共享资源,更适合大规模生产环境。文章对比了两者的资源管理、部署灵活性、扩展性和集成能力,帮助读者根据需求选择合适的部署模式。
429 1
|
消息中间件 分布式计算 Java
Linux环境下 java程序提交spark任务到Yarn报错
Linux环境下 java程序提交spark任务到Yarn报错
507 5
|
SQL 分布式计算 大数据
大数据-91 Spark 集群 RDD 编程-高阶 RDD广播变量 RDD累加器 Spark程序优化
大数据-91 Spark 集群 RDD 编程-高阶 RDD广播变量 RDD累加器 Spark程序优化
287 0
|
8月前
|
缓存 监控 前端开发
顺企网 API 开发实战:搜索 / 详情接口从 0 到 1 落地(附 Elasticsearch 优化 + 错误速查)
企业API开发常陷参数、缓存、错误处理三大坑?本指南拆解顺企网双接口全流程,涵盖搜索优化、签名验证、限流应对,附可复用代码与错误速查表,助你2小时高效搞定开发,提升响应速度与稳定性。
|
9月前
|
数据可视化 测试技术 API
从接口性能到稳定性:这些API调试工具,让你的开发过程事半功倍
在软件开发中,接口调试与测试对接口性能、稳定性、准确性及团队协作至关重要。随着开发节奏加快,传统方式已难满足需求,专业API工具成为首选。本文介绍了Apifox、Postman、YApi、SoapUI、JMeter、Swagger等主流工具,对比其功能与适用场景,并推荐Apifox作为集成度高、支持中文、可视化强的一体化解决方案,助力提升API开发与测试效率。
|
8月前
|
JSON 算法 API
Python采集淘宝商品评论API接口及JSON数据返回全程指南
Python采集淘宝商品评论API接口及JSON数据返回全程指南
|
8月前
|
JSON API 数据安全/隐私保护
Python采集淘宝拍立淘按图搜索API接口及JSON数据返回全流程指南
通过以上流程,可实现淘宝拍立淘按图搜索的完整调用链路,并获取结构化的JSON商品数据,支撑电商比价、智能推荐等业务场景。