Skip to main content

No project description provided

Project description

概述

使用无头浏览器来截图 Grafana 页面实现渲染仪表盘图像的目的。

安装

环境需要 playwright 或者远程 playwright

pip instll playwright py-grafana-render
playwright install
playwright install-dev

使用

在你的代码中引用:

from py_grafana_render import GrafanaRender

# 此处传入 Grafana 服务账户的 Token
gf = GrafanaRender(token="<your-grafana-service-token>", browser="firefox")

gf_ws = GrafanaRender(token="<your-grafana-service-token>", browser="firefox", remote_browser_ws = "ws://<your-host>:port")

# 本地安装了 playwright 浏览器
image_bytes = gf.snapshot(
    url="https://<your-domain>/d/<dashboard-uid>?xxx=xxx&kiosk",
    file_path="./test.png"
)

# 获取仪表盘信息
dashboard_info = gf.get_dashboard_info(
    url="https://<your-domain>/d/<dashboard-uid>"
)

参数说明

GrafanaRender
参数名 必填 类型 默认值 说明
token str Grafana 服务账户的 Token
browser str firefox 使用的无头浏览器,可选值:
- chrome
- firefox
snapshot

参数:

参数名 必填 类型 默认值 说明
url str Grafana 的页面,可以包含查询字符串,不限仪表盘或面板。
width int 762 截图宽度。
height int 300 截图高度。若开启自动高度,则仪表盘将使用自动高度。
auto_height bool True 自动获取实际高度,如果无法自动获取,仅会使用默认高度。面板不会自动获取高度。
auto_height_offset int 150 自动获取的高度,会因为存在顶部筛选器导致误差,使用该值对自动高度进行一定偏移。
hide_class list None 隐藏的样式选择器列表,比如 .css-k3l5qq 是 v11.3.1 的顶部筛选器栏。
filetype str png 可选 png 或 jpeg
file_path str None 截图文件保存路径,需要包括文件名的完整路径。可以不传入,获取返回的字节流后自行保存。

返回:

  • 图片字节流:bytes 当不传入 file_path 时,可以自行存储字节流,比如发送到 s3 存储等。

提示: 若希望全屏,需要自行在 url 中加入 kiosk 查询字符串。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_grafana_render-0.1.4.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_grafana_render-0.1.4-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file py_grafana_render-0.1.4.tar.gz.

File metadata

  • Download URL: py_grafana_render-0.1.4.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for py_grafana_render-0.1.4.tar.gz
Algorithm Hash digest
SHA256 9efaa2c1bd80e63a6260b992d9f99268c56e5de307517359663cab9ebf2fb027
MD5 53881366e09a0b35a167fed6cf1e0580
BLAKE2b-256 bfb026661c3ac60026da3dbc9f08418a5556fff70ad45daad717a70797f8963a

See more details on using hashes here.

File details

Details for the file py_grafana_render-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for py_grafana_render-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 bd17e86c96f5a3405f7865380eea2de7a65c0fe6323e18fd181d5cd9a0866825
MD5 62153096c2132b6f3b2ab74e7700c02b
BLAKE2b-256 e43701bf2598f6950ba1ee1665901aca6ffd13f7312cc06ef39da8a873a8b1a2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page