Haproxy Statistics Report

修改Haproxy状态页中的流量信息

当前为 2016-10-27 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Haproxy Statistics Report
// @namespace    4e29d21a-e289-411d-9549-e2a8906a3cf1
// @version      2016.10.28
// @icon         http://www.haproxy.org/img/logo-med.png
// @description  修改Haproxy状态页中的流量信息
// @author       Dennis(tossp.com)
// @match        http://*/*
// @grant        none
// @require      https://cdn.bootcss.com/jquery/1.2.3/jquery.min.js
// ==/UserScript==


(function() {
    'use strict';
    if ($('h1 a').attr('href')=='http://www.haproxy.org/'){
        console.debug("init");
        $('table:gt(3) tbody tr td span.rls').each(function(k,v) {
            var inElem,outElem;
            if ($(v).parent().parent().children("td:eq(2)").attr('colspan')){
                inElem=$(v).parent().parent().children("td:eq(12)");
                outElem=$(v).parent().parent().children("td:eq(13)");
            }else{
                inElem=$(v).parent().parent().children("td:eq(14)");
                outElem=$(v).parent().parent().children("td:eq(15)");
            }
            //.css('background-color', '#20a0ff')
            inElem.html(size(inElem.text()));
            outElem.html(size(outElem.text()));
            //console.debug(size(inElem.text()),size(outElem.text()));
        });
        
    }
    
    function size(kb){
        var tmp = kb;
        if (tmp.indexOf('Response bytes')!=-1){
            tmp = tmp.substr(0,tmp.indexOf('Response bytes'));
        }
        if (!isNaN(tmp)&&parseInt(tmp)>0){
            if (tmp < 1024 ) {
                tmp = parseFloat(tmp).toFixed(2) + ' B';
            } else if ( tmp >= 1024 && tmp < 1048576 ) {
                tmp = parseFloat(tmp / 1024).toFixed(2) + ' Kb';
            }        else if ( tmp >= 1048576 && tmp < 1073741824 )        {
                tmp = parseFloat(tmp / (1024 * 1024)).toFixed(2) + ' Mb';
            }        else        {
                tmp = parseFloat(tmp / (1024 * 1024 * 1024)).toFixed(2) + ' Gb';
            }
        }else{
            return kb;
        }
        return tmp;


    }
    
})();