LSP: added server stats page and version update check

This commit is contained in:
cat 2013-01-15 19:40:26 +01:00 committed by Thulinma
parent d0040e9b41
commit b5bb288ac0
4 changed files with 200 additions and 84 deletions

View file

@ -79,6 +79,8 @@
// what kind of streams should be displayed? Format is [recorded, live];
var streamsdisplay = [true, true];
// used on the overview page to decide then to ask the controller for an update check
var updatelastchecked;
/**
* Display a certain page. It contains a (giant) switch-statement, that builds a page depending on the tab requested
@ -172,82 +174,117 @@
case 'overview':
$('#page').append(
$('<div>').attr('id', 'editserver').append(
$('<label>').attr('for', 'config-host').text('host').append(
$('<input>').attr('type', 'text').attr('placeholder', 'HOST').attr('id', 'config-host').attr('value', settings.settings.config.host)
)
).append(
$('<label>').attr('for', 'config-name').text('name').append(
$('<input>').attr('type', 'text').attr('placeholder', 'NAME').attr('id', 'config-name').attr('value', settings.settings.config.name)
)
).append(
$('<label>').text('version').append(
$('<span>').text(settings.settings.config.version)
)
).append(
$('<label>').text('time').append(
$('<span>').text( formatDate(settings.settings.config.time) )
)
).append(
$('<label>').text('Streams').append(
$('<span>').attr('id', 'cur_streams_online').text('retrieving data...')
)
).append(
$('<label>').text('Viewers').append(
$('<span>').attr('id', 'cur_num_viewers').text('retrieving data...')
)
)
);
loadSettings(function(){
$uptodate = null;
if (settings.settings.LTS == 1)
{
if ((settings.settings.update == undefined) || (updatelastchecked == undefined) || ((new Date()).getTime() - updatelastchecked > 3600000))
{
settings.settings.checkupdate = true;
settings.settings.update = {};
updatelastchecked = (new Date()).getTime();
loadSettings(function()
{
showTab('overview');
});
}
else
{
if (settings.settings.update.uptodate == 0)
{
$uptodate = $('<label>').text('version check').css('line-height','30px');
$uptodate.append(
$('<span>').attr('class','red').text('Outdated version!').append(
$('<button>').text('update').click(function(){
settings.settings.autoupdate = true;
loadSettings();
})
)
);
}
}
}
$('#page').append(
$('<div>').attr('id', 'editserver').append(
$('<label>').attr('for', 'config-host').text('host').append(
$('<input>').attr('type', 'text').attr('placeholder', 'HOST').attr('id', 'config-host').attr('value', settings.settings.config.host)
)
).append(
$('<label>').attr('for', 'config-name').text('name').append(
$('<input>').attr('type', 'text').attr('placeholder', 'NAME').attr('id', 'config-name').attr('value', settings.settings.config.name)
)
).append(
$('<label>').text('version').append(
$('<span>').text(settings.settings.config.version)
).append($uptodate)
).append(
$('<label>').text('time').append(
$('<span>').text( formatDate(settings.settings.config.time) )
)
).append(
$('<label>').text('Streams').append(
$('<span>').attr('id', 'cur_streams_online').text('retrieving data...')
)
).append(
$('<label>').text('Viewers').append(
$('<span>').attr('id', 'cur_num_viewers').text('retrieving data...')
)
)
);
function showStats()
{
getStatData(function(data)
{
$('#cur_streams_online').html('').text(data.streams[0] + ' of ' + data.streams[1] + ' online');
$('#cur_num_viewers').html('').text(data.viewers);
});
}
// refresh the stream status + viewers
sinterval = setInterval(function()
{
showStats();
}, 10000);
showStats();
$('#editserver').append(
$('<button>').attr('class', 'floatright').click(function()
{
var host = $('#config-host').val();
var name = $('#config-name').val();
settings.settings.config.host = host;
settings.settings.config.name = name;
loadSettings(function()
{
showTab('overview');
});
}).text( 'save' )
);
var forcesave = $('<div>').attr('id', 'forcesave');
forcesave.append(
$('<p>').text('Click the button below to force an immediate settings save. This differs from a regular save to memory and file save on exit by saving directly to file while operating. This may slow server processes for a short period of time.')
).append(
$('<button>').click(function()
{
if(confirmDelete('Are you sure you want to force a JSON save?') == true)
{
forceJSONSave();
}
}).text( 'force save to JSON file' )
);
$('#page').append(forcesave);
function showStats()
{
getStatData(function(data)
{
$('#cur_streams_online').html('').text(data.streams[0] + ' of ' + data.streams[1] + ' online');
$('#cur_num_viewers').html('').text(data.viewers);
});
}
// refresh the stream status + viewers
sinterval = setInterval(function()
{
showStats();
}, 10000);
showStats();
$('#editserver').append(
$('<button>').attr('class', 'floatright').click(function()
{
var host = $('#config-host').val();
var name = $('#config-name').val();
settings.settings.config.host = host;
settings.settings.config.name = name;
loadSettings(function()
{
showTab('overview');
});
}).text( 'save' )
);
var forcesave = $('<div>').attr('id', 'forcesave');
forcesave.append(
$('<p>').text('Click the button below to force an immediate settings save. This differs from a regular save to memory and file save on exit by saving directly to file while operating. This may slow server processes for a short period of time.')
).append(
$('<button>').click(function()
{
if(confirmDelete('Are you sure you want to force a JSON save?') == true)
{
forceJSONSave();
}
}).text( 'force save to JSON file' )
);
$('#page').append(forcesave);
});
break;
@ -298,7 +335,10 @@
var id = Number($(this).parent().parent().attr('id').replace('protocol-', ''));
var pid = pids.indexOf(id);
settings.settings.config.protocols.splice(pid, 1);
showTab('protocols');
loadSettings(function()
{
showTab('protocols');
});
}
}).text('delete') ) );
@ -338,7 +378,7 @@
}
protocolstatus = data.config.protocols[pid].online;
}
$(this).children()[1].innerHTML = formatStatus( protocolstatus );
$(this).children(':nth-child(2)').html( formatStatus( protocolstatus ) );
});
});
}
@ -641,8 +681,8 @@
{
streamstatus = streams[stream][0];
}
$(this).children()[4].innerHTML = formatStatus(streamstatus);
$(this).children()[5].innerHTML = streams[stream][1];
$(this).children(':nth-child(5)').html(formatStatus(streamstatus));
$(this).children(':nth-child(6)').html(streams[stream][1]);
});
});
};
@ -694,6 +734,8 @@
showTab('embed', sname);
}) ) ); // end function, end click(), end append(), end append(). Huzzah jQuery.
if ( cstr.name == undefined ) { cstr.name = ''; }
$tr.append( $('<td>').text( cstr.name ) );
$tr.append( $('<td>').html( formatStatus( cstr.online ) ) );
@ -1102,6 +1144,65 @@
break;
case 'server stats':
loadSettings(function(){
serverstats = settings.settings.capabilities;
console.log(serverstats); //weghalen
if (serverstats.cpu !== undefined)
{
$('#page').append(
$('<div>').attr('class','datacont').append(
$('<p>').text('CPU')
)
);
//be careful, only works if this is the first div to be constructed
for (property in serverstats.cpu[0])
{
$('#page div.datacont').append(
$('<label>').text(property).append(
$('<span>').text(serverstats.cpu[0][property])
)
);
}
}
if (serverstats.mem !== undefined)
{
$('#page').append(
$('<div>').attr('class','datacont').append(
$('<p>').text('Memory')
).append(
$('<label>').text('Physical memory').append(
$('<span>').text(serverstats.mem.used+'MiB/'+serverstats.mem.total+'MiB ('+serverstats.mem.free+'MiB available)')
)
).append(
$('<label>').text('Swap memory').append(
$('<span>').text((serverstats.mem.swaptotal - serverstats.mem.swapfree)+'MiB/'+serverstats.mem.swaptotal+'MiB ('+serverstats.mem.swapfree+'MiB available)')
)
)
);
}
if (serverstats.load !== undefined)
{
$('#page').append(
$('<div>').attr('class','datacont').append(
$('<p>').text('Load')
).append(
$('<label>').text('Memory used').append(
$('<span>').text(serverstats.load.memory+'%')
)
).append(
$('<label>').text('Loading averages').append(
$('<span>').text('1 min: '+serverstats.load.one+'%, 5 min: '+serverstats.load.five+'%, 15 min: '+serverstats.load.fifteen+'%')
)
)
);
}
});
break;
case 'disconnect':
showTab('login');
setHeaderState('disconnected');