viewOraMon.html 4.85 KB
<!DOCTYPE html>
<html>
  <head>
  <title>LIL JMX Monitor</title>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
  </head>
  <body>
    <h1 id="main_title">LIL ORA Monitor</h1>
    <div style="background-color: lightgrey; line-height:1em; min-height:3em;"><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;
                main_div.appendChild(newdiv);
                ac_chart[i] = new google.visualization.LineChart(newdiv);
            }
            
            created = true;
        }

        function getData() {
            if(location.search != '')
            {
            	// Update the data
            	statusP.innerHTML = "Calling getData...";
            	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
                statusP.innerHTML += "<br>Calling getMetrics...";
                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 (ms:" + res.ms + " age:" + res.age + ")<br>" + res.msg;
                    getMetrics();
                } else {
                	statusP.innerHTML += " Received responsecode " + this.status;
                }
            }
        }
        
        function handler2() {
            if (this.readyState == 4) {
                if (this.status == 200 &&
                    this.responseText != null) {
                	statusP.innerHTML += " Received 200 OK";
                	var res = eval('(' + this.responseText + ')');
                    addData(res);
                } else {
                	statusP.innerHTML += " Received responsecode " + this.status;
                }
            }
        }

        function addData(res) {
        	if(res.error == false && res.nvarray.length > 0) {
        		main_title.innerHTML = res.name + " ORA Monitor";
        		document.title = "OraMon " + res.name;
	        	if (created == false) {
	        		createChart(res.nvarray);
	        	}
	        	
	        	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);
	                ac_options.title = res.nvarray[i].name + ": " + res.nvarray[i].value;
	                ac_chart[i].draw(ac_data[i], ac_options);
	            }
        	}

            window.setTimeout('getData()', 15000);
        }

    </script>
  </body>
</html>