grafana生成图片导出

https://grafana.com/docs/grafana/latest/administration/image_rendering/#image-rendering
对着官方文档,github。总算搞出来了。就是grafana的一个插件,可以把dashboard面板生成图片。昨天搞不出来,想用爬虫,害,结果访问一个页面返回全是js,然后本地渲染,不会爬这种网页,试了下不行。最后还是用的插件。插件弄好发现中文不能正常显示。最后看文档可以改字符。

  • 获取ubuntu版本镜像
    docker pull grafana/grafana:7.3.6-ubuntu

下载plugin-grafana安装包

ubuntu版本对插件比较友好

docker run -d --name=grafana -p 3000:3000 grafana/grafana:7.3.6-ubuntu

图表生成图像插件

方式1:进入grafana容器安装(中文字符还是乱码)

- 进入容器执行,先下载插件,放在本地nginx目录安装(远程太大)
/var/lib/grafana/plugins $ grafana-cli --debug --pluginUrl    http://192.168.191.128/saved-images/plugin-linux-x64-glibc.zip    plugins install grafana-image-renderer

#进入容器修改配置文件
docker exec -it --user root 4a309fde5c7e /bin/bash
vi /etc/grafana/grafana.ini
将rendering_language = zh字符改成zh;支持中文

安装成功后,日志报错需要在容器安装chrome依赖



docker logs 4a309fde5c7e
error while loading shared libraries: libX11.so.6: cannot open shared object file

  • 更新依赖(依赖报错,更新容器依赖)
apt update
apt install libx11-6 libx11-xcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrender1 libxtst6 libglib2.0-0 libnss3 libcups2  libdbus-1-3 libxss1 libxrandr2 libgtk-3-0 libgtk-3-0 libasound2

方式2:以另一个容器方式启动render image (可行)

https://grafana.com/docs/grafana/latest/administration/image_rendering/#image-rendering

#进入容器修改配置文件
docker exec -it --user root 4a309fde5c7e /bin/bash
vi /etc/grafana/grafana.ini
将rendering_language = zh字符改成zh;支持中文

根据官方文档所示,如果插件是独立运行的,需要在grafana.ini中配置插件地址。插件可以在github上git clone下来,使用docker build -t 构建镜像。

docker build -t  grafana-image .
docker exec -it --user root 4a309fde5c7e /bin/bash
vi /etc/grafana/grafana.ini

[rendering]
# https://github.com/grafana/grafana-image-renderer.
server_url = http://192.168.191.128:8081/render
callback_url = http://192.168.191.128:3000/
将rendering_language = zh字符改成zh;支持中文
#重启容器

方式3:不行

lanyonm/grafana-images: Interacts with Grafana and hubot-grafana to provide facility to copy/save Grafana panel images

  • 安装go编译的软件
  • grafana生成apikey

curl -d '{"imageUrl":"http://192.168.191.128:3000/d/WojOgXTmk/prometheus-alertmanager?viewPanel=4&orgId=1&from=1609663842748&to=1609685442748"}' -H "Accept: application/json" -H "Authorization: Bearer eyJrIjoidWZlRmZIQm5yU1VxOTR3RzdGZmFrM1ZmelZwWENtNVoiLCJuIjoienhoeSIsImlkIjoxfQ==" http://192.168.191.128:8080/grafana-images

1.  Clone the [Grafana image renderer plugin---github上找](https://grafana.com/grafana/plugins/grafana-image-renderer) Git repository.

2.  Install dependencies and build:

    yarn install --pure-lockfile
    yarn run build
    Bash

3.  Run the server:
    node build/app.js server --port=8081

    Bash

4.  Update Grafana configuration:
    [rendering]
    server_url = http://localhost:8081/render
    callback_url = http://localhost:3000/

5.  Restart Grafana.

PhantomJS

alertmanager数据源插件

grafana-cli plugins install camptocamp-prometheus-alertmanager-datasource
  • root用户进入容器
    docker exec -it --user root /bin/bash

grafana-reporter,导出pdf

yum install go
yum install git
yum install texlive-latex
go get github.com/IzakMarais/reporter/...
go install -v github.com/IzakMarais/reporter/cmd/grafana-reporter
go/bin/grafana-reporter -ip ip:8686 (会开启8686端口)


#grafana.ini
编辑/etc/grafana下的grafana.ini文件
#################################### Anonymous Auth ######################
[auth.anonymous]
# enable anonymous access
enabled = true
 
# specify organization name that should be used for unauthenticated users
;org_name = Main Org.
 
# specify role for unauthenticated users
org_role = Viewer

参考博客

node.js - Can't Use Puppeteer -- Error: Failed to launch chrome - Stack Overflow

Image rendering | Grafana Labs

未完待续

你可能感兴趣的:(grafana生成图片导出)