【问题标题】:How to check for Jupyter active notebooks through command line如何通过命令行检查 Jupyter 活动笔记本
【发布时间】:2021-02-12 13:47:03
【问题描述】:

我有一个运行 Jupyterhub 版本 0.8.1+ 的 AWS EMR,我想检查是否有任何活动的笔记本正在运行任何代码。 我尝试了以下命令,但它们似乎没有输出我在此处查找的内容,因为用户服务器始终在运行,并且笔记本可以在不执行任何代码的情况下运行。

# only lists running servers and jovyan is always running.
sudo docker exec jupyterhub jupyter notebook list
# No useful information outputted
curl -k -i -H "Accept: application/json" "https://localhost:9443/api/sessions"
# always lists processes regardless of running notebooks
ps aux | grep ipykernel
# The last_activity only updates when a user creates a new file or folder in the ui.
curl -k https://localhost:9443/hub/api/users/$user -H "Authorization: token $admin_token" | jq -r .last_activity
curl -k https://localhost:9443/hub/api/users -H "Authorization: token $admin_token" | jq -r .last_activity

我正在关注这个 AWS 博客,以在终止集群之前检查整个 EMR 是否处于空闲状态,但他们似乎从未完全实施过 jupyter 检查。 https://aws.amazon.com/blogs/big-data/optimize-amazon-emr-costs-with-idle-checks-and-automatic-resource-termination-using-advanced-amazon-cloudwatch-metrics-and-aws-lambda/ 大部分引用的文件都可以在 Github 找到https://github.com/septian-putra/emr-monitoring

【问题讨论】:

    标签: amazon-web-services jupyter-notebook jupyter amazon-emr


    【解决方案1】:

    要查看笔记本是否因“忙”而“空闲”,您可以运行curl -ks https://localhost:9443/user/jovyan/api/kernels -H "Authorization: token ${admin_token}" 使用此命令,您只需将其放入带有 grep -q 的简单 if 语句中,以获得真假空闲值。

    if [ $(curl -ks https://localhost:9443/user/jovyan/api/kernels -H "Authorization: token ${admin_token}" | grep -q "busy") ]; then
        JUPYTER_BUSY_NOTEBOOKS=1
    else
        JUPYTER_BUSY_NOTEBOOKS=0
    fi
    

    (curl -ks 用于静默输出并忽略 ssl.jovyan 作为我的管理员用户)

    文档 https://jupyter-kernel-gateway.readthedocs.io/en/latest/websocket-mode.html#http-resources /api/sessions 也可能有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-22
      • 2020-08-26
      • 2020-10-12
      相关资源
      最近更新 更多