【问题标题】:Where can I find a machine readable query log for Athena?在哪里可以找到 Athena 的机器可读查询日志?
【发布时间】:2020-06-10 18:25:31
【问题描述】:

我面临的问题是,我的 AWS 成本报告显示 Athena 查询使用的数据比我预期的要多。在 AWS 控制台(Web UI)中,有一个可用的 Athena 历史记录显示扫描的数据。见截图:

我希望能够在更长的时间内访问此查询信息,以分析和优化我的 Athena 使用情况。如果需要,我也可以启用一些日志记录或监控服务。

我在哪里可以得到这个查询日志?

【问题讨论】:

    标签: database amazon-web-services logging amazon-athena


    【解决方案1】:

    我建议使用 AWS SDK,例如boto3 python 库。特别是需要结合

    下面是一个简单的示例,您的脚本可能如下所示:

    import boto3
    
    
    client = boto3.client('athena')
    
    response = client.list_query_executions()
    
    for query_id in response['QueryExecutionIds']:
        query_execution_response = client.get_query_execution(
            QueryExecutionId=query_id
        )
    
        query_string = query_execution_response['QueryExecution']['Query']
        query_exec_stats = query_execution_response['QueryExecution']['Statistics']
        query_data_scanned = query_exec_stats['DataScannedInBytes']
        query_exec_time = query_exec_stats['TotalExecutionTimeInMillis']
    
        print(f"=> Query id: {query_id}")
        print(f"Executed SQL statement: {query_string}")
        print(f"Total execution time: {query_exec_time}")
        print(f"Total data scanned: {query_data_scanned}")
    

    请注意,如果您运行了很多不同的查询,那么您最好使用paginator

    【讨论】:

    • 看起来很奇怪,不能单独使用 Athena,因为它看起来很明显。尽管如此,这个选项似乎和现在一样好。
    猜你喜欢
    • 2018-07-02
    • 1970-01-01
    • 2018-10-31
    • 2019-11-11
    • 2023-03-15
    • 1970-01-01
    • 2019-06-03
    • 1970-01-01
    • 2022-01-23
    相关资源
    最近更新 更多