dashboard.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. var monitor = {}
  2. monitor.processes = {}
  3. monitor.processes.fetch = function(){
  4. var httpclient = HttpClient.instance()
  5. httpclient.get('/get/processes',monitor.processes.init);
  6. }
  7. monitor.processes.init = function(x){
  8. var r = JSON.parse(x.responseText)
  9. monitor.processes.summary.init(r)
  10. var keys = jx.utils.keys(r)
  11. jx.dom.set.value('menu','')
  12. jx.utils.patterns.visitor(keys,function(label){
  13. var div = jx.dom.get.instance('DIV')
  14. var frame= jx.dom.get.instance('DIV')
  15. var i = jx.dom.get.instance('I')
  16. i.className = 'fa fa-chevron-right left'
  17. div.innerHTML = label
  18. frame.data = r[label]
  19. frame.label = label
  20. frame.appendChild(i)
  21. frame.appendChild(div)
  22. frame.className = 'menu-item'
  23. frame.onclick = function () {
  24. monitor.processes.render(this.label, this.data);
  25. jx.dom.set.value('trends_chart','')
  26. //monitor.processes.trend.init(this.label)
  27. }
  28. jx.dom.append('menu',frame)
  29. })
  30. //
  31. // Auto start the first item in the menu
  32. // This is designed not to let the user wander or wonder what is going on
  33. //
  34. jx.dom.get.children('menu')[0].click()
  35. setTimeout(monitor.sandbox.init,3000)
  36. }
  37. monitor.processes.render = function(label,data) {
  38. data = jx.utils.patterns.visitor(data,function(row){
  39. var status = {"idle":'<i class="fa fa-ellipsis-h" title="IDLE"></i>',"running":'<i class="fa fa-check" title="RUNNING"></i>',"crash":'<i class="fa fa-times" title="CRASHED"></i>'}
  40. if (!row.status.match(/class/)) {
  41. row.status_id = row.status
  42. row.status = status[row.status]
  43. }
  44. return row
  45. })
  46. jx.dom.set.value('latest_processes','') ;
  47. jx.dom.set.value('latest_processes_label',label)
  48. var options = {
  49. width: $('#latest_processes').width(), height:'auto'
  50. }
  51. options.paging = true
  52. options.pageSize = 3
  53. options.pageIndex = 1
  54. options.pageButtonCount = 3
  55. options.pagerContainer = '#latest_process_pager'
  56. options.pagerFormat= "{prev} Page {pageIndex} of {pageCount} {next}"
  57. options.pagePrevText= '<i class="fa fa-chevron-left"></i>'
  58. options.pageNextText= "<i class='fa fa-chevron-right small' title='Next'> </i>"
  59. options.data = data
  60. options.rowClass = function (item, index,evt) {
  61. return 'small'
  62. }
  63. options.rowClick = function(args){
  64. var item = args.item
  65. var id = jx.dom.get.value('latest_processes_label')
  66. var app = item.label
  67. monitor.processes.trend.init(id,app)
  68. }
  69. options.autoload = true
  70. options.fields = [
  71. { name: 'label', type: 'text', title: "Process", headercss: "small bold", css: "small"},
  72. { name: "cpu_usage", type: "number", title: "CPU", headercss: "small bold" , width:'64px'},
  73. { name: "memory_usage", type: "text", title: "Mem. Used", type: "number", headercss: "small bold" },
  74. { name: "memory_available", type: "number", title: "Mem. Avail", headercss: "small bold" },
  75. {name:"status",type:"text",title:"Status",headercss:"small bold",align:"center", width:'64px'}
  76. ]
  77. var grid = $('#latest_processes').jsGrid(options) ;
  78. //
  79. // We need to auto click the first row
  80. $('#latest_processes').find('.jsgrid-row')[0].click()
  81. }
  82. monitor.processes.trend = {}
  83. monitor.processes.trend.init = function (label,app) {
  84. var httpclient = HttpClient.instance()
  85. var uri = '/trends?id='+label+'&app='+encodeURIComponent(app)
  86. httpclient.get(uri, function (x) {
  87. var logs = JSON.parse(x.responseText)
  88. var dom = jx.dom.get.instance('trend_info');
  89. dom.logs = logs
  90. jx.dom.set.value('trend_info',app)
  91. // jx.dom.set.attribute(label,'logs',logs)
  92. monitor.processes.trend.render(logs,null,app)
  93. })
  94. }
  95. monitor.processes.trend.render = function (logs, key,label) {
  96. if (key == null) {
  97. key = 'memory_usage'
  98. }
  99. if (logs == null || label == null){
  100. logs = jx.dom.get.instance('trend_info').logs
  101. label= jx.dom.get.value('trend_info') ;
  102. }
  103. var frame = $('#trends_chart')
  104. jx.dom.set.value('trends_chart','')
  105. var context = jx.dom.get.instance('CANVAS')
  106. var conf = { type: 'line',responsive:true,maintainAspectRatio:true }
  107. conf.data = {}
  108. conf.options = { legend: { position: 'bottom' } }
  109. conf.options.scales = {}
  110. conf.options.scales.yAxes = [ {scaleLabel:{display:true,labelString:key.replace(/_/,' ').toUpperCase()},ticks:{min:0,beginAtZero:true},gridLines: {display:false}}]
  111. conf.options.scales.xAxes = [
  112. {
  113. type: 'time',
  114. gridLines: {display:false},
  115. unitStepSize:25,
  116. time: {
  117. format:'DD-MMM HH:mm'
  118. }
  119. }
  120. ]
  121. conf.data.datasets = [ ]
  122. var x_axis = []
  123. var _x = {}
  124. var _y = {}
  125. var values = jx.utils.patterns.visitor(logs,function(item){
  126. x = new Date(item.year,item.month-1,item.day,item.hour,item.minute)
  127. y = item[key]
  128. if (_x[x] == null ||(_x[x] == null && _y[y] == null)) {
  129. _x[x] = 1
  130. _y[y] = 1
  131. x_axis.push(x)
  132. return {x:x,y:y}
  133. } else {
  134. return null
  135. }
  136. })
  137. var serie = {label:label,data:values}
  138. i = parseInt(Math.random() * (COLORS.length - 1))
  139. serie.backgroundColor = 'transparent'
  140. serie.borderColor = COLORS[2]
  141. serie.borderWidth = 1
  142. serie.type = 'line'
  143. conf.data.datasets.push(serie)
  144. x_axis = jx.utils.unique(x_axis)
  145. conf.data.labels = x_axis
  146. // console.log(conf)
  147. jx.dom.append('trends_chart',context)
  148. var chart = new Chart(context,conf)
  149. }
  150. monitor.processes.summary = {}
  151. monitor.processes.summary.init = function(logs){
  152. var xr = 0, xc = 0, xi = 0
  153. var series = {}
  154. //var colors = [COLORS[11], COLORS[1], COLORS[2]]
  155. colors = [COLORS[11], COLORS[2], COLORS[100]]
  156. RUNNING_COLOR = COLORS[26]
  157. IDLE_COLOR = COLORS[100]
  158. CRASH_COLOR=COLORS[2]
  159. var i = 0;
  160. for( label in logs ){
  161. var rows = logs[label]
  162. series[label] = {data:[0,0,0],label:label}
  163. jx.utils.patterns.visitor(rows,function(item){
  164. if (item.status == 'running'){
  165. xr += 1
  166. }else if(item.status == 'idle'){
  167. xi += 1
  168. }else{
  169. xc += 1
  170. }
  171. })
  172. }
  173. var data = {labels:['Running','Crash','Idle'],datasets:[{data:[xr,xc,xi],backgroundColor:[RUNNING_COLOR,CRASH_COLOR,IDLE_COLOR/**COLORS[11],COLORS[2],COLORS[100]*/]}]}
  174. var context = jx.dom.get.instance('CANVAS')
  175. jx.dom.set.value('summary_chart','')
  176. jx.dom.append('summary_chart',context)
  177. var conf = {width:50,height:50}
  178. conf.type = 'doughnut'
  179. conf.data = data
  180. conf.options = {legend:{ position:'right'},repsonsive:true}
  181. var chart = new Chart(context,conf)
  182. jx.dom.set.value('summary_ranking','')
  183. context = jx.dom.get.instance('CANVAS')
  184. jx.dom.append('summary_ranking',context)
  185. conf = { type: 'bar', responsive: true }
  186. conf.options={scales:{xAxes:[{gridLines: {display:false}}],yAxes:[{gridLines: {display:false},scaleLabel:{display:true,labelString:'PROCESS COUNTS'} }] }}
  187. conf.options.legend ={position:'right'}
  188. /*
  189. conf.data = {labels:['Running','Idle','Crash']}
  190. var labels = jx.utils.keys(series)
  191. var i = 0
  192. conf.data.datasets = jx.utils.patterns.visitor(labels,function(id){
  193. series[id].backgroundColor = COLORS[i++]
  194. return series[id]})
  195. chart = new Chart(context,conf);
  196. */
  197. var labels = jx.utils.keys(logs)
  198. conf.data = { labels: labels, backgroundColor:colors }
  199. var xr = [], xi = [], xc = [],xr_bg = [],xc_bg = [],xi_bg = []
  200. jx.utils.patterns.visitor(labels, function (id) {
  201. var rows = logs[id]
  202. var index = xr.length
  203. xr_bg[index] = RUNNING_COLOR
  204. xi_bg[index] = IDLE_COLOR
  205. xc_bg[index] = CRASH_COLOR
  206. if (xr[index] == null) {
  207. xr[index] = 0
  208. xc[index] = 0
  209. xi[index] = 0
  210. }
  211. jx.utils.patterns.visitor(logs[id], function (row) {
  212. if (row.status.match(/running/i)) {
  213. xr[index] += 1
  214. } else if (row.status.match(/idle/i)) {
  215. xi[index] += 1
  216. } else {
  217. xc[index] += 1
  218. }
  219. })
  220. })
  221. conf.data.datasets = [{ label: 'running', data:xr,backgroundColor:xr_bg},{label:'crash',data:xc,backgroundColor:xc_bg},{label:'idle',data:xi,backgroundColor:xi_bg} ]
  222. console.log(conf.data.datasets)
  223. chart = new Chart(context, conf)
  224. }
  225. monitor.sandbox = {}
  226. monitor.sandbox.init = function () {
  227. jx.dom.hide('inspect_sandbox')
  228. var httpclient = HttpClient.instance()
  229. httpclient.get('/sandbox', function (x) {
  230. var r = JSON.parse(x.responseText)
  231. monitor.sandbox.render(r);
  232. })
  233. }
  234. monitor.sandbox.render = function (logs) {
  235. months = {1:'Jan',2:'Feb',3:'Mar',4:'Apr',5:'May',6:'Jun',7:'Jul',8:'Aug',9:'Sep',10:'Oct',11:'Nov',12:'Dec'}
  236. var d = ([logs[0].day, '-', months[logs[0].month],'-', logs[0].year, ' ', logs[0].hour, ':', logs[0].minute]).join('')
  237. jx.dom.set.value('sandbox_date',d)
  238. var options = {width:$('#sandbox_status').width(),height:'auto'}
  239. options.data = logs
  240. options.paging = true
  241. options.pageSize = 3
  242. options.pageIndex = 1
  243. options.pageButtonCount = 3
  244. options.pagerContainer = '#latest_process_pager'
  245. options.pagerFormat= "{prev} Page {pageIndex} of {pageCount} {next}"
  246. options.pagePrevText= '<i class="fa fa-chevron-left"></i>'
  247. options.pageNextText = "<i class='fa fa-chevron-right small' title='Next'> </i>";
  248. options.rowClass = function (item) {
  249. if (item.value < 70) {
  250. return 'bad'
  251. } else if (item.value < 100) {
  252. return 'warning'
  253. } else {
  254. return 'good'
  255. }
  256. }
  257. options.fields = [
  258. { name: 'label',title:'Virtual Environment Label',type:'text',css:'small',headercss:'small bold' },
  259. { name: 'value', title:'Completeness %',type: 'number', css: 'small', headercss: 'small bold' }
  260. ]
  261. var grid = $('#sandbox_status').jsGrid(options)
  262. jx.dom.show('inspect_sandbox')
  263. }