采用nodejs+phantom对grafana整个页面截图

把grafana整个页面定时保存为图片既方便发送邮件日报又方便存档。以下方式在grafana-6.6.1,phantom 6.3.0, nodejs 8.16.2上亲测可用。

1. 修改配置文件允许匿名访问(默认文件conf/defaults.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

2. nodejs调用phantom抓取页面,待渲染完毕再保存为图片

npm install phantom
var phantom = require('phantom');

phantom.create().then(function(ph) {
    ph.createPage().then(function(page) {
        page.open("http://127.0.0.1:3000/d/13-JkEQWz/example?orgId=1&from=now-24h&to=now-3m").then(function(status) {
            page.property('viewportSize', { width: 1920, height: 3580 });
           setTimeout(function(){
            page.render('./images/report.png').then(function() {
                console.log('Page rendered');
                ph.exit();
            });
           },30000);
        });
    });
});
发布了51 篇原创文章 · 获赞 3 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/pengpengzhou/article/details/104428951