showlog.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  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. let delay = parseInt(iterator[2]);
  16. if (api.hasOwnProperty.call(api, iterator[0])) {
  17. let element = api[iterator[0]];
  18. element.times++;
  19. element.delay += delay;
  20. try{
  21. let hour = parseInt(iterator[1].split(':')[0]);
  22. element.delayHour[hour] += delay;
  23. if(delay>api[iterator[0]].delayMaxHour[hour]){
  24. api[iterator[0]].delayMaxHour[hour] = delay;
  25. }
  26. if(delay < api[iterator[0]].delayMinHour[hour]){
  27. api[iterator[0]].delayMinHour[hour] = delay;
  28. }
  29. element.timesHour[hour] ++;
  30. }catch(e){
  31. }
  32. }else{
  33. api[iterator[0]] = {
  34. times:1,
  35. 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],
  36. delay:delay,
  37. //一小时总执行时间
  38. 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],
  39. //一小时最高执行时间
  40. delayMaxHour:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
  41. //一小时最低执行时间
  42. delayMinHour:[30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000,30000],
  43. //一小时平均执行时间
  44. delayAverageHour:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
  45. };
  46. try{
  47. let hour = parseInt(iterator[1].split(':')[0]);
  48. api[iterator[0]].delayHour[hour] = parseInt(iterator[2]);
  49. api[iterator[0]].delayMaxHour[hour] = parseInt(iterator[2]);
  50. api[iterator[0]].delayMinHour[hour] = parseInt(iterator[2]);
  51. api[iterator[0]].timesHour[hour] = 1;
  52. }catch(e){
  53. }
  54. }
  55. }
  56. let api_timms = new Array();
  57. let api_delay = new Array();
  58. let ApiDelayInHour = new Array();
  59. let ApiTimesInHour = new Array();
  60. let ohlc = new Array();
  61. let volume = new Array();
  62. for (const key in api) {
  63. if (api.hasOwnProperty.call(api, key)) {
  64. //计算每个小时的平均执行时间
  65. for (let index = 0; index < api[key].delayAverageHour.length; index++) {
  66. api[key].delayAverageHour[index] = api[key].delayHour[index]/api[key].timesHour[index];
  67. }
  68. const element = api[key];
  69. api_timms.push({
  70. name:key,
  71. y:element.times
  72. });
  73. api_delay.push({
  74. name:key,
  75. y:element.delay
  76. });
  77. ApiDelayInHour.push({
  78. name:key,
  79. data:element.delayHour
  80. });
  81. ApiTimesInHour.push({
  82. name:key,
  83. data:element.timesHour
  84. });
  85. for (let index = 1; index < api[key].delayAverageHour.length; index++) {
  86. api[key].delayAverageHour[index] = api[key].delayHour[index]/api[key].timesHour[index];
  87. if(key=="/app/uwbw/update.php"){
  88. ohlc.push([
  89. Date.UTC(2022,1,1,index,0,0,0), // the date
  90. api[key].delayAverageHour[index-1], // open
  91. api[key].delayMaxHour[index], // high
  92. api[key].delayMinHour[index], // low
  93. api[key].delayAverageHour[index] // close
  94. ]);
  95. volume.push([
  96. Date.UTC(2022,1,1,index,0,0,0), // the date
  97. element.timesHour[index] // the volume
  98. ]);
  99. }
  100. }
  101. }
  102. }
  103. chart_1(api_timms);
  104. chart_2(api_delay);
  105. chart_3(ApiDelayInHour);
  106. chart_4(ApiTimesInHour);
  107. chart_5(ohlc,volume);
  108. chart_6(ohlc,volume);
  109. });
  110. }
  111. function chart_1(data){
  112. // Make monochrome colors
  113. var pieColors = (function () {
  114. var colors = [],
  115. base = Highcharts.getOptions().colors[0],
  116. i;
  117. for (i = 0; i < 10; i += 1) {
  118. // Start out with a darkened base color (negative brighten), and end
  119. // up with a much brighter color
  120. colors.push(Highcharts.color(base).brighten((i - 3) / 7).get());
  121. }
  122. return colors;
  123. }());
  124. // Build the chart
  125. Highcharts.chart('chart-1', {
  126. chart: {
  127. plotBackgroundColor: null,
  128. plotBorderWidth: null,
  129. plotShadow: false,
  130. type: 'pie'
  131. },
  132. title: {
  133. text: 'API 执行次数'
  134. },
  135. tooltip: {
  136. pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
  137. },
  138. accessibility: {
  139. point: {
  140. valueSuffix: '%'
  141. }
  142. },
  143. plotOptions: {
  144. pie: {
  145. allowPointSelect: true,
  146. cursor: 'pointer',
  147. colors: pieColors,
  148. dataLabels: {
  149. enabled: true,
  150. format: '<b>{point.name}</b><br>{point.percentage:.1f} %',
  151. distance: -50,
  152. filter: {
  153. property: 'percentage',
  154. operator: '>',
  155. value: 4
  156. }
  157. }
  158. }
  159. },
  160. series: [{
  161. name: 'Share',
  162. data: data
  163. }]
  164. });
  165. }
  166. function chart_2(data){
  167. // Make monochrome colors
  168. var pieColors = (function () {
  169. var colors = [],
  170. base = Highcharts.getOptions().colors[0],
  171. i;
  172. for (i = 0; i < 10; i += 1) {
  173. // Start out with a darkened base color (negative brighten), and end
  174. // up with a much brighter color
  175. colors.push(Highcharts.color(base).brighten((i - 3) / 7).get());
  176. }
  177. return colors;
  178. }());
  179. // Build the chart
  180. Highcharts.chart('chart-2', {
  181. chart: {
  182. plotBackgroundColor: null,
  183. plotBorderWidth: null,
  184. plotShadow: false,
  185. type: 'pie'
  186. },
  187. title: {
  188. text: 'API 累积执行时间'
  189. },
  190. tooltip: {
  191. pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
  192. },
  193. accessibility: {
  194. point: {
  195. valueSuffix: '%'
  196. }
  197. },
  198. plotOptions: {
  199. pie: {
  200. allowPointSelect: true,
  201. cursor: 'pointer',
  202. colors: pieColors,
  203. dataLabels: {
  204. enabled: true,
  205. format: '<b>{point.name}</b><br>{point.percentage:.1f} %',
  206. distance: -50,
  207. filter: {
  208. property: 'percentage',
  209. operator: '>',
  210. value: 4
  211. }
  212. }
  213. }
  214. },
  215. series: [{
  216. name: 'Share',
  217. data: data
  218. }]
  219. });
  220. }
  221. //按照小时计算的api 执行时间
  222. function chart_3(data){
  223. Highcharts.chart('chart-3', {
  224. title: {
  225. text: '按照小时计算的 API 执行时间'
  226. },
  227. subtitle: {
  228. text: 'Source: thesolarfoundation.com'
  229. },
  230. yAxis: {
  231. title: {
  232. text: '执行时间'
  233. }
  234. },
  235. xAxis: {
  236. categories: [
  237. '8',
  238. '9',
  239. '10',
  240. '11',
  241. '12',
  242. '13',
  243. '14',
  244. '15',
  245. '16',
  246. '17',
  247. '18',
  248. '19',
  249. '20',
  250. '21',
  251. '22',
  252. '23',
  253. '0',
  254. '1',
  255. '2',
  256. '3',
  257. '4',
  258. '5',
  259. '6',
  260. '7'
  261. ],
  262. accessibility: {
  263. rangeDescription: 'Range: 0 to 23'
  264. }
  265. },
  266. legend: {
  267. layout: 'vertical',
  268. align: 'right',
  269. verticalAlign: 'middle'
  270. },
  271. plotOptions: {
  272. series: {
  273. label: {
  274. connectorAllowed: false
  275. },
  276. pointStart: 0
  277. }
  278. },
  279. series: data,
  280. responsive: {
  281. rules: [{
  282. condition: {
  283. maxWidth: 500
  284. },
  285. chartOptions: {
  286. legend: {
  287. layout: 'horizontal',
  288. align: 'center',
  289. verticalAlign: 'bottom'
  290. }
  291. }
  292. }]
  293. }
  294. });
  295. }
  296. function chart_4(data){
  297. Highcharts.chart('chart-4', {
  298. chart: {
  299. type: 'column'
  300. },
  301. title: {
  302. text: 'API 执行次数'
  303. },
  304. subtitle: {
  305. text: 'Source: WorldClimate.com'
  306. },
  307. xAxis: {
  308. categories: [
  309. '8',
  310. '9',
  311. '10',
  312. '11',
  313. '12',
  314. '13',
  315. '14',
  316. '15',
  317. '16',
  318. '17',
  319. '18',
  320. '19',
  321. '20',
  322. '21',
  323. '22',
  324. '23',
  325. '0',
  326. '1',
  327. '2',
  328. '3',
  329. '4',
  330. '5',
  331. '6',
  332. '7'
  333. ],
  334. crosshair: true
  335. },
  336. yAxis: {
  337. min: 0,
  338. title: {
  339. text: '执行次数'
  340. }
  341. },
  342. legend: {
  343. layout: 'vertical',
  344. align: 'right',
  345. verticalAlign: 'middle'
  346. },
  347. tooltip: {
  348. headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
  349. pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
  350. '<td style="padding:0"><b>{point.y} 次</b></td></tr>',
  351. footerFormat: '</table>',
  352. shared: true,
  353. useHTML: true
  354. },
  355. plotOptions: {
  356. column: {
  357. pointPadding: 0.2,
  358. borderWidth: 0
  359. }
  360. },
  361. series: data
  362. });
  363. }
  364. function chart_6(ohlc,volume){
  365. {
  366. // create the chart
  367. Highcharts.stockChart('chart-6', {
  368. title: {
  369. text: 'AAPL stock price by minute'
  370. },
  371. rangeSelector: {
  372. buttons: [{
  373. type: 'hour',
  374. count: 1,
  375. text: '1h'
  376. }, {
  377. type: 'day',
  378. count: 1,
  379. text: '1D'
  380. }, {
  381. type: 'all',
  382. count: 1,
  383. text: 'All'
  384. }],
  385. selected: 1,
  386. inputEnabled: false
  387. },
  388. series: [{
  389. name: 'AAPL',
  390. type: 'candlestick',
  391. data: ohlc,
  392. tooltip: {
  393. valueDecimals: 2
  394. }
  395. }]
  396. });
  397. }
  398. }
  399. function chart_5(ohlc,volume){
  400. // create the chart
  401. groupingUnits = [[
  402. 'week', // unit name
  403. [1] // allowed multiples
  404. ], [
  405. 'month',
  406. [1, 2, 3, 4, 6]
  407. ]];
  408. Highcharts.stockChart('chart-5', {
  409. rangeSelector: {
  410. selected: 2
  411. },
  412. title: {
  413. text: 'progress_curve'
  414. },
  415. yAxis: [{
  416. labels: {
  417. align: 'right',
  418. x: -3
  419. },
  420. title: {
  421. text: 'EXP'
  422. },
  423. height: '60%',
  424. lineWidth: 2,
  425. resize: {
  426. enabled: true
  427. }
  428. }, {
  429. labels: {
  430. align: 'right',
  431. x: -3
  432. },
  433. title: {
  434. text: 'action'
  435. },
  436. top: '65%',
  437. height: '35%',
  438. offset: 0,
  439. lineWidth: 2
  440. }],
  441. tooltip: {
  442. shared: false,
  443. useHTML: true,
  444. pointFormatter: function() {
  445. if(this.high){
  446. return '<b><a href="../">'+this.series.name + ' : ' + this.high + '&nbsp;' +'gLocal.gui.h'+ '</a><br><a href="../">' +'gLocal.gui.day_EXP' + ' : ' + Math.round((this.high - this.low)*100)/100 + '&nbsp;' +'gLocal.gui.h'+'</a></b><br/>';
  447. }
  448. else{
  449. return '<b><a href="../">'+this.series.name + ' : ' + this.y + '&nbsp;' +'gLocal.gui.times'+'</a><span style="display:none;">'+this.x+'</span></b>';
  450. }
  451. },
  452. valueDecimals: 2,//保留两位小數
  453. split: true
  454. },
  455. series: [{
  456. type: 'ohlc',
  457. name: 'gLocal.gui.EXP_in_total',
  458. data: ohlc,
  459. dataGrouping: {
  460. units: [[
  461. 'week', // unit name
  462. [1] // allowed multiples
  463. ], [
  464. 'month',
  465. [1, 2, 3, 4, 6]
  466. ]]
  467. }
  468. }, {
  469. type: 'column',
  470. name: 'gLocal.gui.day_action',
  471. data: volume,
  472. yAxis: 1,
  473. dataGrouping: {
  474. units: groupingUnits
  475. }
  476. }]
  477. });
  478. }