本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
监控 Python Kinesis Data Analytics 应用程序
你使用你的应用程序CloudWatch登录以监控 Python Kinesis Data Analytics 应用程序。
Kinesis Data Analytics 记录 Python 应用程序的以下消息:
使用写入控制台的消息
print()
在应用程序的main
方法。使用用户定义的函数发送的消息
logging
程序包。以下代码示例演示了从用户定义的函数写入应用程序日志的操作:import logging @udf(input_types=[DataTypes.BIGINT()], result_type=DataTypes.BIGINT()) def doNothingUdf(i): logging.info("Got {} in the doNothingUdf".format(str(i))) return i
应用程序抛出的错误消息。
如果应用程序在
main
函数,它将出现在应用程序的日志中。以下示例演示了从 Python 代码抛出的异常的日志条目:
2021-03-15 16:21:20.000 --------------------------- Python Process Started -------------------------- 2021-03-15 16:21:21.000 Traceback (most recent call last): 2021-03-15 16:21:21.000 " File ""/tmp/flink-web-6118109b-1cd2-439c-9dcd-218874197fa9/flink-web-upload/4390b233-75cb-4205-a532-441a2de83db3_code/PythonKinesisSink/PythonUdfUndeclared.py"", line 101, in <module>" 2021-03-15 16:21:21.000 main() 2021-03-15 16:21:21.000 " File ""/tmp/flink-web-6118109b-1cd2-439c-9dcd-218874197fa9/flink-web-upload/4390b233-75cb-4205-a532-441a2de83db3_code/PythonKinesisSink/PythonUdfUndeclared.py"", line 54, in main" 2021-03-15 16:21:21.000 " table_env.register_function(""doNothingUdf"", doNothingUdf)" 2021-03-15 16:21:21.000 NameError: name 'doNothingUdf' is not defined 2021-03-15 16:21:21.000 --------------------------- Python Process Exited --------------------------- 2021-03-15 16:21:21.000 Run python process failed 2021-03-15 16:21:21.000 Error occurred when trying to start the job
由于性能问题,我们建议您只在应用程序开发期间使用自定义日志消息。
使用查询日志CloudWatch见解
以下CloudWatchInsights 查询会在执行应用程序的主要功能时搜索 Python 入口点创建的日志:
fields @timestamp, message | sort @timestamp asc | filter logger like /PythonDriver/ | limit 1000