简体   繁体   English

如何让我的 Grafana iframe 加载得更快?

[英]How can I make my Grafana iframes load faster?

I embeded 12 Grafana charts via iframe into my page我通过 iframe 将 12 个 Grafana 图表嵌入到我的页面中

It take about ~ 21 seconds to load the page.加载页面大约需要21秒。

This same dashboard take on 3 seconds if I load it on the Grafana's site itself.如果我将它加载到 Grafana 的网站本身,这个相同的仪表板需要 3 秒钟。

This is how I embedded it:这是我嵌入它的方式:

ajax.done(function (titles) {

// console.log('%c titles = ' + titles, "color: green;");

for (var i = 0; i < titles.length; i++) {

    var data         = {};
    data.sessionName = "{{ $sessionName }}";
    data.type        = "{{ $type }}";
    data.title       = titles[i];

    // console.log(JSON.stringify(data));

    $.ajax({
        method: 'POST',
        url: `/graphs/chartsBaseOnTitle`,
        crossDomain: true,
        contentType: false,
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('value'),
            "Accept": "application/json",
            "Content-Type": "application/x-www-form-urlencoded",
            "Cache-Control": "no-cache"
        },
        data: data,
        success: function(charts){

            // console.log('charts = ', charts);

            for (var i = 0; i < charts.length; i++) {

                var title     = charts[i].accordionTitle.replace(" ", "");
                var iFrameUrl = charts[i].iFrameUrl;
                var colSize   = 12/charts.length;

                var iframe = `
                <div class="col-sm-${colSize}">
                <iframe async id="${title}" src="${iFrameUrl}" width="100%" height="451px" frameborder="0"></iframe>
                </div>
                `;

                $('div#'+title).append(iframe);

                console.log('%c title = ' + title, "color: green;");

            }


        },
        error: function(jqXHR, textStatus, errorThrown) {
            console.log(JSON.stringify(jqXHR));
            console.log("AJAX error: " + textStatus + ' : ' + errorThrown);
        }
    });



}
});

What can I do different to reduce this huge latency ?我可以做些什么来减少这种巨大的延迟?

58.1 MB transferred - that's because you have 12 iframes = 12 Grafana windows and each iframe loads the same static files again and again: 58.1 MB transferred - 那是因为您有 12 个 iframe = 12 个 Grafana 窗口,并且每个 iframe 一次又一次地加载相同的静态文件:

  • you may try to enable enable_gzip Grafana config您可以尝试启用enable_gzip Grafana 配置
  • ads proper cache headers to static Grafana resources, so they will be cached in the browser and they don't need to be redownloaded again and again - you may need reverse proxy in front of Grafana for that向静态 Grafana 资源广告适当的缓存标头,因此它们将被缓存在浏览器中,并且不需要一次又一次地重新下载 - 为此您可能需要在 Grafana 前面进行反向代理
  • enable http2 protocol - you may need reverse proxy in front of Grafana for that启用 http2 协议 - 为此,您可能需要在 Grafana 前面进行反向代理

You may also to create first iframe and other iframes creates only when first iframe is loaded (or adds static delay).您也可以创建第一个 iframe,其他 iframe 仅在加载第一个 iframe 时创建(或添加静态延迟)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM