dashboard.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. type = ['','info','success','warning','danger'];
  2. dashboard = {
  3. initPickColor: function(){
  4. $('.pick-class-label').click(function(){
  5. var new_class = $(this).attr('new-class');
  6. var old_class = $('#display-buttons').attr('data-class');
  7. var display_div = $('#display-buttons');
  8. if(display_div.length) {
  9. var display_buttons = display_div.find('.btn');
  10. display_buttons.removeClass(old_class);
  11. display_buttons.addClass(new_class);
  12. display_div.attr('data-class', new_class);
  13. }
  14. });
  15. },
  16. initChartist: function(){
  17. var getData = $.get('/get/1');
  18. getData.done(function(results) {
  19. var data = JSON.parse(results)
  20. console.log(data)
  21. var app = data['apps@lab'];
  22. function getCpuUsage (app){
  23. cpu_usage = []
  24. for (var i in app){
  25. cpu_usage.push(app[i].cpu_usage)
  26. }
  27. return cpu_usage
  28. }
  29. function getMemoryUsage (app){
  30. memory_usage = []
  31. for (var i in app){
  32. memory_usage.push(app[i].memory_usage)
  33. }
  34. return memory_usage
  35. }
  36. function getStatus (app){
  37. statusList = []
  38. for (var i in app){
  39. statusList.push(app[i].status)
  40. }
  41. return statusList
  42. }
  43. // monitoring apps chart
  44. var dataChart = {
  45. labels: ['9:00AM', '12:00AM', '3:00PM', '6:00PM', '9:00PM', '12:00PM', '3:00AM', '6:00AM'],
  46. series: [
  47. [287, 385, 490, 562, 594, 626, 698, 895, 952],
  48. [67, 152, 193, 240, 387, 435, 535, 642, 744],
  49. [23, 113, 67, 108, 190, 239, 307, 410, 410],
  50. ]
  51. };
  52. var optionsChart = {
  53. lineSmooth: false,
  54. low: 0,
  55. high: 1000,
  56. showArea: true,
  57. height: "245px",
  58. axisX: {
  59. showGrid: false,
  60. },
  61. lineSmooth: Chartist.Interpolation.simple({
  62. divisor: 3
  63. }),
  64. showLine: true,
  65. showPoint: false,
  66. };
  67. var responsiveChart = [
  68. ['screen and (max-width: 640px)', {
  69. axisX: {
  70. labelInterpolationFnc: function (value) {
  71. return value[0];
  72. }
  73. }
  74. }]
  75. ];
  76. Chartist.Line('#chartHours', dataChart, optionsChart, responsiveChart);
  77. // cpu and memory --------------------------
  78. cpu_usage = getCpuUsage(app)
  79. memory_usage = getMemoryUsage(app)
  80. var data = {
  81. labels: ['Jan', 'Feb', 'Mar', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
  82. series: [
  83. cpu_usage,memory_usage
  84. // [542, 543, 520, 680, 653, 753, 326, 434, 568, 610, 756, 895],
  85. // [230, 293, 380, 480, 503, 553, 600, 664, 698, 710, 736, 795]
  86. ]
  87. };
  88. var options = {
  89. seriesBarDistance: 10,
  90. axisX: {
  91. showGrid: false
  92. },
  93. height: "245px"
  94. };
  95. var responsiveOptions = [
  96. ['screen and (max-width: 640px)', {
  97. seriesBarDistance: 5,
  98. axisX: {
  99. labelInterpolationFnc: function (value) {
  100. return value[0];
  101. }
  102. }
  103. }]
  104. ];
  105. Chartist.Line('#chartActivity', data, options, responsiveOptions);
  106. var dataPreferences = {
  107. series: [
  108. [25, 30, 20, 25]
  109. ]
  110. };
  111. var optionsPreferences = {
  112. donut: true,
  113. donutWidth: 40,
  114. startAngle: 0,
  115. total: 100,
  116. showLabel: false,
  117. axisX: {
  118. showGrid: false
  119. }
  120. };
  121. Chartist.Pie('#chartPreferences', dataPreferences, optionsPreferences);
  122. //summary Run|Idle|Crash pie chart
  123. status = getStatus(app)
  124. statusList = status.split(',');
  125. statusByNum = getStatusByType(statusList)
  126. function getStatusByType(statusList){
  127. running = 0;
  128. idle = 0;
  129. crash = 0;
  130. for (var n in statusList){
  131. if (statusList[n] == 'running'){
  132. running += 1;
  133. };
  134. if (statusList[n] == 'idle'){
  135. idle += 1;
  136. };
  137. if (statusList[n] == 'crash'){
  138. crash += 1;
  139. };
  140. }
  141. statusList = [running, idle, crash];
  142. return statusList
  143. }
  144. percentage = getStatusPercent(statusByNum);
  145. function getStatusPercent(statusByNum){
  146. let total = 0
  147. for (var i in statusByNum){
  148. total += statusByNum[i];
  149. }
  150. percent = []
  151. for (var i in statusByNum){
  152. percent.push(total / statusByNum[i])
  153. }
  154. total = 100
  155. let percentage = []
  156. for (var i in percent){
  157. percentage.push(total/percent[i])
  158. }
  159. for (var i in percentage){
  160. if (percentage[i] == 0){
  161. percentage.pop(percentage[i]);
  162. }
  163. }
  164. return percentage
  165. }
  166. for (i in percentage){
  167. percentage[i] = percentage[i].toString()+'%';
  168. }
  169. Chartist.Pie('#chartPreferences', {
  170. labels: percentage,
  171. series: statusByNum
  172. });
  173. })
  174. },
  175. // End chartist function
  176. initGoogleMaps: function(){
  177. var myLatlng = new google.maps.LatLng(40.748817, -73.985428);
  178. var mapOptions = {
  179. zoom: 13,
  180. center: myLatlng,
  181. scrollwheel: false, //we disable de scroll over the map, it is a really annoing when you scroll through page
  182. styles: [{"featureType":"water","stylers":[{"saturation":43},{"lightness":-11},{"hue":"#0088ff"}]},{"featureType":"road","elementType":"geometry.fill","stylers":[{"hue":"#ff0000"},{"saturation":-100},{"lightness":99}]},{"featureType":"road","elementType":"geometry.stroke","stylers":[{"color":"#808080"},{"lightness":54}]},{"featureType":"landscape.man_made","elementType":"geometry.fill","stylers":[{"color":"#ece2d9"}]},{"featureType":"poi.park","elementType":"geometry.fill","stylers":[{"color":"#ccdca1"}]},{"featureType":"road","elementType":"labels.text.fill","stylers":[{"color":"#767676"}]},{"featureType":"road","elementType":"labels.text.stroke","stylers":[{"color":"#ffffff"}]},{"featureType":"poi","stylers":[{"visibility":"off"}]},{"featureType":"landscape.natural","elementType":"geometry.fill","stylers":[{"visibility":"on"},{"color":"#b8cb93"}]},{"featureType":"poi.park","stylers":[{"visibility":"on"}]},{"featureType":"poi.sports_complex","stylers":[{"visibility":"on"}]},{"featureType":"poi.medical","stylers":[{"visibility":"on"}]},{"featureType":"poi.business","stylers":[{"visibility":"simplified"}]}]
  183. }
  184. var map = new google.maps.Map(document.getElementById("map"), mapOptions);
  185. var marker = new google.maps.Marker({
  186. position: myLatlng,
  187. title:"Hello World!"
  188. });
  189. // To add the marker to the map, call setMap();
  190. marker.setMap(map);
  191. },
  192. showNotification: function(from, align){
  193. color = Math.floor((Math.random() * 4) + 1);
  194. $.notify({
  195. icon: "ti-comment",
  196. message: "Message."
  197. },{
  198. type: type[color],
  199. timer: 4000,
  200. placement: {
  201. from: from,
  202. align: align
  203. }
  204. });
  205. },
  206. }