Clean up 'running' history-pulling code

This commit is contained in:
Scott Schneider 2014-02-12 16:27:14 -08:00
parent 18f139905a
commit a8d3369684
2 changed files with 22 additions and 30 deletions

View file

@ -17,22 +17,16 @@ d3.json( running_url+'?history=1',
stats_vcloud_running__data[ 'stack' ] = [];
}
var mytmphash = [];
for ( var c = 0; c < 500; c++ ) {
for ( var key in stats_vcloud_running__data ) {
if ( ! stats_vcloud_running__data[ key ][ 'history' ] ) {
continue;
if ( stats_vcloud_running__data[ key ][ 'history' ] ) {
for ( var c = 0; c < stats_vcloud_running__data[ key ][ 'history' ].length; c++ ) {
if ( typeof stats_vcloud_running__data[ 'stack' ][ c ] === 'undefined' ) {
stats_vcloud_running__data[ 'stack' ][ c ] = {};
}
if ( ! stats_vcloud_running__data[ key ][ 'history' ][ c ] ) {
mytmphash[ key ] = 0;
}
else {
mytmphash[ key ] = stats_vcloud_running__data[ key ][ 'history' ][ c ];
stats_vcloud_running__data[ 'stack' ][ c ][ key ] = stats_vcloud_running__data[ key ][ 'history' ][ c ];
}
}
stats_vcloud_running__data[ 'stack' ].push( mytmphash );
}
( function tick() {

View file

@ -124,32 +124,30 @@ get '/dashboard/stats/vcloud/running' do
if ( params[:history] )
if ( config[:config]['graphite'] )
history ||= Hash.new
begin
buffer = open( 'http://'+config[:config]['graphite']+'/render?target=vcloud.running.*&from=-1hour&format=json' ).read
history = JSON.parse( buffer )
history.each do |pool|
JSON.parse( buffer ).each do |pool|
if pool['target'] =~ /.*\.(.*)$/
pool['name'] = $1
pool['major'] = $1 if pool['name'] =~ /^(\w+)\-/
if ( result[pool['major']] )
pool['last'] = result[pool['major']]['running']
result[pool['major']]['history'] ||= Array.new
pool['datapoints'].each do |metric|
3.times do |n|
if ( metric[0] )
pool['last'] = metric[0].to_i
result[pool['major']]['history'].push( metric[0].to_i )
for i in 0..pool['datapoints'].length
if (
pool['datapoints'][i] and
pool['datapoints'][i][0]
)
pool['last'] = pool['datapoints'][i][0]
result[pool['major']]['history'][i] ||= 0
result[pool['major']]['history'][i] = result[pool['major']]['history'][i].to_i + pool['datapoints'][i][0].to_i
else
result[pool['major']]['history'].push( pool['last'] )
end
end
result[pool['major']]['history'][i] = result[pool['major']]['history'][i].to_i + pool['last'].to_i
end
end
end
end
rescue