viewOraMon.html
6.38 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<!DOCTYPE html>
<html>
<head>
<title>DB Monitor</title>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<style>
.ac_div {
width: 33%;
display: inline-block;
height: 18%;
margin: 0;
padding: 0;
}
.top_left_div {
width: 33%;
display: inline-block;
margin: 0;
padding: 0;
line-height:1em;
min-height:3em;
font-family:sans-serif;
}
.top_middle_div {
width: 33%;
display: inline-block;
margin: 0;
padding: 0;
line-height:1em;
min-height:3em;
font-family:sans-serif;
text-align: center;
}
.top_right_div {
width: 33%;
display: inline-block;
margin: 0;
padding: 0;
line-height:1em;
min-height:3em;
font-family:sans-serif;
text-align: right;
}
</style>
</head>
<body>
<div class="top_left_div"><h3 id="main_title">DB Monitor</h3></div>
<div class="top_middle_div">
<p>
Interval (s): <input type="text" id="updateTextBox" size="3" value="15">
Precision: <input type="text" id="precisionTextBox" size="3" value="6">
</p>
</div>
<div class="top_right_div"><p id="statusP">Nothing loaded</p></div>
<div id="main_div"></div>
<script type="text/javascript">
var ac_data = [];
var ac_chart = [];
var created = false;
google.load("visualization", "1", { packages: ["corechart"] });
google.setOnLoadCallback(getData);
var ac_options = {
title: 'Current Activity',
hAxis: { title: 'Timeline', titleTextStyle: { color: '#333'}, format: 'HH:mm:ss' },
vAxis: { },
isStacked: false,
legend: { position: 'none' }
};
function createChart(nvarray) {
for(var i=0; i < nvarray.length; i++) {
ac_data[i] = new google.visualization.DataTable();
ac_data[i].addColumn('datetime', 'Time');
ac_data[i].addColumn('number', nvarray[i].name);
var newdiv = document.createElement('div');
newdiv.id = 'ac_div' + i;
newdiv.className = 'ac_div';
main_div.appendChild(newdiv);
ac_chart[i] = new google.visualization.LineChart(newdiv);
}
created = true;
}
function getData() {
if(location.search != '')
{
// Update the data
statusP.innerHTML = "Updating...";
var client1 = new XMLHttpRequest();
client1.onreadystatechange = handler1;
client1.open("GET", "/OraMonREST/getData?age=14&connectionString=" + location.search.substring(1));
client1.setRequestHeader('Cache-Control', 'no-cache');
client1.setRequestHeader('Pragma', 'no-cache');
client1.send();
} else {
// Error, no monitor specified
statusP.innerHTML = "No monitor specified in URL QueryString (use ?enter%20uri%20encoded%20con%20string)";
}
}
function getMetrics() {
if(location.search != '')
{
// Get the metrics
var client2 = new XMLHttpRequest();
client2.onreadystatechange = handler2;
client2.open("GET", "/OraMonREST/getMetrics?connectionString=" + location.search.substring(1));
client2.setRequestHeader('Cache-Control', 'no-cache');
client2.setRequestHeader('Pragma', 'no-cache');
client2.send();
} else {
// Error, no monitor specified
statusP.innerHTML = "No monitor specified in URL QueryString (use ?enter%20uri%20encoded%20con%20string)";
}
}
function handler1() {
if (this.readyState == 4) {
if ((this.status == 200 || this.status == 202) &&
this.responseText != null) {
var res = eval('(' + this.responseText + ')');
statusP.innerHTML = " Received 200 OK (in " + (res.ms ? res.ms : 0) + "ms with age " + (res.age ? res.age : 0) + "ms)";
getMetrics();
} else {
statusP.innerHTML += " getData code " + this.status + " msg: " + res.msg;
}
}
}
function handler2() {
if (this.readyState == 4) {
if (this.status == 200 &&
this.responseText != null) {
var res = eval('(' + this.responseText + ')');
addData(res);
} else {
statusP.innerHTML += " getMetrics code " + this.status + " msg: " + res.msg;
}
}
}
function addData(res) {
if(res.error == false && res.nvarray.length > 0) {
main_title.innerHTML = res.name + " DB Monitor";
document.title = res.name;
if (created == false) {
createChart(res.nvarray);
}
var precision = parseInt(precisionTextBox.value);
if(isNaN(precision)) {
precision = 6;
precisionTextBox.value = "6";
}
for(var i=0; i < res.nvarray.length; i++) {
var dataRow = [];
dataRow[0] = new Date();
dataRow[1] = res.nvarray[i].value;
ac_data[i].addRow(dataRow);
if (ac_data[i].getNumberOfRows() > 100) ac_data[i].removeRow(0);
if (Math.floor(res.nvarray[i].value) === res.nvarray[i].value) {
ac_options.title = res.nvarray[i].name + ": " + res.nvarray[i].value;
} else {
ac_options.title = res.nvarray[i].name + ": " + res.nvarray[i].value.toPrecision(precision);
}
ac_chart[i].draw(ac_data[i], ac_options);
}
}
var updateTime = parseInt(updateTextBox.value);
if(isNaN(updateTime)) {
updateTime = 15000;
updateTextBox.value = "15";
}
else updateTime = updateTime * 1000;
window.setTimeout('getData()', updateTime);
}
</script>
</body>
</html>