index.html 10 KB

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