Haproxy Statistics Report

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

目前为 2016-10-27 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Haproxy Statistics Report
  3. // @namespace 4e29d21a-e289-411d-9549-e2a8906a3cf1
  4. // @version 2016.10.27
  5. // @icon http://www.haproxy.org/img/logo-med.png
  6. // @description 修改Haproxy状态页中的流量信息
  7. // @author Dennis(tossp.com)
  8. // @match http://*/*
  9. // @grant none
  10. // @require https://cdn.bootcss.com/jquery/1.2.3/jquery.min.js
  11. // ==/UserScript==
  12.  
  13.  
  14. (function() {
  15. 'use strict';
  16. if ($('h1 a').attr('href')=='http://www.haproxy.org/'){
  17. console.debug("init");
  18. $('table:gt(3) tbody tr td span.rls').each(function(k,v) {
  19. var inElem,outElem;
  20. if ($(v).parent().parent().children("td:eq(2)").attr('colspan')){
  21. inElem=$(v).parent().parent().children("td:eq(12)");
  22. outElem=$(v).parent().parent().children("td:eq(13)");
  23. }else{
  24. inElem=$(v).parent().parent().children("td:eq(14)");
  25. outElem=$(v).parent().parent().children("td:eq(15)");
  26. }
  27. //.css('background-color', '#20a0ff')
  28. inElem.html(size(inElem.text()));
  29. outElem.html(size(outElem.text()));
  30. //console.debug(size(inElem.text()),size(outElem.text()));
  31. });
  32. }
  33. function size(kb){
  34. var tmp = kb;
  35. if (tmp.indexOf('Response bytes')!=-1){
  36. tmp = tmp.substr(0,tmp.indexOf('Response bytes'));
  37. }
  38. if (!isNaN(tmp)&&parseInt(tmp)>0){
  39. if (tmp < 1024 ) {
  40. tmp = parseFloat(tmp).toFixed(2) + ' B';
  41. } else if ( tmp >= 1024 && tmp < 1048576 ) {
  42. tmp = parseFloat(tmp / 1024).toFixed(2) + ' Kb';
  43. } else if ( tmp >= 1048576 && tmp < 1073741824 ) {
  44. tmp = parseFloat(tmp / (1024 * 1024)).toFixed(2) + ' Mb';
  45. } else {
  46. tmp = parseFloat(tmp / (1024 * 1024 * 1024)).toFixed(2) + ' Gb';
  47. }
  48. }else{
  49. return kb;
  50. }
  51. return tmp;
  52.  
  53.  
  54. }
  55. })();