Jump to content

This is the support site for Andrews & Arnold Ltd, a UK Internet provider. Information on these pages is generally for our customers but may be useful to others, enjoy!

CHAOS: Difference between revisions

1,470 bytes removed ,  12 January 2015
m
no edit summary
mNo edit summary
mNo edit summary
This is a quick example of getting cqm graphs from CHAOS.
 
In short, the Info command is used to get the graph URLs. The HTML provides a form to enter the credentials or you can edit the javascript to hardcode these.
 
HTML:
<source>
<!DOCTYPE html>
<head lang='en'>
<title>Graphs</title>
<script type="text/javascript" src="jquery-1.8.3.min.js"></script>
<script src='chaosgraphs.js'></script>
</head>
<body>
<form id='login'>
 
<input type='text' name='username' placeholder='username' autofocus />
<form id='login'>
<input type='textpassword' name='usernamepassword' placeholder='usernamepassword' autofocus />
<input type='password' name='passwordsubmit' placeholdervalue='passwordLogin' />
</form>
<input type='submit' value='Login' />
<hr /form>
<div id='results'></div>
 
<hr </body>
 
<div id='results'></div>
 
</body>
</html>
 
</source>
 
 
<source>
//Function to get service data from chaos using the "info" command
 
function getgraphs(username,password)
var gxml = new Array(); //Xml for plotting graphs
 
//Go through each graph div and plot it's graph
function plotgraphs()
{
$("#results").html("<p><img src='images/loading-small.gif' alt='Loading' /></p>"); //Show a loading image while wai
$("div.graph").each(function() {
ting for chaos
var graph = $(this).attr("graph");
if(!username) { var username = $("input[type='text'][name='username']").val(); }
var url = $(this).attr("url");
if(!password) { var password = $("input[type='password'][name='password']").val(); }
var units = $(this).attr("units");
//AJAX request for "info" command
var pwidth = $(this).parent().width();
$.ajax({
$(this).width(pwidth-300).addClass("waiting");
type: "POST",
$("div.graphlegend[graph='"+graph+"']").hide();
url: "https://chaos.aa.net.uk/info",
$.ajax({url: url, dataType: "xml", complete: function(data) {
xhrFields: { withCredentials: true },
gxml[graph] = $.xml2json(data.responseXML,true);
contentType: 'application/json',
var html = "";
data: JSON.stringify({username:username,password:password}),
for(var j = 0; j < gxml[graph].dataset.length; j++) {
success: function(data) {
html+="<div class='legenditem' style='border-left: 5px solid #"+colors[j]+";'><label for='legend-"+gxml[graph].d;
var chaos = data;
}
var html = "";
 
console.log(chaos);
//Create legend
if(chaos.error != undefined) {
$("div.graphlegend[graph='"+graph+"']").html(html);
//If there is an error display it
 
html+="<p class='error'>"+chaos.error+"</p>";
//Plot each graph
}
myplot(graph);
else {
 
//If there is no error, loop through the response and create graphs
//Display precise data on hover
for(var i = 0; i < chaos.login.length; i++) {
$("div.graph[graph='"+graph+"']").bind("plothover", function(event, pos, item) {
if(chaos.login[i].broadband_count != 0) {
$("div.datapoint").remove();
for(var j = 0; j < chaos.login[i].broadband.length; j++) {
if(item) {
var bb = chaos.login[i].broadband[j];
var html = "<div class='datapoint' style='top: 20px; right: 50px;'>";
if(units == 'B' || units == 'b') { html+=mega(itembb.datapoint[1])circuit+units"<br />"; }
html+="<img src='"+bb.cqm_png.replace(/http:/g,"https:")+"' alt='CQM graph "+j+"' /><hr />";
else if(units != undefined) { html+=item.datapoint[1]+units; }
else { html+=item.datapoint[1]; }
html+="</div>"; }
else { html+="No lines"; }
$("div.graph[graph='"+graph+"']").append(html);
}
}
$("#results").html(html);
//Put the results into a div
}
});
 
//Show/Hide data when the legend items are clicked
$("input.legend[type='checkbox'][graph='"+graph+"']").unbind("change").change(function() {
var checked = $(this).attr("checked");
var graph = $(this).attr("graph");
if($("input.legend[type='checkbox'][graph='"+graph+"']:checked").length == 0 ) { $(this).attr("checked","true");}
else { myplot(graph); }
});
 
}});
});
}
 
function myplot(graph)
{
var mode = '';
var bwidth = $("div.graph[graph='"+graph+"']").attr("width");
if(bwidth == 'hour') { bwidth = 60*60*1000; }
else if(bwidth == 'day') { bwidth = 60*60*24*1000; }
else if(bwidth == 'week') { bwidth = 60*60*24*7*1000; }
else if(bwidth == 'month') { bwidth = 60*60*24*30*1000; }
var format = $("div.graph[graph='"+graph+"']").attr("format");
if(format == undefined) { format = ''; } else { mode = 'time'; }
var bars = '';
if($("div.graph[graph='"+graph+"']").attr("type") == 'bars') { bars = true; }
 
var gdata = new Array();
for(var j = 0; j < gxml[graph].dataset.length; j++) {
if($("input.legend[type='checkbox'][id='legend-"+gxml[graph].dataset[j].title+"']").attr("checked") != undefined) {
var gjson = new Array();
for(var i = 0; i < gxml[graph].dataset[j].data.length; i++) {
if(mode == 'time') { gjson[i] = [Date.parse(gxml[graph].dataset[j].data[i].x),gxml[graph].dataset[j].data[i].y];}
else { gjson[i] = [gxml[graph].dataset[j].data[i].x,gxml[graph].dataset[j].data[i].y]; }
}
gdata.push({label: gxml[graph].dataset[j].title, data: gjson, color: "#"+colors[j]});
}
}
//console.log(gdata);
 
$.plot($("div.graph[graph='"+graph+"']"),gdata,{
xaxis: {
mode: mode,
timeformat: format,
},
yaxis: {
tickFormatter: mega,
},
legend: {
show: false,
backgroundOpacity: 1,
},
bars: {
barWidth: bwidth,
show: bars,
fill: bars,
},
grid: {
hoverable: true,
},
});
$("div.graph[graph='"+graph+"']").removeClass("waiting");
$("div.graphlegend[graph='"+graph+"']").show();
}
 
$(document).ready(function() {
//Run the getgraphs() function when the form is submitted
plotgraphs();
$("#login").submit(function(e) {
e.preventDefault();
getgraphs();
//Or you could run getgraphs with a static username and password e.g.
//getgraphs('myusername','mypassword');
});
});
</source>
autoreview, Bureaucrats, editor, Interface administrators, reviewer, Administrators
12,264

edits