showlog.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. function getData(filename){
  2. $.get("../../tmp/log/"+filename,
  3. function(data,status){
  4. //生成数据数组
  5. let rowData= data.split('\n');
  6. let arrData = new Array();
  7. for (const iterator of rowData) {
  8. arrData.push(iterator.split(","));
  9. }
  10. console.log(arrData);
  11. let api = new Object;
  12. let delayInMinute
  13. //遍历所有数据
  14. for (const iterator of arrData) {
  15. if (api.hasOwnProperty.call(api, iterator[0])) {
  16. let element = api[iterator[0]];
  17. element.times++;
  18. element.delay += parseInt(iterator[2]);
  19. try{
  20. let hour = parseInt(iterator[1].split(':')[0]);
  21. element.delayHour[hour] += parseInt(iterator[2]);
  22. element.timesHour[hour] ++;
  23. }catch(e){
  24. }
  25. }else{
  26. api[iterator[0]] = {
  27. times:1,
  28. timesHour:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
  29. delay:parseInt(iterator[2]),
  30. delayHour:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
  31. };
  32. try{
  33. let hour = parseInt(iterator[1].split(':')[0]);
  34. api[iterator[0]].delayHour[hour] = parseInt(iterator[2]);
  35. api[iterator[0]].timesHour[hour] = 1;
  36. }catch(e){
  37. }
  38. }
  39. }
  40. let api_timms = new Array();
  41. let api_delay = new Array();
  42. let ApiDelayInHour = new Array();
  43. let ApiTimesInHour = new Array();
  44. for (const key in api) {
  45. if (Object.hasOwnProperty.call(api, key)) {
  46. const element = api[key];
  47. api_timms.push({
  48. name:key,
  49. y:element.times
  50. });
  51. api_delay.push({
  52. name:key,
  53. y:element.delay
  54. });
  55. ApiDelayInHour.push({
  56. name:key,
  57. data:element.delayHour
  58. });
  59. ApiTimesInHour.push({
  60. name:key,
  61. data:element.timesHour
  62. })
  63. }
  64. }
  65. chart_1(api_timms);
  66. chart_2(api_delay);
  67. chart_3(ApiDelayInHour);
  68. chart_4(ApiTimesInHour);
  69. });
  70. }
  71. function chart_1(data){
  72. // Make monochrome colors
  73. var pieColors = (function () {
  74. var colors = [],
  75. base = Highcharts.getOptions().colors[0],
  76. i;
  77. for (i = 0; i < 10; i += 1) {
  78. // Start out with a darkened base color (negative brighten), and end
  79. // up with a much brighter color
  80. colors.push(Highcharts.color(base).brighten((i - 3) / 7).get());
  81. }
  82. return colors;
  83. }());
  84. // Build the chart
  85. Highcharts.chart('chart-1', {
  86. chart: {
  87. plotBackgroundColor: null,
  88. plotBorderWidth: null,
  89. plotShadow: false,
  90. type: 'pie'
  91. },
  92. title: {
  93. text: 'API 执行次数'
  94. },
  95. tooltip: {
  96. pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
  97. },
  98. accessibility: {
  99. point: {
  100. valueSuffix: '%'
  101. }
  102. },
  103. plotOptions: {
  104. pie: {
  105. allowPointSelect: true,
  106. cursor: 'pointer',
  107. colors: pieColors,
  108. dataLabels: {
  109. enabled: true,
  110. format: '<b>{point.name}</b><br>{point.percentage:.1f} %',
  111. distance: -50,
  112. filter: {
  113. property: 'percentage',
  114. operator: '>',
  115. value: 4
  116. }
  117. }
  118. }
  119. },
  120. series: [{
  121. name: 'Share',
  122. data: data
  123. }]
  124. });
  125. }
  126. function chart_2(data){
  127. // Make monochrome colors
  128. var pieColors = (function () {
  129. var colors = [],
  130. base = Highcharts.getOptions().colors[0],
  131. i;
  132. for (i = 0; i < 10; i += 1) {
  133. // Start out with a darkened base color (negative brighten), and end
  134. // up with a much brighter color
  135. colors.push(Highcharts.color(base).brighten((i - 3) / 7).get());
  136. }
  137. return colors;
  138. }());
  139. // Build the chart
  140. Highcharts.chart('chart-2', {
  141. chart: {
  142. plotBackgroundColor: null,
  143. plotBorderWidth: null,
  144. plotShadow: false,
  145. type: 'pie'
  146. },
  147. title: {
  148. text: 'API 累积执行时间'
  149. },
  150. tooltip: {
  151. pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
  152. },
  153. accessibility: {
  154. point: {
  155. valueSuffix: '%'
  156. }
  157. },
  158. plotOptions: {
  159. pie: {
  160. allowPointSelect: true,
  161. cursor: 'pointer',
  162. colors: pieColors,
  163. dataLabels: {
  164. enabled: true,
  165. format: '<b>{point.name}</b><br>{point.percentage:.1f} %',
  166. distance: -50,
  167. filter: {
  168. property: 'percentage',
  169. operator: '>',
  170. value: 4
  171. }
  172. }
  173. }
  174. },
  175. series: [{
  176. name: 'Share',
  177. data: data
  178. }]
  179. });
  180. }
  181. //按照小时计算的api 执行时间
  182. function chart_3(data){
  183. Highcharts.chart('chart-3', {
  184. title: {
  185. text: '按照小时计算的 API 执行时间'
  186. },
  187. subtitle: {
  188. text: 'Source: thesolarfoundation.com'
  189. },
  190. yAxis: {
  191. title: {
  192. text: '执行时间'
  193. }
  194. },
  195. xAxis: {
  196. categories: [
  197. '8',
  198. '9',
  199. '10',
  200. '11',
  201. '12',
  202. '13',
  203. '14',
  204. '15',
  205. '16',
  206. '17',
  207. '18',
  208. '19',
  209. '20',
  210. '21',
  211. '22',
  212. '23',
  213. '0',
  214. '1',
  215. '2',
  216. '3',
  217. '4',
  218. '5',
  219. '6',
  220. '7'
  221. ],
  222. accessibility: {
  223. rangeDescription: 'Range: 0 to 23'
  224. }
  225. },
  226. legend: {
  227. layout: 'vertical',
  228. align: 'right',
  229. verticalAlign: 'middle'
  230. },
  231. plotOptions: {
  232. series: {
  233. label: {
  234. connectorAllowed: false
  235. },
  236. pointStart: 0
  237. }
  238. },
  239. series: data,
  240. responsive: {
  241. rules: [{
  242. condition: {
  243. maxWidth: 500
  244. },
  245. chartOptions: {
  246. legend: {
  247. layout: 'horizontal',
  248. align: 'center',
  249. verticalAlign: 'bottom'
  250. }
  251. }
  252. }]
  253. }
  254. });
  255. }
  256. function chart_4(data){
  257. Highcharts.chart('chart-4', {
  258. chart: {
  259. type: 'column'
  260. },
  261. title: {
  262. text: 'API 执行次数'
  263. },
  264. subtitle: {
  265. text: 'Source: WorldClimate.com'
  266. },
  267. xAxis: {
  268. categories: [
  269. '8',
  270. '9',
  271. '10',
  272. '11',
  273. '12',
  274. '13',
  275. '14',
  276. '15',
  277. '16',
  278. '17',
  279. '18',
  280. '19',
  281. '20',
  282. '21',
  283. '22',
  284. '23',
  285. '0',
  286. '1',
  287. '2',
  288. '3',
  289. '4',
  290. '5',
  291. '6',
  292. '7'
  293. ],
  294. crosshair: true
  295. },
  296. yAxis: {
  297. min: 0,
  298. title: {
  299. text: '执行次数'
  300. }
  301. },
  302. legend: {
  303. layout: 'vertical',
  304. align: 'right',
  305. verticalAlign: 'middle'
  306. },
  307. tooltip: {
  308. headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
  309. pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
  310. '<td style="padding:0"><b>{point.y} 次</b></td></tr>',
  311. footerFormat: '</table>',
  312. shared: true,
  313. useHTML: true
  314. },
  315. plotOptions: {
  316. column: {
  317. pointPadding: 0.2,
  318. borderWidth: 0
  319. }
  320. },
  321. series: data
  322. });
  323. }