1 <div id="HPCDashboard">
2 <h1>CDN Operations View</h1>
4 <span class="summary-attr"><b>Allocated Slivers:</b> <span id="active-slivers-value"> </span> </span>
5 <span class="summary-attr"><b>CDN Bandwidth:</b> <span id="overall-throughput-value"> </span> </span>
6 <span class="summary-attr-util"><b>CDN Load:</b> <span id="cpu-utilization-value"> </span> </span>
8 <div id="map-us" ></div>
9 <div style="line-height: 30%"><br></div><table border=0><tr>
10 <td>Least Loaded </td>
11 <td bgcolor="#0000FF" width=40> </td>
12 <td bgcolor="#00FFFF" width=40> </td>
13 <td bgcolor="#00FF00" width=40> </td>
14 <td bgcolor="#FFFF00" width=40> </td>
15 <td bgcolor="#FF0000" width=40> </td>
16 <td> Most Loaded</td>
21 $( "#confirmNodeAdded" ).dialog({ autoOpen: false,
25 $( this ).dialog( "close" );
28 $( "#confirmNodeRemoved" ).dialog({ autoOpen: false });
30 L.Map = L.Map.extend({
31 openPopup: function(popup) {
34 return this.addLayer(popup).fire('popupopen', {
41 //Iterate through data and find the max/min coordinates to include all of our points to start
42 var map = L.map('map-us'); //.setView([0, 0], 1);
43 map.scrollWheelZoom.disable();
46 // Great tiles, but starting to occasionally see 403 errors on certain tiles causing grey out effect
47 //L.tileLayer('http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png', {
49 // Swapping out cloudmade tiles to openstreetmap - too many grey tiles showing
50 L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
55 var arrayOfLatLngs = [];
56 var mapData = {{ cdnData|safe }};
59 for ( var key in mapData ) {
60 arrayOfLatLngs.push([mapData[key]['lat'],mapData[key]['long']]);
61 log.debug( arrayOfLatLngs );
63 mapData[key]['marker'] = L.marker([mapData[key]['lat'], mapData[key]['long']], {icon: getIcon(mapData[key]['numNodes'], mapData[key]['numHPCSlivers'], 0, mapData[key]['hot']) });
64 mapData[key]['marker'].addTo(map).bindPopup(setPopupVals(key, mapData[key]));
67 var bounds = new L.LatLngBounds(arrayOfLatLngs);
68 map.fitBounds(bounds);
70 var popup = L.popup();
73 function setPopupVals (site, siteData) {
74 var retVal = '<span class="SiteDetail"><b>' + site + '</b></span>' +
75 '</br><a href="' + siteData['siteUrl'] + '">' + siteData['siteUrl'] + '</a>' +
76 '</br><b>HPC Slivers: </b>' + siteData['numHPCSlivers'] +
77 '</br><b>Total Nodes: </b>' + siteData['numNodes'] +
78 // '</br><b>Hot: </b>' + Math.round(siteData['hot']*100) +
79 '</br><b>Measured Load: </b>' + siteData['load'] + '%' +
80 '<span id="addSlivers"></br><a href="#" id="addHPCSliver" data-site="' + site + '" data-availNodes="' + siteData['numNodes'] +'">Add HPC Slivers</a> </span>' +
81 '<span id="remSlivers"><a href="#" id="remHPCSliver" data-site="' + site + '">Remove HPC Slivers</a> </span>';
86 $('#map-us').on('click', '#remHPCSliver', function() {
89 url : '/dashboardaddorremsliver/',
91 data: {site: $(this).data('site'),
93 csrfmiddlewaretoken: "{{ csrf_token }}", // < here
96 //success: function(response)
98 // alert("Successfully posted request to REMOVE sliver");
101 confirmDialog("Info","Removed an HPC Sliver from Site ");
103 //error:function (xhr, textStatus, thrownError){
104 // alert("Could not request to remove HPC Sliver");
109 $('#map-us').on('click', '#addHPCSliver', function() {
112 url : '/dashboardaddorremsliver/',
114 data: {site: $(this).data('site'),
116 csrfmiddlewaretoken: "{{ csrf_token }}", // < here
119 success: function(response)
121 //alert("Successfully posted request to add sliver");
125 confirmDialog("Info","Added an HPC Sliver to Site ");
127 //error:function (xhr, textStatus, thrownError){
128 // alert("error doing something");
131 // confirmDialog("Add HPC Slivers","Add some HPC Slivers to site " + $(this).data('site'));
134 function getIcon(numNodes, numHPCSlivers, currentBW, hot) {
135 //var colorChoices = ["#007FFF", "#0000FF", "#7f00ff", "#FF00FF", "#FF007F", "#FF0000"];
136 var colorChoices = ["#0000FF", "#00FFFF", "#00FF00", "#FFFF00", "#FF0000"];
138 var ratio = hot * 100; //(numHPCSlivers/numNodes) * 100;
139 var numColors = colorChoices.length;
140 var colorBands = 100/numColors;
142 //Algorithm for color tone should consider the number of available nodes
143 // on the site, and then how much the current dedicated nodes are impacted
145 var iconColor = colorChoices.length-1;
146 for (colorBand = 0; colorBand < numColors; colorBand ++) {
147 if (ratio < colorBands * colorBand+1) {
148 iconColor = colorBand
153 if (numHPCSlivers < 1) {
154 iconColor = "#7F7F7F";
156 iconColor = colorChoices[iconColor];
159 var icon = L.MakiMarkers.icon({icon: "star-stroked", color: iconColor , size: "s"});
163 function updateMaps() {
164 log.debug("Attempting to update Maps");
166 url : '/hpcdashboard',
169 success: function(newData)
171 log.debug("Successfully got data back...");
173 log.debug("Still have old data too");
175 updateMapData(newData);
178 setTimeout(updateMaps, 30000)
182 function updateMapData(newData) {
183 for ( site in newData ) {
184 var isNewSite = false;
185 //check to see if the site is new or not
186 if (site in mapData) {
187 log.debug("Site " + site + " already mapped");
188 //take ownership of marker
189 newData[site]['marker'] = mapData[site]['marker'];
190 delete mapData[site];
191 newData[site]['marker'].setIcon(getIcon(newData[site]['numNodes'], newData[site]['numHPCSlivers'], 0, newData[site]['hot']));
192 // workaround, markers currently don't have a setPopup Content method -- so have to grab object directly
193 newData[site]['marker']._popup.setContent(setPopupVals(site, newData[site]));
197 log.debug("New Site detected: " + site);
198 newData[site]['marker'] = L.marker([newData[site]['lat'], newData[site]['long']],
199 {icon: getIcon(newData[site]['numNodes'], newData[site]['numHPCSlivers'], 0, newData[site]['hot']) });
200 newData[site]['marker'].addTo(map).bindPopup(setPopupVals(site, newData[site])); //.openPopup();
201 log.debug("Should have added the new site");
206 // Anything still in data needs to be removed since it is no longer a valid site
207 for (remSite in mapData) {
208 log.warn("Site: " + remSite + " is no longer valid, removing from map");
209 map.removeLayer(data[remSite]['marker']);
214 function onMapClick(e) {
217 .setContent("You clicked the map at " + e.latlng.toString())
221 setTimeout(updateMaps, 5000)
223 // from stackexchange
224 function setInnerText (elementId, text) {
226 if (document.getElementById) {
227 element = document.getElementById(elementId);
228 } else if (document.all) {
229 element = document.all[elementId];
232 if (typeof element.textContent != 'undefined') {
233 element.textContent = text;
234 } else if (typeof element.innerText != 'undefined') {
235 element.innerText = text;
236 } else if (typeof element.removeChild != 'undefined') {
237 while (element.hasChildNodes()) {
238 element.removeChild(element.lastChild);
240 element.appendChild(document.createTextNode(text)) ;
245 function updateLabelData(summaryData) {
246 setInnerText("active-slivers-value", summaryData["total_slivers"]);
247 setInnerText("overall-throughput-value", (summaryData["total_bandwidth"]*8/1024/1024/1024).toFixed(2) + " Gbps");
248 setInnerText("cpu-utilization-value", summaryData["average_cpu"] + "%");
251 function updateLabels() {
252 log.debug("Attempting to update Labels");
257 success: function(newData)
259 updateLabelData(newData);
262 setTimeout(updateLabels, 30000)
266 setTimeout(updateLabels, 5000)