- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntimeMonitorClient.js
More file actions
Latest commit
115 lines (102 loc) · 3.28 KB
/
Copy pathruntimeMonitorClient.js
File metadata and controls
115 lines (102 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
varprefix='smr_monitor';
console.log('Runtime Monitor, Run!');
vardataUrl='/'+prefix+'/data';
varcommandUrl='/'+prefix+'/command/';
varqueryData=function(post){
varxhr=newwindow.XMLHttpRequest();
xhr.onreadystatechange=function(){
if(xhr.readyState==4){
varresult;
if(xhr.status>=200&&xhr.status<300){
result=xhr.responseText;
ondata(null,JSON.parse(result));
}else{
ondata(xhr.responseText,null);
}
}
};
xhr.open(post ? 'POST' : 'GET',dataUrl,true);
xhr.send(post||'');
};
varVisibleMap={},Command={};
varmakeAjaxButton=function(root){
varbuttons=root.querySelectorAll('a');
varbut=null;
for(vari=0,len=buttons.length;i<len;i++){
but=buttons[i];
but.addEventListener('click',function(event){
varme=this;
if(me.runing!="1"){
me.runing=1;
me.style.background="#F77";
varxhr=newwindow.XMLHttpRequest();
xhr.onreadystatechange=function(){
if(xhr.readyState==4){
varresult;
if(xhr.status>=200&&xhr.status<300){
//
}else{
alert(xhr.responseText);
}
me.style.background='';
me.runing=0;
}
setTimeout(queryData,100);
};
xhr.open('GET',this.href,true);
xhr.send('');
}else{
console.log('relax.. please!!!');
}
event.preventDefault();
})
}
}
vartoWatchPage=function(){
varcontent="<div>",values;
varinput=document.createElement('span');
for(varkeyinVisibleMap){
values=VisibleMap[key];
if(values.indexOf(/\<\>/i)){
input.innerText=values;
values=input.innerHTML;
}
values=values.replace(/\\n/igm,"\n");
values=values.replace(/\\t/igm,"\t");
//values = values.replace(/\\"/igm,'"');
//values = values.replace(/\\'/igm,"'");
content+="<h2>"+key+"</h2><pre>"+values+"</pre>";
}
content+="</div>";
document.getElementById('monitor').innerHTML=content;
returncontent;
};
vartoCommandPage=function(){
varcontent='',value;
for(varkeyinCommand){
value=Command[key];
content+='<a href="'+commandUrl+encodeURI(value)+'">'+value+'</a>';
}
varcommands=document.getElementById('commands');
commands.innerHTML=content;
makeAjaxButton(commands);
returncontent;
};
varondata=function(err,data){
if(err){
return;
}
VisibleMap=data.data;
Command=data.command;
toWatchPage();
toCommandPage();
};
varsetPrefix=function(_prefix){
prefix=_prefix;
dataUrl='/'+prefix+'/data';
commandUrl='/'+prefix+'/command/';
};
window.onload=function(){
queryData();
setInterval(queryData,5*1000);
};