index.html 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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. locations: [ <<< range.Locations >>> "<<< . >>>", <<< end >>> ],
  65. stat: "<<< .StatusDesc >>>",
  66. use_encryption: "<<< .UseEncryption >>>",
  67. use_gzip: "<<< .UseGzip >>>",
  68. privilege_mode: "<<< .PrivilegeMode >>>",
  69. times: [],
  70. ins: [],
  71. outs: [],
  72. conns: [],
  73. };
  74. <<< end >>>
  75. var newproxies = <<< . >>>;
  76. var dom1 = document.getElementById("view1");
  77. var dom2 = document.getElementById("view2");
  78. var myChart1 = echarts.init(dom1);
  79. var myChart2 = echarts.init(dom2);
  80. var option1 = null;
  81. var option2 = null;
  82. var maxval = 0;
  83. var dw = " B";
  84. var step = 1;
  85. function reloadview() {
  86. window.maxval = 0;
  87. window.dw = " B";
  88. window.step = 1;
  89. for (var val1 in alldata[index].ins) {
  90. if (maxval < alldata[index].ins[val1]) {
  91. window.maxval = alldata[index].outs[val1];
  92. }
  93. }
  94. for (var val2 in alldata[index].outs) {
  95. if (maxval < alldata[index].outs[val2]) {
  96. window.maxval = alldata[index].outs[val2]
  97. }
  98. }
  99. if (maxval > 1024 * 1024) {
  100. window.dw = " MB";
  101. window.step = 1024 * 1024;
  102. } else if (maxval > 1024) {
  103. window.dw = " KB";
  104. window.step = 1024;
  105. }
  106. window.option1 = {
  107. title: {
  108. text: alldata[index].name
  109. },
  110. tooltip: {
  111. trigger: 'axis'
  112. },
  113. legend: {
  114. data: ['flow_in', 'flow_out']
  115. },
  116. grid: {
  117. left: '3%',
  118. right: '6%',
  119. bottom: '3%',
  120. containLabel: true
  121. },
  122. toolbox: {
  123. feature: {
  124. saveAsImage: {}
  125. }
  126. },
  127. xAxis: {
  128. type: 'category',
  129. data: alldata[index].times
  130. },
  131. yAxis: {
  132. type: 'value',
  133. axisLabel: {
  134. formatter: function(value) {
  135. var data = (value / step).toFixed(2);
  136. return data + dw;
  137. }
  138. }
  139. },
  140. series: [{
  141. name: 'flow_in',
  142. type: 'bar',
  143. stack: '总量',
  144. data: alldata[index].ins
  145. }, {
  146. name: 'flow_out',
  147. type: 'bar',
  148. stack: '总量',
  149. data: alldata[index].outs
  150. }]
  151. };
  152. window.option2 = {
  153. title: {
  154. text: ""
  155. },
  156. tooltip: {
  157. trigger: 'axis'
  158. },
  159. legend: {
  160. data: ['total_accept_conns']
  161. },
  162. grid: {
  163. left: '3%',
  164. right: '6%',
  165. bottom: '3%',
  166. containLabel: true
  167. },
  168. toolbox: {
  169. feature: {
  170. saveAsImage: {}
  171. }
  172. },
  173. xAxis: {
  174. type: 'category',
  175. data: alldata[index].times
  176. },
  177. yAxis: {
  178. type: 'value'
  179. },
  180. series: [{
  181. name: 'total_accept_conns',
  182. type: 'bar',
  183. stack: '总量',
  184. data: alldata[index].conns
  185. }]
  186. };
  187. myChart1.setOption(option1, true);
  188. myChart2.setOption(option2, true);
  189. };;
  190. var showdetail = false;
  191. var newindex = 0;
  192. function cleandetail() {
  193. $(".info_detail").remove();
  194. showdetail = false;
  195. };
  196. function changeit(id) {
  197. newindex = id.firstElementChild.innerHTML;
  198. if (index == newindex) {
  199. if (showdetail) {
  200. cleandetail();
  201. return;
  202. }
  203. }
  204. index = newindex;
  205. cleandetail();
  206. window.showdetail = true;
  207. var newrow = "<tr class='info_detail'><th colspan='4'>Key</th><th colspan='4'>Val</th><tr>";
  208. for (var domainindex in alldata[index].domains) {
  209. newrow += "<tr class='info_detail'><td colspan='4'>Domains</td><td colspan='4'>" +
  210. alldata[index].domains[domainindex] + "</td><tr>";
  211. }
  212. for (var locindex in alldata[index].locations) {
  213. newrow += "<tr class='info_detail'><td colspan='4'>Locations</td><td colspan='4'>" +
  214. alldata[index].locations[locindex] + "</td><tr>";
  215. }
  216. newrow += "<tr class='info_detail'><td colspan='4'>Ip</td><td colspan='4'>" + alldata[index].bind_addr + "</td><tr>";
  217. newrow += "<tr class='info_detail'><td colspan='4'>Status</td><td colspan='4'>" + alldata[index].stat + "</td><tr>";
  218. newrow += "<tr class='info_detail'><td colspan='4'>Encryption</td><td colspan='4'>" + alldata[index].use_encryption + "</td><tr>";
  219. newrow += "<tr class='info_detail'><td colspan='4'>Gzip</td><td colspan='4'>" + alldata[index].use_gzip + "</td><tr>";
  220. newrow += "<tr class='info_detail'><td colspan='4'>Privilege</td><td colspan='4'>" + alldata[index].privilege_mode + "</td><tr>";
  221. var hehe = $(id.parentNode.parentNode);
  222. $(hehe).after(newrow);
  223. reloadview();
  224. };
  225. // add somedata
  226. {
  227. var ttdy = new Date();
  228. var today = ttdy.getFullYear() * 10000 + (1 + ttdy.getMonth()) * 100 + ttdy.getDate();
  229. for (var inx in newproxies) {
  230. if (newproxies[inx].current_conns == undefined) {
  231. newproxies[inx].current_conns = 0;
  232. alldata[newproxies[inx].name].current_conns = 0;
  233. }
  234. if (newproxies[inx].daily == undefined ) {
  235. newproxies[inx].daily = [];
  236. }
  237. newproxies[inx].daily.sort(function (a, b) {
  238. return a.time > b.time;
  239. });
  240. for (var iinnx in newproxies[inx].daily) {
  241. alldata[newproxies[inx].name].times.push(newproxies[inx].daily[iinnx].time);
  242. alldata[newproxies[inx].name].ins.push(newproxies[inx].daily[iinnx].flow_in);
  243. alldata[newproxies[inx].name].outs.push(newproxies[inx].daily[iinnx].flow_out);
  244. alldata[newproxies[inx].name].conns.push(newproxies[inx].daily[iinnx].total_accept_conns);
  245. }
  246. if (newproxies[inx].daily.length == 0 || newproxies[inx].daily[newproxies[inx].daily.length-1].time != today) {
  247. alldata[newproxies[inx].name].times.push(today);
  248. alldata[newproxies[inx].name].ins.push(0);
  249. alldata[newproxies[inx].name].outs.push(0);
  250. alldata[newproxies[inx].name].conns.push(0);
  251. newproxies[inx].daily.push({
  252. time: today,
  253. flow_in: 0,
  254. flow_out: 0,
  255. total_accept_conns: 0
  256. });
  257. }
  258. }
  259. }
  260. var app = angular.module('myTable', []);
  261. app.controller('myCtrl', function($scope) {
  262. $scope.col = 'name';
  263. $scope.desc = 0;
  264. $scope.proxies = newproxies;
  265. });
  266. $(".tab_info").hover(
  267. function() {
  268. $(this).css("color", "orange");
  269. },
  270. function() {
  271. $(this).css("color", "black");
  272. });
  273. // set default index
  274. for (var inx in alldata) {
  275. if (window.index == null || window.index > inx) {
  276. window.index = inx;
  277. }
  278. }
  279. reloadview();
  280. </script>
  281. </body>
  282. </html>