2011-01-13 23:06:31 +00:00
/ * *
* Global variables
* /
2011-01-14 20:25:14 +00:00
var gangliaTableId = 'nodesDatatable' ;
2011-05-02 20:33:25 +00:00
var gangliaData ;
2011-01-13 23:06:31 +00:00
2010-11-05 22:53:47 +00:00
/ * *
* Load Ganglia monitoring tool
*
* @ return Nothing
* /
function loadGangliaMon ( ) {
// Get Ganglia tab
var gangliaTab = $ ( '#gangliamon' ) ;
2010-11-17 18:53:40 +00:00
2010-11-05 22:53:47 +00:00
// Check whether Ganglia RPMs are installed on the xCAT MN
2011-01-14 05:05:06 +00:00
$ . ajax ( {
2010-09-17 08:39:17 +00:00
url : 'lib/systemcmd.php' ,
dataType : 'json' ,
data : {
cmd : 'rpm -q rrdtool ganglia-gmetad ganglia-gmond ganglia-web'
} ,
2010-11-05 22:53:47 +00:00
success : checkGangliaRPMs
2010-09-17 08:39:17 +00:00
} ) ;
2010-11-17 18:53:40 +00:00
2010-11-05 22:53:47 +00:00
// Create groups and nodes DIV
var groups = $ ( '<div id="groups"></div>' ) ;
var nodes = $ ( '<div id="nodes"></div>' ) ;
gangliaTab . append ( groups ) ;
gangliaTab . append ( nodes ) ;
2010-09-17 08:39:17 +00:00
2010-11-05 22:53:47 +00:00
// Create info bar
var info = createInfoBar ( 'Select a group to view its nodes' ) ;
nodes . append ( info ) ;
// Get groups
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'extnoderange' ,
tgt : '/.*' ,
args : 'subgroups' ,
msg : ''
} ,
success : loadGroups4Ganglia
2010-09-17 08:39:17 +00:00
} ) ;
2010-11-05 22:53:47 +00:00
return ;
2010-09-17 08:39:17 +00:00
}
2010-11-05 22:53:47 +00:00
/ * *
* Check whether Ganglia RPMs are installed
*
* @ param data
* Data returned from HTTP request
* @ return Nothing
* /
function checkGangliaRPMs ( data ) {
var gangliaTab = $ ( '#gangliamon' ) ;
2010-11-17 18:53:40 +00:00
2010-11-05 22:53:47 +00:00
// Get the list of Ganglia RPMs installed
var status = data . rsp . split ( /\n/ ) ;
var gangliaRPMs = [ "rrdtool" , "ganglia-gmetad" , "ganglia-gmond" , "ganglia-web" ] ;
var warningMsg = 'Before continuing, please install the following packages: ' ;
var missingRPMs = false ;
for ( var i in status ) {
if ( status [ i ] . indexOf ( "not installed" ) > - 1 ) {
warningMsg += gangliaRPMs [ i ] + ' ' ;
missingRPMs = true ;
}
}
2010-11-17 18:53:40 +00:00
2010-11-05 22:53:47 +00:00
// Append Ganglia PDF
if ( missingRPMs ) {
warningMsg += ". Refer to <a href='http://xcat.svn.sourceforge.net/viewvc/xcat/xcat-core/trunk/xCAT-client/share/doc/xCAT2-Monitoring.pdf'>xCAT2-Monitoring.pdf</a> for more information." ;
2010-11-17 18:53:40 +00:00
2010-11-05 22:53:47 +00:00
var warningBar = createWarnBar ( warningMsg ) ;
warningBar . css ( 'margin-bottom' , '10px' ) ;
warningBar . prependTo ( gangliaTab ) ;
2010-11-06 00:15:13 +00:00
} else {
// Check if ganglia is running on the xCAT MN
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'monls' ,
tgt : '' ,
args : 'gangliamon' ,
msg : ''
} ,
/ * *
* Append warning message
*
* @ param data
* Data returned from HTTP request
* @ return Nothing
* /
success : function ( data ) {
if ( data . rsp [ 0 ] . indexOf ( "not-monitored" ) > - 1 ) {
// Create link to start Ganglia
2011-01-19 15:56:43 +00:00
var startLnk = $ ( '<a href="#">Click here</a>' ) ;
startLnk . css ( {
'color' : 'blue' ,
'text-decoration' : 'none'
} ) ;
startLnk . click ( function ( ) {
// Turn on Ganglia for all nodes
monitorNode ( '' , 'on' ) ;
} ) ;
// Create warning bar
var warningBar = $ ( '<div class="ui-state-error ui-corner-all"></div>' ) ;
var msg = $ ( '<p></p>' ) ;
msg . append ( '<span class="ui-icon ui-icon-alert"></span>' ) ;
msg . append ( 'Please start Ganglia Monitoring on xCAT. ' ) ;
msg . append ( startLnk ) ;
msg . append ( ' to start Ganglia Monitoring.' ) ;
warningBar . append ( msg ) ;
warningBar . css ( 'margin-bottom' , '10px' ) ;
// If there are any warning messages, append this warning after it
var curWarnings = $ ( '#gangliamon' ) . find ( '.ui-state-error' ) ;
var gangliaTab = $ ( '#gangliamon' ) ;
if ( curWarnings . length ) {
curWarnings . after ( warningBar ) ;
} else {
warningBar . prependTo ( gangliaTab ) ;
}
}
2010-11-06 00:15:13 +00:00
}
2010-11-17 18:53:40 +00:00
} ) ;
2010-11-06 00:15:13 +00:00
}
2010-11-05 22:53:47 +00:00
return ;
}
/ * *
* Load groups
*
* @ param data
* Data returned from HTTP request
* @ return
* /
function loadGroups4Ganglia ( data ) {
// Remove loader
$ ( '#groups' ) . find ( 'img' ) . remove ( ) ;
2010-11-17 18:53:40 +00:00
2010-11-05 22:53:47 +00:00
var groups = data . rsp ;
setGroupsCookies ( data ) ;
// Create a list of groups
var ul = $ ( '<ul></ul>' ) ;
var item = $ ( '<li id="root"><h3>Groups</h3></li>' ) ;
ul . append ( item ) ;
var subUL = $ ( '<ul></ul>' ) ;
item . append ( subUL ) ;
// Create a link for each group
for ( var i = groups . length ; i -- ; ) {
2010-11-12 14:01:28 +00:00
var subItem = $ ( '<li id="' + groups [ i ] + '"></li>' ) ;
var link = $ ( '<a>' + groups [ i ] + '</a>' ) ;
2010-11-05 22:53:47 +00:00
subItem . append ( link ) ;
subUL . append ( subItem ) ;
}
// Turn groups list into a tree
$ ( '#groups' ) . append ( ul ) ;
$ ( '#groups' ) . jstree ( {
2010-11-17 18:53:40 +00:00
core : {
"initially_open" : [ "root" ]
} ,
2010-11-05 22:53:47 +00:00
themes : {
"theme" : "default" ,
2010-11-17 18:53:40 +00:00
"dots" : false , // No dots
"icons" : false // No icons
2010-11-05 22:53:47 +00:00
}
2010-09-17 08:39:17 +00:00
} ) ;
2010-11-17 18:53:40 +00:00
2010-11-12 14:01:28 +00:00
// Load nodes onclick
2011-01-14 05:05:06 +00:00
$ ( '#groups' ) . bind ( 'select_node.jstree' , function ( event , data ) {
2010-11-18 00:39:27 +00:00
// If there are subgroups, remove them
data . rslt . obj . children ( 'ul' ) . remove ( ) ;
2010-11-17 18:53:40 +00:00
var thisGroup = jQuery . trim ( data . rslt . obj . text ( ) ) ;
if ( thisGroup ) {
// Clear nodes division
2010-11-12 14:01:28 +00:00
$ ( '#nodes' ) . children ( ) . remove ( ) ;
2010-11-17 18:53:40 +00:00
2010-11-12 14:01:28 +00:00
// Create link to Ganglia
2011-05-02 20:33:25 +00:00
var gangliaLnk = $ ( '<a href="#">Click here</a>' ) ;
2010-11-12 14:01:28 +00:00
gangliaLnk . css ( {
'color' : 'blue' ,
'text-decoration' : 'none'
} ) ;
gangliaLnk . click ( function ( ) {
// Open a new window for Ganglia
window . open ( '../ganglia/' ) ;
} ) ;
// Create info bar
var info = $ ( '<div class="ui-state-highlight ui-corner-all"></div>' ) ;
2011-04-14 20:28:18 +00:00
info . append ( '<span class="ui-icon ui-icon-info" style="display: inline-block; margin: 10px 5px;"></span>' ) ;
var msg = $ ( '<p style="display: inline-block; width: 95%;"></p>' ) ;
2011-05-02 20:33:25 +00:00
msg . append ( 'Below is a summary of nodes within the selected group. ' ) ;
2010-11-12 14:01:28 +00:00
msg . append ( gangliaLnk ) ;
2011-04-21 19:09:11 +00:00
msg . append ( ' to open the Ganglia page.' ) ;
2010-11-12 14:01:28 +00:00
info . append ( msg ) ;
info . css ( 'margin-bottom' , '10px' ) ;
$ ( '#nodes' ) . append ( info ) ;
// Create loader
var loader = $ ( '<center></center>' ) . append ( createLoader ( ) ) ;
2011-05-02 20:33:25 +00:00
$ ( '#nodes' ) . append ( loader ) ;
2010-11-17 18:53:40 +00:00
2011-01-14 05:05:06 +00:00
// To improve performance, get all nodes within selected group
// Get node definitions only for first 50 nodes
2010-11-12 14:01:28 +00:00
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
2011-01-14 05:05:06 +00:00
cmd : 'nodels' ,
tgt : thisGroup ,
args : '' ,
2010-11-12 14:01:28 +00:00
msg : thisGroup
} ,
2011-01-14 05:05:06 +00:00
/ * *
2011-05-02 20:33:25 +00:00
* Get node definitions
2011-01-14 05:05:06 +00:00
*
* @ param data
* Data returned from HTTP request
* @ return Nothing
* /
success : function ( data ) {
var group = data . msg ;
// Get nodes definitions
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
2011-05-02 20:33:25 +00:00
cmd : 'nodestat' ,
tgt : group ,
args : '' ,
2011-01-14 05:05:06 +00:00
msg : group
} ,
2011-05-02 20:33:25 +00:00
success : loadGangliaSummary
2011-01-14 05:05:06 +00:00
} ) ;
}
2010-11-12 14:01:28 +00:00
} ) ;
2011-01-14 05:05:06 +00:00
// Get subgroups within selected group
// only when this is the parent group and not a subgroup
2010-11-12 14:01:28 +00:00
if ( data . rslt . obj . attr ( 'id' ) . indexOf ( 'Subgroup' ) < 0 ) {
2011-01-14 05:05:06 +00:00
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'extnoderange' ,
tgt : thisGroup ,
args : 'subgroups' ,
msg : thisGroup
} ,
success : loadSubgroups
} ) ;
2010-11-12 14:01:28 +00:00
}
} // End of if (thisGroup)
2010-12-21 02:47:30 +00:00
} ) ;
2010-09-17 08:39:17 +00:00
}
2010-09-24 02:27:04 +00:00
2010-11-05 22:53:47 +00:00
/ * *
2011-05-02 20:33:25 +00:00
* Load Ganglia summary page
2010-11-05 22:53:47 +00:00
*
* @ param data
* Data returned from HTTP request
* @ return Nothing
* /
2011-05-02 20:33:25 +00:00
function loadGangliaSummary ( data ) {
2010-11-05 22:53:47 +00:00
// Data returned
var rsp = data . rsp ;
// Group name
var group = data . msg ;
// Node attributes hash
var attrs = new Object ( ) ;
2010-12-09 03:44:11 +00:00
2011-05-02 20:33:25 +00:00
var node , status , args ;
2010-11-05 22:53:47 +00:00
for ( var i in rsp ) {
// Get key and value
2011-05-02 20:33:25 +00:00
args = rsp [ i ] . split ( ':' , 2 ) ;
node = jQuery . trim ( args [ 0 ] ) ;
status = jQuery . trim ( args [ 1 ] ) ;
2011-01-14 05:05:06 +00:00
2010-11-05 22:53:47 +00:00
// Create a hash table
2011-05-02 20:33:25 +00:00
attrs [ node ] = new Object ( ) ;
attrs [ node ] [ 'status' ] = status ;
2010-11-05 22:53:47 +00:00
}
2011-01-14 05:05:06 +00:00
2011-05-02 20:33:25 +00:00
// Save node attributes hash
gangliaData = attrs ;
2011-01-14 05:05:06 +00:00
2010-11-05 22:53:47 +00:00
// Get the status of Ganglia
2011-05-02 20:33:25 +00:00
// Then create pie chart for node and Ganglia status
2010-11-05 22:53:47 +00:00
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'webrun' ,
tgt : '' ,
2011-05-02 20:33:25 +00:00
args : 'gangliastatus;' + group ,
2010-11-05 22:53:47 +00:00
msg : ''
} ,
success : loadGangliaStatus
} ) ;
}
/ * *
* Load the status of Ganglia for a given group
*
* @ param data
* Data returned from HTTP request
* @ return Nothing
* /
function loadGangliaStatus ( data ) {
2011-05-02 20:33:25 +00:00
// Remove loader
$ ( '#nodes' ) . find ( 'img' ) . remove ( ) ;
2010-11-05 22:53:47 +00:00
// Get datatable
var ganglia = data . rsp ;
2011-05-02 20:33:25 +00:00
var node , ping , monitored ;
2010-11-05 22:53:47 +00:00
2011-05-02 20:33:25 +00:00
// Count nodes that are pingable and not pingable
// and nodes that are pingable and monitored by Ganglia
var pingWGanglia = 0 ;
var pingWOGanglia = 0 ;
var noping = 0 ;
2010-11-05 22:53:47 +00:00
for ( var i in ganglia ) {
// ganglia[0] = nodeName and ganglia[1] = state
node = jQuery . trim ( ganglia [ i ] [ 0 ] ) ;
2011-05-02 20:33:25 +00:00
monitored = jQuery . trim ( ganglia [ i ] [ 1 ] ) ;
ping = gangliaData [ node ] [ 'status' ] ;
// If the node is monitored, increment count
if ( ping == 'sshd' && monitored == 'on' ) {
pingWGanglia ++ ;
} else if ( ping == 'sshd' && monitored == 'off' ) {
pingWOGanglia ++ ;
2010-11-05 22:53:47 +00:00
} else {
2011-05-02 20:33:25 +00:00
noping ++ ;
2011-01-14 05:05:06 +00:00
}
}
2011-05-02 20:33:25 +00:00
// Create pie chart
var summary = $ ( '<div id="ganglia_sum"></div>' ) ;
$ ( '#nodes' ) . append ( summary ) ;
2011-01-14 05:05:06 +00:00
2011-05-02 20:33:25 +00:00
// Create pie details
var details = $ ( '<div id="ganglia_details"></div>' ) ;
$ ( '#nodes' ) . append ( details ) ;
2011-01-14 05:05:06 +00:00
2011-05-02 20:33:25 +00:00
var pie = [ [ 'Ping & monitored' , pingWGanglia ] , [ 'Ping & not monitored' , pingWOGanglia ] , [ 'Noping' , noping ] ] ;
var chart = $ . jqplot ( 'ganglia_sum' , [ pie ] , {
seriesDefaults : {
renderer : $ . jqplot . PieRenderer
} ,
seriesColors : [
'#3CB548' , '#FE9A2E' , '#848484' // Green, orange, grey
] ,
legend : {
show : true
} ,
grid : {
background : 'transparent' ,
borderColor : 'white' ,
borderWidth : '0px' ,
shadow : false
} ,
show : true
} ) ;
2011-01-14 05:05:06 +00:00
2011-05-02 20:33:25 +00:00
// Change CSS styling for legend
summary . find ( 'table' ) . css ( {
'border-style' : 'none'
} ) . find ( 'td' ) . css ( {
'border-style' : 'none'
} ) ;
2011-01-14 05:05:06 +00:00
2011-05-02 20:33:25 +00:00
// Show details on mouse-over
$ ( '#ganglia_sum' ) . bind ( 'jqplotDataMouseOver' , function ( env , srIndex , ptIndex , data ) {
// Show for 8 seconds before sliding up
$ ( '#ganglia_details' ) . children ( ) . remove ( ) ;
$ ( '#ganglia_details' ) . show ( ) ;
$ ( '#ganglia_details' ) . append ( $ ( '<p>' + data [ 1 ] + ' node(s) ' + data [ 0 ] + '</p>' ) ) ;
$ ( '#ganglia_details' ) . delay ( 8000 ) . slideUp ( ) ;
} ) ;
2011-01-14 05:05:06 +00:00
2011-05-02 20:33:25 +00:00
// Open nodes page on-click
$ ( '#ganglia_sum' ) . bind ( 'jqplotDataClick' , function ( env , srIndex , ptIndex , data ) {
window . open ( '../xcat/index.php' ) ;
2011-01-14 05:05:06 +00:00
} ) ;
2011-04-27 20:28:00 +00:00
2011-05-02 20:33:25 +00:00
// Special note
// To redraw pie chart:
// - Use chart.series[0].data[i] to reference existing data
// - Use chart.redraw() to redraw chart
2010-09-17 08:39:17 +00:00
}