var globalNodesDetail= new Object(); var globalAllNodesNum = 0; var globalFinishNodesNum = 0; var globalTimeStamp; var globalCondition = ''; var globalResponse = new Object(); function loadRmcMon() { //find the rmcmon tab var rmcMonTab = $('#rmcmon'); //add the stauts bar first. id = 'rmcMonStatus' var rmcStatusBar = createStatusBar('rmcMonStatus'); rmcStatusBar.find('div').append(createLoader()); rmcMonTab.append(rmcStatusBar); //add the configure button. var configButton = createButton('Configure'); configButton.hide(); configButton.click(function() { if ($('#rmcMonConfig').is(':hidden')) { $('#rmcMonConfig').show(); } else { $('#rmcMonConfig').hide(); } }); rmcMonTab.append(configButton); //add configure div rmcMonTab.append("
"); $('#rmcMonConfig').hide(); //load the configure div's content loadRmcMonConfigure(); //add the content of the rmcmon, id = 'rmcMonTab' rmcMonTab.append("
"); $('#nodeDetail').hide(); //check the software work status by platform(linux and aix) $.ajax( { url : 'lib/systemcmd.php', dataType : 'json', data : { cmd : 'ostype' }, success : rsctRpmCheck }); } function loadRmcMonConfigure(){ //get the configure div and clean its content. var rmcmonCfgDiv = $('#rmcMonConfig'); rmcmonCfgDiv.empty(); //add the start button var startButton = createButton('Start'); rmcmonCfgDiv.append(startButton); startButton.click(function(){ $('#rmcMonStatus div').empty().append(createLoader()); $.ajax({ url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'webrun', tgt : '', args : 'rmcstart;compute', msg : '' }, success : function(data){ $('#rmcMonStatus div').empty().append(data.rsp[0]); } }); }); //add the stop button var stopButton = createButton('Stop'); rmcmonCfgDiv.append(stopButton); stopButton.click(function(){ $('#rmcMonStatus div').empty().append(createLoader()); $.ajax({ url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'monstop', tgt : '', args : 'rmcmon', msg : '' }, success : function(data){ $('#rmcMonStatus div').empty().append(data.rsp[0]); } }); }); //add the cancel button var cancelButton = createButton('Cancel'); rmcmonCfgDiv.append(cancelButton); cancelButton.click(function(){ $('#rmcMonConfig').hide(); }); } function rsctRpmCheck(data){ //linux had to check the rscp first if ('aix' != data.rsp){ $.ajax( { url : 'lib/systemcmd.php', dataType : 'json', data : { cmd : 'rpm -q rsct.core' }, success : function(data){ if (-1 != data.rsp.indexOf("not")){ $('#rmcMonStatus div').empty().append( 'Please install the RSCT first.
' + 'You can find more support from xCAT2-Monitoring.pdf'); } else{ xcatrmcRpmCheck(); } } }); } else{ xcatrmcRpmCheck(); } } function xcatrmcRpmCheck(){ $.ajax( { url : 'lib/systemcmd.php', dataType : 'json', data : { cmd : 'rpm -q xCAT-rmc rrdtool' }, success : function(data){ var softInstallStatus = data.rsp.split(/\n/); var needHelp = false; $('#rmcMonStatus div').empty(); //check the xcat-rmc if (-1 != softInstallStatus[0].indexOf("not")){ needHelp = true; $('#rmcMonStatus div').append( 'Please install the xCAT-rmc first.
'); } //check the rrdtool if (-1 != softInstallStatus[1].indexOf("not")){ needHelp = true; $('#rmcMonStatus div').append( 'Please install the RRD-tool first.
'); } //add help info or load the rmc show if (needHelp){ $('#rmcMonStatus div').append( 'You can find more support form xCAT2-Monitoring.pdf'); } else{ rmcWorkingCheck(); } } }); } function rmcWorkingCheck(){ $('#rmcMonStatus div').empty().append("Checking RMC working status."); $('#rmcMonStatus div').append(createLoader()); $('#rmcmon button:first').show(); $.ajax({ url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'monls', tgt : '', args : 'rmcmon', msg : '' }, success : function(data){ if (-1 != data.rsp[0].indexOf("not-monitored")){ $('#rmcMonStatus div').empty().append("Please start the RMC Monitoring first."); return; } loadRmcMonShow(); } }); } function removeStatusBar(){ if (globalAllNodesNum == globalFinishNodesNum){ $('#rmcMonStatus').remove(); } $('#rmcmonDetail [title]').tooltip({position:['center','right']}); } function loadRmcMonShow(){ $('#rmcMonStatus div').empty().append("Getting Summary Data."); $('#rmcMonStatus div').append(createLoader()); //load the rmc status summary $.ajax({ url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'webrun', tgt : '', args : 'rmcshow;summary;PctTotalTimeIdle,PctRealMemFree', msg : '' }, success : function(data){ showRmcSummary(data.rsp[0]); } }); } function showRmcSummary(returnData) { var attributes = returnData.split(';'); var attr; var attrName; var attrValues; var attrDiv; var summaryTable = $('
'); var summaryRow; globalTimeStamp = new Array(); //update the rmc status area $('#rmcMonStatus div').empty().append("Getting Nodes' Data").append(createLoader()); //load each nodes' status $.ajax( { url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'webrun', tgt : '', args : 'rmcshow;compute;PctTotalTimeIdle,PctRealMemFree', msg : '' }, success : function(data) { parseRmcData(data.rsp); } }); //create the timestamp, the flot only use the UTC time, so had to change //the value, to show the right time var tempDate = new Date(); var tempOffset = tempDate.getTimezoneOffset(); var tempTime = tempDate.getTime() - 3600000; for ( var i = 0; i < 60; i++) { tempDate.setTime(tempTime + i * 60000); globalTimeStamp.push(tempDate.getTime()); } //show the summary data $('#rmcmonSummary').empty().append('

Overview


'); $('#rmcmonSummary').append(summaryTable); for (attr in attributes) { var tempTd = $(''); var tempArray = []; var temp = attributes[attr].indexOf(':'); attrName = attributes[attr].substr(0, temp); attrValues = attributes[attr].substr(temp + 1).split(','); if (0 == (attr % 3)) { summaryRow = $(''); summaryTable.append(summaryRow); } summaryRow.append(tempTd); attrDiv = $('
'); tempTd.append(attrDiv); for ( var i in attrValues) { tempArray.push( [ globalTimeStamp[i], Number(attrValues[i]) ]); } $.jqplot('monitorsumdiv' + attr, [ tempArray ], { series : [ { showMarker : false } ], axes : { xaxis : { label : attrName, renderer : $.jqplot.DateAxisRenderer, numberTicks : 5, tickOptions : { formatString : '%R', show : true, fontSize : '10px' } }, yaxis : { tickOptions : { formatString : '%.2f', fontSize : '10px' } } } }); } } function parseRmcData(returnData){ var nodeName; var nodeStatus; $('#rmcmonDetail').empty().append('

Detail


'); //add the table for show nodes var detailUl = $(''); //update the table area $('#rmcmonDetail ul').remove(); $('#rmcmonDetail').append(detailUl); globalAllNodesNum = returnData.length; globalFinishNodesNum = 0; for(var i in returnData){ var temp = returnData[i].indexOf(':');; nodeName = returnData[i].substr(0, temp); nodeStatus = returnData[i].substr(temp + 1).replace(/(^\s*)|(\s*$)/g, ''); if ('OK' != nodeStatus){ globalFinishNodesNum++; detailUl.append(createUnkownNode(nodeName)); removeStatusBar(); continue; } $.ajax({ url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'webrun', tgt : '', args : 'rmcshow;' + nodeName + ';PctTotalTimeIdle,PctRealMemFree', msg : nodeName }, success : function(data){ showRmcNodes(data.rsp, data.msg); } }); } } function createUnkownNode(nodeName){ var tempLi = '
  • '; return tempLi; } function createErrorNode(nodeName){ var tempLi = '
  • '; } function showRmcNodes(data, nodename) { var attrname = ''; var values = ''; var position = 0; var index = 0; var classname = ''; var tempObj = {}; for (index in data){ position = data[index].indexOf(':'); attrname = data[index].substr(0, position); values = data[index].substr(position + 1); //error node, can not get the last hour's data if ('' == values){ $('#rmcmonDetail ul').append(createErrorNode(nodename)); if (globalNodesDetail[nodename]){ delete(globalNodesDetail[nodename]); } return; } //normal node, save the values tempObj[attrname] = values; } globalNodesDetail[nodename] = tempObj; //get each average var cpuAvg = 0; var memAvg = 0; var tempSum = 0; var tempArray = globalNodesDetail[nodename]['PctTotalTimeIdle'].split(','); for (index = 0; index < tempArray.length; index++){ tempSum += Number(tempArray[index]); } cpuAvg = parseInt(tempSum / index); tempArray = globalNodesDetail[nodename]['PctRealMemFree'].split(','); tempSum = 0; for (index = 0; index < tempArray.length; index++){ tempSum += Number(tempArray[index]); } memAvg = parseInt(tempSum / index); if (cpuAvg >= 10 && memAvg <= 90){ classname = 'rmcnormal'; } else{ classname = 'rmcwarning'; } var normalLi = $('
  • '); $('#rmcmonDetail ul').append(normalLi); normalLi.bind('click', function() { showNode($(this).attr('id')); }); //check if the process finished globalFinishNodesNum++; removeStatusBar(); } function showNode(nodeName) { var nodeTable = $('
    '); var backButton = createButton('Go back to all nodes'); var nodeRow; var parseNum = 0; $('#rmcmonDetail').hide(); $('#nodeDetail').empty().show(); $('#nodeDetail').append('

    ' + nodeName + ' Detail


    '); $('#nodeDetail').append(backButton); backButton.bind('click', function() { $('#nodeDetail').hide(); $('#rmcmonDetail').show(); }); $('#nodeDetail').append(nodeTable); for ( var attr in globalNodesDetail[nodeName]) { var tempTd = $(''); var attrChat = $('
    '); if (0 == parseNum % 4) { nodeRow = $(''); nodeTable.append(nodeRow); } nodeRow.append(tempTd); parseNum++; // data tempTd.append(attrChat); var tempData = globalNodesDetail[nodeName][attr].split(','); var tempArray = []; for ( var i in tempData) { tempArray.push( [ globalTimeStamp[i], Number(tempData[i]) ]); } $.jqplot('monitornodediv' + nodeName + attr, [ tempArray ], { series : [ { showMarker : false } ], axes : { xaxis : { label : attr, renderer : $.jqplot.DateAxisRenderer, numberTicks : 5, tickOptions : { formatString : '%R', show : true, fontSize : '10px' } }, yaxis : { tickOptions : { formatString : '%.2f', fontSize : '10px' } } } }); } } /*===========RMC Event Tab============*/ /** * load the rmc event tab. * * @param * * @return * */ function loadRmcEvent(){ //find the rmcevent tab //add the stauts bar first. id = 'rmcMonStatus' var rmcStatusBar = createStatusBar('rmcEventStatus'); rmcStatusBar.find('div').append(createLoader()); $('#rmcevent').append(rmcStatusBar); $('#rmcevent').append('
    '); $.ajax( { url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'webrun', tgt : '', args : 'lsevent;-O;1000', msg : '' }, success : showEventLog }); } /** * get all conditions * * @return * */ function getConditions(){ if ('' == globalCondition){ $('#rmcEventStatus div').empty().append('Getting predefined conditions').append(createLoader()); $.ajax({ url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'webrun', tgt : '', args : 'lscondition', msg : '' }, success : function (data){ $('#rmcEventStatus div').empty(); $('#rmcEventButtons').show(); globalCondition = data.rsp[0]; } }); } else{ $('#rmcEventButtons').show(); } } /** * get all response * * @return * */ function getResponse(){ var tempFlag = false; //get all response first for (var i in globalResponse){ tempFlag = true; break; } if (!tempFlag){ $.ajax({ url : 'lib/cmd.php', dataType : 'json', data : { cmd : 'webrun', tgt : '', args : 'lsresponse', msg : '' }, success : function(data){ var resps = data.rsp[0].split(';'); for (var i in resps){ var name = resps[i]; name = name.substr(1, (name.length - 2)); globalResponse[name] = 1; } } }); } } /** * show all the event in the rmc event tab * * @param data response from the xcat server. * @return * */ function showEventLog(data){ $('#rmcEventStatus div').empty(); // rsct not installed. if (data.rsp[0] && (-1 != data.rsp[0].indexOf('lsevent'))){ $('#rmcEventStatus div').append('Please install RSCT first!'); return; } var eventDiv = $('#rmcEventDiv'); eventDiv.empty(); //add the configure button loadRmcEventConfig(); //get conditions and responses, save in the global getConditions(); getResponse(); var eventTable = new DataTable('lsEventTable'); eventTable.init(['Time', 'Type', 'Content']); for (var i in data.rsp){ var row = data.rsp[i].split(';'); eventTable.add(row); } eventDiv.append(eventTable.object()); $('#lsEventTable').dataTable({ 'bFilter' : true, 'bLengthChange' :true, 'bSort' :true, 'bPaginate' :true, 'iDisplayLength' :10 }); //unsort on the content column $('#lsEventTable thead tr th').eq(2).unbind('click'); } /** * Add the configure button into rmc event tab * * @param * @return * */ function loadRmcEventConfig(){ var buttons = $(''); var chCondScopeBut = createButton('Change Condition Scope'); chCondScopeBut.bind('click', function(){ chCondScopeDia(); }); buttons.append(chCondScopeBut); var mkCondRespBut = createButton('Make/Remove Association'); mkCondRespBut.bind('click', function(){ mkCondRespDia(); }); buttons.append(mkCondRespBut); var startCondRespBut = createButton('Start/Stop Association'); startCondRespBut.bind('click', function(){ startStopCondRespDia(); }); buttons.append(startCondRespBut); $('#rmcEventDiv').append(buttons); } /** * show the make association dialogue * * @param * @return * */ function mkCondRespDia(){ var diaDiv = $('
    '); var mkAssociationTable = '
    '; mkAssociationTable += '
    Condition NameResponse Name
    '; //add the conditions into fieldset if ('' == globalCondition){ mkAssociationTable += 'Getting predefined conditions, open this dislogue later.'; } else{ mkAssociationTable += createConditionTd(globalCondition); } mkAssociationTable += 'Plase select condition first.
    '; diaDiv.append(mkAssociationTable); diaDiv.append('