index.html 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>frp</title>
  5. <link href="static/css/bootstrap.min.css" rel="stylesheet">
  6. <link href="static/css/iconfont.css" rel="stylesheet">
  7. <script src="static/js/jquery.min.js"></script>
  8. <script src="static/js/bootstrap.min.js"></script>
  9. </head>
  10. <body>
  11. <div class="container" style="margin-top: 80px">
  12. <div class="row">
  13. <div class="col-md-7">
  14. <div class="panel panel-default">
  15. <div ng-app="myTable" class="panel-body">
  16. <table class="table table-bordered" ng-app="myTable" ng-controller="myCtrl">
  17. <thead>
  18. <tr>
  19. <th class="tab_info" ng-click="col='name';desc=!desc">Server<i class="iconfont pull-right">&#xe66d;</i></th>
  20. <th class="tab_info" ng-click="col='type';desc=!desc">Type<i class="iconfont pull-right">&#xe66d;</i></th>
  21. <th class="tab_info" ng-click="col='listen_port';desc=!desc">Port<i class="iconfont pull-right">&#xe66d;</i></th>
  22. <th class="tab_info" ng-click="col='status';desc=!desc">Status<i class="iconfont pull-right">&#xe66d;</i></th>
  23. <th class="tab_info" ng-click="col='current_conns';desc=!desc">CurCon<i class="iconfont pull-right">&#xe66d;</i></th>
  24. <th class="tab_info" ng-click="col='daily[daily.length-1].flow_out';desc=!desc">FlowOut<i class="iconfont pull-right">&#xe66d;</i></th>
  25. <th class="tab_info" ng-click="col='daily[daily.length-1].flow_in';desc=!desc">FlowIn<i class="iconfont pull-right">&#xe66d;</i></th>
  26. </tr>
  27. </thead>
  28. <tbody id="tab_body">
  29. <tr ng-repeat="x in proxies|orderBy:col:desc">
  30. <td>
  31. <button class="btn btn-xs btn-block btn-success center-block" onclick="changeit(this)"><span ng-bind="x.name"></span></button>
  32. </td>
  33. <td><span ng-bind="x.type"></span></td>
  34. <td><span ng-bind="x.listen_port"></span></td>
  35. <td><span ng-bind="x.status"></span></td>
  36. <td><span ng-bind="x.current_conns"></span></td>
  37. <td><span ng-bind="x.daily[x.daily.length-1].flow_out"></span></td>
  38. <td><span ng-bind="x.daily[x.daily.length-1].flow_in"></span></td>
  39. </tr>
  40. </tbody>
  41. </table>
  42. </div>
  43. </div>
  44. </div>
  45. <div class="col-md-5">
  46. <div id="view1" style="height: 300pt"></div>
  47. <div id="view2" style="height: 300pt"></div>
  48. </div>
  49. </div>
  50. </div>
  51. <script src="static/js/angular.min.js"></script>
  52. <script type="text/javascript" src="static/js/echarts.min.js"></script>
  53. <script>
  54. var alldata = new Array();
  55. var index = null;
  56. <<< range .>>>
  57. alldata["<<< .Name >>>"] = {
  58. name: "<<< .Name >>>",
  59. type: "<<< .Type >>>",
  60. bind_addr: "<<< .BindAddr >>>",
  61. listen_port: "<<< .ListenPort >>>",
  62. current_conns: <<< .CurrentConns >>> ,
  63. domains: [ <<< range.CustomDomains >>> "<<< . >>>", <<< end >>> ],
  64. stat: "<<< .Status >>>",
  65. use_encryption: "<<< .UseEncryption >>>",
  66. use_gzip: "<<< .UseGzip >>>",
  67. privilege_mode: "<<< .PrivilegeMode >>>",
  68. times: [],
  69. ins: [],
  70. outs: [],
  71. conns: [],
  72. };
  73. <<< end >>>
  74. var newproxies = <<< . >>>;
  75. var dom1 = document.getElementById("view1");
  76. var dom2 = document.getElementById("view2");
  77. var myChart1 = echarts.init(dom1);
  78. var myChart2 = echarts.init(dom2);
  79. var option1 = null;
  80. var option2 = null;
  81. var maxval = 0;
  82. var dw = " B";
  83. var step = 1;
  84. function reloadview() {
  85. window.maxval = 0;
  86. window.dw = " B";
  87. window.step = 1;
  88. for (var val1 in alldata[index].ins) {
  89. if (maxval < alldata[index].ins[val1]) {
  90. window.maxval = alldata[index].outs[val1];
  91. }
  92. }
  93. for (var val2 in alldata[index].outs) {
  94. if (maxval < alldata[index].outs[val2]) {
  95. window.maxval = alldata[index].outs[val2]
  96. }
  97. }
  98. if (maxval > 1024 * 1024) {
  99. window.dw = " MB";
  100. window.step = 1024 * 1024;
  101. } else if (maxval > 1024) {
  102. window.dw = " KB";
  103. window.step = 1024;
  104. }
  105. window.option1 = {
  106. title: {
  107. text: alldata[index].name
  108. },
  109. tooltip: {
  110. trigger: 'axis'
  111. },
  112. legend: {
  113. data: ['flow_in', 'flow_out']
  114. },
  115. grid: {
  116. left: '3%',
  117. right: '6%',
  118. bottom: '3%',
  119. containLabel: true
  120. },
  121. toolbox: {
  122. feature: {
  123. saveAsImage: {}
  124. }
  125. },
  126. xAxis: {
  127. type: 'category',
  128. data: alldata[index].times
  129. },
  130. yAxis: {
  131. type: 'value',
  132. axisLabel: {
  133. formatter: function(value) {
  134. var data = (value / step).toFixed(2);
  135. return data + dw;
  136. }
  137. }
  138. },
  139. series: [{
  140. name: 'flow_in',
  141. type: 'bar',
  142. stack: '总量',
  143. data: alldata[index].ins
  144. }, {
  145. name: 'flow_out',
  146. type: 'bar',
  147. stack: '总量',
  148. data: alldata[index].outs
  149. }]
  150. };
  151. window.option2 = {
  152. title: {
  153. text: ""
  154. },
  155. tooltip: {
  156. trigger: 'axis'
  157. },
  158. legend: {
  159. data: ['total_accept_conns']
  160. },
  161. grid: {
  162. left: '3%',
  163. right: '6%',
  164. bottom: '3%',
  165. containLabel: true
  166. },
  167. toolbox: {
  168. feature: {
  169. saveAsImage: {}
  170. }
  171. },
  172. xAxis: {
  173. type: 'category',
  174. data: alldata[index].times
  175. },
  176. yAxis: {
  177. type: 'value'
  178. },
  179. series: [{
  180. name: 'total_accept_conns',
  181. type: 'bar',
  182. stack: '总量',
  183. data: alldata[index].conns
  184. }]
  185. };
  186. myChart1.setOption(option1, true);
  187. myChart2.setOption(option2, true);
  188. };;
  189. var showdetail = false;
  190. var newindex = 0;
  191. function cleandetail() {
  192. $(".info_detail").remove();
  193. showdetail = false;
  194. };
  195. function changeit(id) {
  196. newindex = id.firstElementChild.innerHTML;
  197. if (index == newindex) {
  198. if (showdetail) {
  199. cleandetail();
  200. return;
  201. }
  202. }
  203. index = newindex;
  204. cleandetail();
  205. window.showdetail = true;
  206. var newrow = "<tr class='info_detail'><th colspan='4'>Key</th><th colspan='4'>Val</th><tr>";
  207. for (var domainindex in alldata[index].domains) {
  208. newrow += "<tr class='info_detail'><td colspan='4'>Domains</td><td colspan='4'>" +
  209. alldata[index].domains[domainindex] + "</td><tr>";
  210. }
  211. newrow += "<tr class='info_detail'><td colspan='4'>Ip</td><td colspan='4'>" + alldata[index].bind_addr + "</td><tr>";
  212. newrow += "<tr class='info_detail'><td colspan='4'>Status</td><td colspan='4'>" + alldata[index].stat + "</td><tr>";
  213. newrow += "<tr class='info_detail'><td colspan='4'>Encryption</td><td colspan='4'>" + alldata[index].use_encryption + "</td><tr>";
  214. newrow += "<tr class='info_detail'><td colspan='4'>Gzip</td><td colspan='4'>" + alldata[index].use_gzip + "</td><tr>";
  215. newrow += "<tr class='info_detail'><td colspan='4'>Privilege</td><td colspan='4'>" + alldata[index].privilege_mode + "</td><tr>";
  216. var hehe = $(id.parentNode.parentNode);
  217. $(hehe).after(newrow);
  218. reloadview();
  219. };
  220. // add somedata
  221. {
  222. var ttdy = new Date();
  223. var today = ttdy.getFullYear() * 10000 + (1 + ttdy.getMonth()) * 100 + ttdy.getDate();
  224. for (var inx in newproxies) {
  225. if (newproxies[inx].current_conns == undefined) {
  226. newproxies[inx].current_conns = 0;
  227. alldata[newproxies[inx].name].current_conns = 0;
  228. }
  229. if (newproxies[inx].daily == undefined ) {
  230. newproxies[inx].daily = [];
  231. }
  232. newproxies[inx].daily.sort(function (a, b) {
  233. return a.time > b.time;
  234. });
  235. for (var iinnx in newproxies[inx].daily) {
  236. alldata[newproxies[inx].name].times.push(newproxies[inx].daily[iinnx].time);
  237. alldata[newproxies[inx].name].ins.push(newproxies[inx].daily[iinnx].flow_in);
  238. alldata[newproxies[inx].name].outs.push(newproxies[inx].daily[iinnx].flow_out);
  239. alldata[newproxies[inx].name].conns.push(newproxies[inx].daily[iinnx].total_accept_conns);
  240. }
  241. if (newproxies[inx].daily.length == 0 || newproxies[inx].daily[newproxies[inx].daily.length-1].time != today) {
  242. alldata[newproxies[inx].name].times.push(today);
  243. alldata[newproxies[inx].name].ins.push(0);
  244. alldata[newproxies[inx].name].outs.push(0);
  245. alldata[newproxies[inx].name].conns.push(0);
  246. newproxies[inx].daily.push({
  247. time: today,
  248. flow_in: 0,
  249. flow_out: 0,
  250. total_accept_conns: 0
  251. });
  252. }
  253. }
  254. }
  255. var app = angular.module('myTable', []);
  256. app.controller('myCtrl', function($scope) {
  257. $scope.col = 'name';
  258. $scope.desc = 0;
  259. $scope.proxies = newproxies;
  260. });
  261. $(".tab_info").hover(
  262. function() {
  263. $(this).css("color", "orange");
  264. },
  265. function() {
  266. $(this).css("color", "black");
  267. });
  268. // set default index
  269. for (var inx in alldata) {
  270. if (window.index == null || window.index > inx) {
  271. window.index = inx;
  272. }
  273. }
  274. reloadview();
  275. </script>
  276. </body>
  277. </html>