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
2011-07-20 21:13:09 +00:00
var info = createInfoBar ( 'Select a group to view the nodes summary' ) ;
2010-11-05 22:53:47 +00:00
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 ( ) ;
2011-07-20 21:13:09 +00:00
// Save group in cookie
2010-11-05 22:53:47 +00:00
var groups = data . rsp ;
setGroupsCookies ( data ) ;
// Create a list of groups
2011-07-20 21:13:09 +00:00
$ ( '#groups' ) . append ( '<div class="grouplabel">Groups</div>' ) ;
var grouplist = $ ( '<div class="groupdiv"></div>' ) ;
2010-11-05 22:53:47 +00:00
// Create a link for each group
2011-07-20 21:13:09 +00:00
for ( var i = groups . length ; i -- ; ) {
grouplist . append ( '<div><a href="#">' + groups [ i ] + '</a></div>' ) ;
2010-11-05 22:53:47 +00:00
}
2011-07-20 21:13:09 +00:00
$ ( '#groups' ) . append ( grouplist ) ;
// Bind the click event
$ ( '#groups .groupdiv div' ) . bind ( 'click' , function ( ) {
$ ( '#nodes .jqplot-target' ) . remove ( ) ;
// Create loader
var loader = createLoader ( ) ;
loader . css ( 'padding' , '5px' ) ;
$ ( '#nodes' ) . append ( loader ) ;
var thisGroup = $ ( this ) . text ( ) ;
$ ( '#groups .groupdiv div' ) . removeClass ( 'selectgroup' ) ;
$ ( this ) . addClass ( 'selectgroup' ) ;
$ . ajax ( {
url : 'lib/cmd.php' ,
dataType : 'json' ,
data : {
cmd : 'nodels' ,
tgt : thisGroup ,
args : '' ,
msg : thisGroup
} ,
2010-11-05 22:53:47 +00:00
2011-07-20 21:13:09 +00:00
/ * *
* Get node definitions
*
* @ 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 : {
cmd : 'nodestat' ,
tgt : group ,
args : '' ,
msg : group
} ,
2011-01-14 05:05:06 +00:00
2011-07-20 21:13:09 +00:00
success : loadGangliaSummary
} ) ;
2010-11-12 14:01:28 +00:00
}
2011-07-20 21:13:09 +00:00
} ) ;
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-07-20 21:13:09 +00:00
if ( node ) {
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 ++ ;
} else {
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-07-20 21:13:09 +00:00
var pie = [ [ 'Ping + monitored' , pingWGanglia ] , [ 'Ping + not monitored' , pingWOGanglia ] , [ 'Noping' , noping ] ] ;
var plot = $ . jqplot ( 'ganglia_sum' ,
[ pie ] , {
seriesDefaults : {
renderer : $ . jqplot . PieRenderer ,
rendererOptions : {
padding : 5 ,
fill : true ,
shadow : true ,
shadowOffset : 2 ,
shadowDepth : 5 ,
shadowAlpha : 0.07 ,
dataLabels : 'value' ,
showDataLabels : true
}
} ,
legend : {
show : true ,
location : 'e'
}
} ) ;
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-07-20 21:13:09 +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
}