Haproxy状态页强化

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

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

  1. // ==UserScript==
  2. // @name Haproxy状态页强化
  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. function size(kb){
  14. var tmp = kb;
  15. if (tmp.indexOf('Response bytes')!=-1){
  16. tmp = tmp.substr(0,tmp.indexOf('Response bytes'));
  17. }
  18. if (!isNaN(tmp)&&parseInt(tmp)>0){
  19. if (tmp < 1024 ) {
  20. tmp = parseFloat(tmp).toFixed(2) + ' B';
  21. } else if ( tmp >= 1024 && tmp < 1048576 ) {
  22. tmp = parseFloat(tmp / 1024).toFixed(2) + ' Kb';
  23. } else if ( tmp >= 1048576 && tmp < 1073741824 ) {
  24. tmp = parseFloat(tmp / (1024 * 1024)).toFixed(2) + ' Mb';
  25. } else {
  26. tmp = parseFloat(tmp / (1024 * 1024 * 1024)).toFixed(2) + ' Gb';
  27. }
  28. }else{
  29. return kb;
  30. }
  31. return tmp;
  32.  
  33.  
  34. }
  35. (function() {
  36. 'use strict';
  37. if ($('h1 a').attr('href')=='http://www.haproxy.org/'){
  38. console.debug("init");
  39. $('table:gt(3) tbody tr td span.rls').each(function(k,v) {
  40. var inElem,outElem;
  41. if ($(v).parent().parent().children("td:eq(2)").attr('colspan')){
  42. inElem=$(v).parent().parent().children("td:eq(12)");
  43. outElem=$(v).parent().parent().children("td:eq(13)");
  44. }else{
  45. inElem=$(v).parent().parent().children("td:eq(14)");
  46. outElem=$(v).parent().parent().children("td:eq(15)");
  47. }
  48. //.css('background-color', '#20a0ff')
  49. inElem.html(size(inElem.text()));
  50. outElem.html(size(outElem.text()));
  51. //console.debug(size(inElem.text()),size(outElem.text()));
  52. });
  53. }
  54. })();